blob: 199d75a858ed83712f1e7ae0ee9f248b114a8b47 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600358
359 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600360 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 std::vector<const char *> instance_extension_names;
362 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600363
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700364 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600365 /*
366 * Since CreateDbgMsgCallback is an instance level extension call
367 * any extension / layer that utilizes that feature also needs
368 * to be enabled at create instance time.
369 */
Karl Schultz6addd812016-02-02 17:17:23 -0700370 // Use Threading layer first to protect others from
371 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700372 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600373 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800374 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700375 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
661 memory_allocate_info.allocationSize = memory_requirements.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 return;
1571 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1573 ASSERT_VK_SUCCESS(err);
1574 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1575 ASSERT_VK_SUCCESS(err);
1576
Rene Lindsayd14f5572016-12-16 14:57:18 -07001577 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1578
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1582 m_errorMonitor->VerifyFound();
1583
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001584 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001585 // aliasing buffer2
1586 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1587 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001590 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001593 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 m_errorMonitor->VerifyFound();
1596
1597 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001598 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001599 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 vkFreeMemory(m_device->device(), mem, NULL);
1602 vkFreeMemory(m_device->device(), mem_img, NULL);
1603}
1604
Tobin Ehlis35372522016-05-12 08:32:31 -06001605TEST_F(VkLayerTest, InvalidMemoryMapping) {
1606 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1607 VkResult err;
1608 bool pass;
1609 ASSERT_NO_FATAL_FAILURE(InitState());
1610
1611 VkBuffer buffer;
1612 VkDeviceMemory mem;
1613 VkMemoryRequirements mem_reqs;
1614
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001615 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1616
Tobin Ehlis35372522016-05-12 08:32:31 -06001617 VkBufferCreateInfo buf_info = {};
1618 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1619 buf_info.pNext = NULL;
1620 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1621 buf_info.size = 256;
1622 buf_info.queueFamilyIndexCount = 0;
1623 buf_info.pQueueFamilyIndices = NULL;
1624 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1625 buf_info.flags = 0;
1626 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1630 VkMemoryAllocateInfo alloc_info = {};
1631 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1632 alloc_info.pNext = NULL;
1633 alloc_info.memoryTypeIndex = 0;
1634
1635 // Ensure memory is big enough for both bindings
1636 static const VkDeviceSize allocation_size = 0x10000;
1637 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 if (!pass) {
1640 vkDestroyBuffer(m_device->device(), buffer, NULL);
1641 return;
1642 }
1643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 uint8_t *pData;
1647 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1650 m_errorMonitor->VerifyFound();
1651 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1655 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1656 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 m_errorMonitor->VerifyFound();
1658
1659 // Unmap the memory to avoid re-map error
1660 vkUnmapMemory(m_device->device(), mem);
1661 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1663 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1668 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001669 m_errorMonitor->VerifyFound();
1670 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkUnmapMemory(m_device->device(), mem);
1673 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001676 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 ASSERT_VK_SUCCESS(err);
1678 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001679 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001681 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001683 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1684 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001685
Tobin Ehlis35372522016-05-12 08:32:31 -06001686 // Now flush range that oversteps mapped range
1687 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001688 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001689 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001690 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
1695
1696 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001701 mmr.size = VK_WHOLE_SIZE;
1702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001707 // Some platforms have an atomsize of 1 which makes the test meaningless
1708 if (atom_size > 3) {
1709 // Now with an offset NOT a multiple of the device limit
1710 vkUnmapMemory(m_device->device(), mem);
1711 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1712 ASSERT_VK_SUCCESS(err);
1713 mmr.offset = 3; // Not a multiple of atom_size
1714 mmr.size = VK_WHOLE_SIZE;
1715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1716 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Now with a size NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = atom_size;
1724 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001729#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001732 if (!pass) {
1733 vkFreeMemory(m_device->device(), mem, NULL);
1734 vkDestroyBuffer(m_device->device(), buffer, NULL);
1735 return;
1736 }
1737 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1738 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1739
1740 vkDestroyBuffer(m_device->device(), buffer, NULL);
1741 vkFreeMemory(m_device->device(), mem, NULL);
1742}
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001745TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1746 VkResult err;
1747 bool pass;
1748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1750 // following declaration (which is temporarily being moved below):
1751 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001753 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760
Ian Elliott3f06ce52016-04-29 14:46:21 -06001761#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1762#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1763 // Use the functions from the VK_KHR_android_surface extension without
1764 // enabling that extension:
1765
1766 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001767 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001773#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775#if defined(VK_USE_PLATFORM_MIR_KHR)
1776 // Use the functions from the VK_KHR_mir_surface extension without enabling
1777 // that extension:
1778
1779 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
1787 // Tell whether an mir_connection supports presentation:
1788 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1790 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001791 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001792#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1795 // Use the functions from the VK_KHR_wayland_surface extension without
1796 // enabling that extension:
1797
1798 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001799 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1801 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802 pass = (err != VK_SUCCESS);
1803 ASSERT_TRUE(pass);
1804 m_errorMonitor->VerifyFound();
1805
1806 // Tell whether an wayland_display supports presentation:
1807 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1809 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_WAYLAND_KHR
1812#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1816 // TO NON-LINUX PLATFORMS:
1817 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 // Use the functions from the VK_KHR_win32_surface extension without
1819 // enabling that extension:
1820
1821 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001822 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 pass = (err != VK_SUCCESS);
1826 ASSERT_TRUE(pass);
1827 m_errorMonitor->VerifyFound();
1828
1829 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001831 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001836#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1838 // TO NON-LINUX PLATFORMS:
1839 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001840#endif
1841#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001842 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1843 // that extension:
1844
1845 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001848 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1849 pass = (err != VK_SUCCESS);
1850 ASSERT_TRUE(pass);
1851 m_errorMonitor->VerifyFound();
1852
1853 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001854 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001855 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1857 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001859// Set this (for now, until all platforms are supported and tested):
1860#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001861#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001862
Ian Elliott12630812016-04-29 14:35:43 -06001863#if defined(VK_USE_PLATFORM_XLIB_KHR)
1864 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1865 // that extension:
1866
1867 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001868 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001870 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1871 pass = (err != VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Tell whether an Xlib VisualID supports presentation:
1876 Display *dpy = NULL;
1877 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001879 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1880 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001881// Set this (for now, until all platforms are supported and tested):
1882#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001883#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885// Use the functions from the VK_KHR_surface extension without enabling
1886// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001887
Ian Elliott489eec02016-05-05 14:12:44 -06001888#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001891 vkDestroySurfaceKHR(instance(), surface, NULL);
1892 m_errorMonitor->VerifyFound();
1893
1894 // Check if surface supports presentation:
1895 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Check surface capabilities:
1903 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Check surface formats:
1911 uint32_t format_count = 0;
1912 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1914 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001915 pass = (err != VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917 m_errorMonitor->VerifyFound();
1918
1919 // Check surface present modes:
1920 uint32_t present_mode_count = 0;
1921 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1923 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001928
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 // Use the functions from the VK_KHR_swapchain extension without enabling
1930 // that extension:
1931
1932 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1935 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001937 pass = (err != VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
Chris Forbeseb7d5502016-09-13 18:19:21 +12001948 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1949 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1950 VkFence fence;
1951 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1952
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001955 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 pass = (err != VK_SUCCESS);
1957 ASSERT_TRUE(pass);
1958 m_errorMonitor->VerifyFound();
1959
Chris Forbeseb7d5502016-09-13 18:19:21 +12001960 vkDestroyFence(m_device->device(), fence, nullptr);
1961
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001963 //
1964 // NOTE: Currently can't test this because a real swapchain is needed (as
1965 // opposed to the fake one we created) in order for the layer to lookup the
1966 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001967
1968 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001970 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1971 m_errorMonitor->VerifyFound();
1972}
Chris Forbes09368e42016-10-13 11:59:22 +13001973#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001974
Karl Schultz6addd812016-02-02 17:17:23 -07001975TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1976 VkResult err;
1977 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1980 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983
1984 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001985 VkImage image;
1986 VkDeviceMemory mem;
1987 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Karl Schultz6addd812016-02-02 17:17:23 -07001989 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1990 const int32_t tex_width = 32;
1991 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Tony Barboureb254902015-07-15 12:50:33 -06001993 VkImageCreateInfo image_create_info = {};
1994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001995 image_create_info.pNext = NULL;
1996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1997 image_create_info.format = tex_format;
1998 image_create_info.extent.width = tex_width;
1999 image_create_info.extent.height = tex_height;
2000 image_create_info.extent.depth = 1;
2001 image_create_info.mipLevels = 1;
2002 image_create_info.arrayLayers = 1;
2003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2004 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2005 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2006 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002009 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002010 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002011 mem_alloc.pNext = NULL;
2012 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chia-I Wuf7458c52015-10-26 21:10:41 +08002014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015 ASSERT_VK_SUCCESS(err);
2016
Karl Schultz6addd812016-02-02 17:17:23 -07002017 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018
Mark Lobodzinski23065352015-05-29 09:32:35 -05002019 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002022 if (!pass) { // If we can't find any unmappable memory this test doesn't
2023 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002025 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002026 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002027
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002033 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map memory as if to initialize the image
2037 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002043 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044}
2045
Karl Schultz6addd812016-02-02 17:17:23 -07002046TEST_F(VkLayerTest, RebindMemory) {
2047 VkResult err;
2048 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002051
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053
2054 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002055 VkImage image;
2056 VkDeviceMemory mem1;
2057 VkDeviceMemory mem2;
2058 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2061 const int32_t tex_width = 32;
2062 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
Tony Barboureb254902015-07-15 12:50:33 -06002064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2066 image_create_info.pNext = NULL;
2067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2068 image_create_info.format = tex_format;
2069 image_create_info.extent.width = tex_width;
2070 image_create_info.extent.height = tex_height;
2071 image_create_info.extent.depth = 1;
2072 image_create_info.mipLevels = 1;
2073 image_create_info.arrayLayers = 1;
2074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2075 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2076 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2077 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002079 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2081 mem_alloc.pNext = NULL;
2082 mem_alloc.allocationSize = 0;
2083 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002084
Karl Schultz6addd812016-02-02 17:17:23 -07002085 // Introduce failure, do NOT set memProps to
2086 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002087 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002089 ASSERT_VK_SUCCESS(err);
2090
Karl Schultz6addd812016-02-02 17:17:23 -07002091 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002095 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002096
2097 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002100 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
2103 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002104 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105 ASSERT_VK_SUCCESS(err);
2106
Karl Schultz6addd812016-02-02 17:17:23 -07002107 // Introduce validation failure, try to bind a different memory object to
2108 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002109 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002111 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002112
Chia-I Wuf7458c52015-10-26 21:10:41 +08002113 vkDestroyImage(m_device->device(), image, NULL);
2114 vkFreeMemory(m_device->device(), mem1, NULL);
2115 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002117
Karl Schultz6addd812016-02-02 17:17:23 -07002118TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002119 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2122 "submitted in SIGNALED state. Fences "
2123 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002124
2125 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002126 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2127 fenceInfo.pNext = NULL;
2128 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002129
Tony Barbour300a6082015-04-07 13:44:53 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitViewport());
2132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2133
Tony Barbour552f6c02016-12-21 14:34:07 -07002134 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002136 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002137
2138 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002139
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2142 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002144 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002145 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002146 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002149 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002150
2151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002152 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002153
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002154 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002155}
Chris Forbes4e44c912016-06-16 10:20:00 +12002156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002158 TEST_DESCRIPTION(
2159 "Specify wrong usage for image then create conflicting view of image "
2160 "Initialize buffer with wrong usage then perform copy expecting errors "
2161 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002165
2166 auto format = VK_FORMAT_D24_UNORM_S8_UINT;
2167
Tony Barbourf92621a2016-05-02 14:28:12 -06002168 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002169 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002170 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002171 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002172
Tony Barbourf92621a2016-05-02 14:28:12 -06002173 VkImageView dsv;
2174 VkImageViewCreateInfo dsvci = {};
2175 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2176 dsvci.image = image.handle();
2177 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002178 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002179 dsvci.subresourceRange.layerCount = 1;
2180 dsvci.subresourceRange.baseMipLevel = 0;
2181 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002182 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002183
Tony Barbourf92621a2016-05-02 14:28:12 -06002184 // Create a view with depth / stencil aspect for image with different usage
2185 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002186
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002187 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002188
2189 // Initialize buffer with TRANSFER_DST usage
2190 vk_testing::Buffer buffer;
2191 VkMemoryPropertyFlags reqs = 0;
2192 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2193 VkBufferImageCopy region = {};
2194 region.bufferRowLength = 128;
2195 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002196 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002197 region.imageSubresource.layerCount = 1;
2198 region.imageExtent.height = 16;
2199 region.imageExtent.width = 16;
2200 region.imageExtent.depth = 1;
2201
Mark Lobodzinski80871462017-02-16 10:37:27 -07002202 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002203 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002204
Chris Forbesda581202016-10-06 18:25:26 +13002205 // two separate errors from this call:
2206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2208
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002209 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2210 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002212}
Tony Barbour75d79f02016-08-30 09:39:07 -06002213
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002214TEST_F(VkLayerTest, LeakAnObject) {
2215 VkResult err;
2216
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002217 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218
2219 // Note that we have to create a new device since destroying the
2220 // framework's device causes Teardown() to fail and just calling Teardown
2221 // will destroy the errorMonitor.
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002224
2225 ASSERT_NO_FATAL_FAILURE(InitState());
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228 std::vector<VkDeviceQueueCreateInfo> queue_info;
2229 queue_info.reserve(queue_props.size());
2230 std::vector<std::vector<float>> queue_priorities;
2231 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2232 VkDeviceQueueCreateInfo qi = {};
2233 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2234 qi.pNext = NULL;
2235 qi.queueFamilyIndex = i;
2236 qi.queueCount = queue_props[i].queueCount;
2237 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2238 qi.pQueuePriorities = queue_priorities[i].data();
2239 queue_info.push_back(qi);
2240 }
2241
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002243
2244 // The sacrificial device object
2245 VkDevice testDevice;
2246 VkDeviceCreateInfo device_create_info = {};
2247 auto features = m_device->phy().features();
2248 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2249 device_create_info.pNext = NULL;
2250 device_create_info.queueCreateInfoCount = queue_info.size();
2251 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002252 device_create_info.enabledLayerCount = 0;
2253 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002254 device_create_info.pEnabledFeatures = &features;
2255 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2256 ASSERT_VK_SUCCESS(err);
2257
2258 VkFence fence;
2259 VkFenceCreateInfo fence_create_info = {};
2260 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2261 fence_create_info.pNext = NULL;
2262 fence_create_info.flags = 0;
2263 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2264 ASSERT_VK_SUCCESS(err);
2265
2266 // Induce failure by not calling vkDestroyFence
2267 vkDestroyDevice(testDevice, NULL);
2268 m_errorMonitor->VerifyFound();
2269}
2270
2271TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002272 TEST_DESCRIPTION(
2273 "Allocate command buffers from one command pool and "
2274 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002275
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002277
Cody Northropc31a84f2016-08-22 10:41:47 -06002278 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279 VkCommandPool command_pool_one;
2280 VkCommandPool command_pool_two;
2281
2282 VkCommandPoolCreateInfo pool_create_info{};
2283 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2284 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2285 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2286
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002287 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002289 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002290
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002291 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002297 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300
2301 m_errorMonitor->VerifyFound();
2302
2303 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2304 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2305}
2306
2307TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2308 VkResult err;
2309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002310 TEST_DESCRIPTION(
2311 "Allocate descriptor sets from one DS pool and "
2312 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002313
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002315
2316 ASSERT_NO_FATAL_FAILURE(InitState());
2317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2318
2319 VkDescriptorPoolSize ds_type_count = {};
2320 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2321 ds_type_count.descriptorCount = 1;
2322
2323 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2324 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2325 ds_pool_ci.pNext = NULL;
2326 ds_pool_ci.flags = 0;
2327 ds_pool_ci.maxSets = 1;
2328 ds_pool_ci.poolSizeCount = 1;
2329 ds_pool_ci.pPoolSizes = &ds_type_count;
2330
2331 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002332 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002333 ASSERT_VK_SUCCESS(err);
2334
2335 // Create a second descriptor pool
2336 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002337 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002338 ASSERT_VK_SUCCESS(err);
2339
2340 VkDescriptorSetLayoutBinding dsl_binding = {};
2341 dsl_binding.binding = 0;
2342 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2343 dsl_binding.descriptorCount = 1;
2344 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2345 dsl_binding.pImmutableSamplers = NULL;
2346
2347 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2348 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2349 ds_layout_ci.pNext = NULL;
2350 ds_layout_ci.bindingCount = 1;
2351 ds_layout_ci.pBindings = &dsl_binding;
2352
2353 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002354 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002355 ASSERT_VK_SUCCESS(err);
2356
2357 VkDescriptorSet descriptorSet;
2358 VkDescriptorSetAllocateInfo alloc_info = {};
2359 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2360 alloc_info.descriptorSetCount = 1;
2361 alloc_info.descriptorPool = ds_pool_one;
2362 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002363 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002364 ASSERT_VK_SUCCESS(err);
2365
2366 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2367
2368 m_errorMonitor->VerifyFound();
2369
2370 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2371 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2372 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2373}
2374
2375TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002376 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002377
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002378 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002379
2380 ASSERT_NO_FATAL_FAILURE(InitState());
2381
2382 // Pass bogus handle into GetImageMemoryRequirements
2383 VkMemoryRequirements mem_reqs;
2384 uint64_t fakeImageHandle = 0xCADECADE;
2385 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2386
2387 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2388
2389 m_errorMonitor->VerifyFound();
2390}
2391
Mike Schuchardt17838902017-02-21 09:48:06 -07002392TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2393 TEST_DESCRIPTION(
2394 "Try to destroy a render pass object using a device other than the one it was created on. "
2395 "This should generate a distinct error from the invalid handle error.");
2396 // Create first device and renderpass
2397 ASSERT_NO_FATAL_FAILURE(InitState());
2398 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2399
2400 // Create second device
2401 float priorities[] = {1.0f};
2402 VkDeviceQueueCreateInfo queue_info{};
2403 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2404 queue_info.pNext = NULL;
2405 queue_info.flags = 0;
2406 queue_info.queueFamilyIndex = 0;
2407 queue_info.queueCount = 1;
2408 queue_info.pQueuePriorities = &priorities[0];
2409
2410 VkDeviceCreateInfo device_create_info = {};
2411 auto features = m_device->phy().features();
2412 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2413 device_create_info.pNext = NULL;
2414 device_create_info.queueCreateInfoCount = 1;
2415 device_create_info.pQueueCreateInfos = &queue_info;
2416 device_create_info.enabledLayerCount = 0;
2417 device_create_info.ppEnabledLayerNames = NULL;
2418 device_create_info.pEnabledFeatures = &features;
2419
2420 VkDevice second_device;
2421 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2422
2423 // Try to destroy the renderpass from the first device using the second device
2424 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2425 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2426 m_errorMonitor->VerifyFound();
2427
2428 vkDestroyDevice(second_device, NULL);
2429}
2430
Karl Schultz6addd812016-02-02 17:17:23 -07002431TEST_F(VkLayerTest, PipelineNotBound) {
2432 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002433
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002434 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002435
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002437
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002438 ASSERT_NO_FATAL_FAILURE(InitState());
2439 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002440
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002441 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002442 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2443 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
2445 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2447 ds_pool_ci.pNext = NULL;
2448 ds_pool_ci.maxSets = 1;
2449 ds_pool_ci.poolSizeCount = 1;
2450 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002451
2452 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002453 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454 ASSERT_VK_SUCCESS(err);
2455
2456 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002457 dsl_binding.binding = 0;
2458 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2459 dsl_binding.descriptorCount = 1;
2460 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2461 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002462
2463 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002464 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2465 ds_layout_ci.pNext = NULL;
2466 ds_layout_ci.bindingCount = 1;
2467 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468
2469 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002470 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002471 ASSERT_VK_SUCCESS(err);
2472
2473 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002474 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002476 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002477 alloc_info.descriptorPool = ds_pool;
2478 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002479 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002480 ASSERT_VK_SUCCESS(err);
2481
2482 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002483 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2484 pipeline_layout_ci.pNext = NULL;
2485 pipeline_layout_ci.setLayoutCount = 1;
2486 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002487
2488 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002489 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002490 ASSERT_VK_SUCCESS(err);
2491
Mark Youngad779052016-01-06 14:26:04 -07002492 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002493
Tony Barbour552f6c02016-12-21 14:34:07 -07002494 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002495 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002496
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002497 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002498
Chia-I Wuf7458c52015-10-26 21:10:41 +08002499 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2500 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2501 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002502}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002503
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002504TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2505 VkResult err;
2506
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002507 TEST_DESCRIPTION(
2508 "Test validation check for an invalid memory type index "
2509 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002510
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002511 ASSERT_NO_FATAL_FAILURE(InitState());
2512
2513 // Create an image, allocate memory, set a bad typeIndex and then try to
2514 // bind it
2515 VkImage image;
2516 VkDeviceMemory mem;
2517 VkMemoryRequirements mem_reqs;
2518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2519 const int32_t tex_width = 32;
2520 const int32_t tex_height = 32;
2521
2522 VkImageCreateInfo image_create_info = {};
2523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2524 image_create_info.pNext = NULL;
2525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2526 image_create_info.format = tex_format;
2527 image_create_info.extent.width = tex_width;
2528 image_create_info.extent.height = tex_height;
2529 image_create_info.extent.depth = 1;
2530 image_create_info.mipLevels = 1;
2531 image_create_info.arrayLayers = 1;
2532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2533 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2535 image_create_info.flags = 0;
2536
2537 VkMemoryAllocateInfo mem_alloc = {};
2538 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2539 mem_alloc.pNext = NULL;
2540 mem_alloc.allocationSize = 0;
2541 mem_alloc.memoryTypeIndex = 0;
2542
2543 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2544 ASSERT_VK_SUCCESS(err);
2545
2546 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2547 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002548
2549 // Introduce Failure, select invalid TypeIndex
2550 VkPhysicalDeviceMemoryProperties memory_info;
2551
2552 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2553 unsigned int i;
2554 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2555 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2556 mem_alloc.memoryTypeIndex = i;
2557 break;
2558 }
2559 }
2560 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002561 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562 vkDestroyImage(m_device->device(), image, NULL);
2563 return;
2564 }
2565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "for this object type are not compatible with the memory");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002567
2568 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2569 ASSERT_VK_SUCCESS(err);
2570
2571 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2572 (void)err;
2573
2574 m_errorMonitor->VerifyFound();
2575
2576 vkDestroyImage(m_device->device(), image, NULL);
2577 vkFreeMemory(m_device->device(), mem, NULL);
2578}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002579
Karl Schultz6addd812016-02-02 17:17:23 -07002580TEST_F(VkLayerTest, BindInvalidMemory) {
2581 VkResult err;
2582 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002583
2584 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002585
Cortf801b982017-01-17 18:10:21 -08002586 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -07002587 const int32_t tex_width = 32;
2588 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
2590 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002591 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2592 image_create_info.pNext = NULL;
2593 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2594 image_create_info.format = tex_format;
2595 image_create_info.extent.width = tex_width;
2596 image_create_info.extent.height = tex_height;
2597 image_create_info.extent.depth = 1;
2598 image_create_info.mipLevels = 1;
2599 image_create_info.arrayLayers = 1;
2600 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002601 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002602 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2603 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002604
Cortf801b982017-01-17 18:10:21 -08002605 VkBufferCreateInfo buffer_create_info = {};
2606 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2607 buffer_create_info.pNext = NULL;
2608 buffer_create_info.flags = 0;
2609 buffer_create_info.size = tex_width;
2610 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
2611 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002612
Cortf801b982017-01-17 18:10:21 -08002613 // Create an image/buffer, allocate memory, free it, and then try to bind it
2614 {
2615 VkImage image = VK_NULL_HANDLE;
2616 VkBuffer buffer = VK_NULL_HANDLE;
2617 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2618 ASSERT_VK_SUCCESS(err);
2619 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2620 ASSERT_VK_SUCCESS(err);
2621 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2622 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2623 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002624
Cortf801b982017-01-17 18:10:21 -08002625 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2626 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2627 image_mem_alloc.allocationSize = image_mem_reqs.size;
2628 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2629 ASSERT_TRUE(pass);
2630 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002634
Cortf801b982017-01-17 18:10:21 -08002635 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2636 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2637 ASSERT_VK_SUCCESS(err);
2638 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2639 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002640
Cortf801b982017-01-17 18:10:21 -08002641 vkFreeMemory(device(), image_mem, NULL);
2642 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002643
Cortf801b982017-01-17 18:10:21 -08002644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2645 err = vkBindImageMemory(device(), image, image_mem, 0);
2646 (void)err; // This may very well return an error.
2647 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2650 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2651 (void)err; // This may very well return an error.
2652 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002653
Cortf801b982017-01-17 18:10:21 -08002654 vkDestroyImage(m_device->device(), image, NULL);
2655 vkDestroyBuffer(m_device->device(), buffer, NULL);
2656 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002657
2658 // Try to bind memory to an object that already has a memory binding
2659 {
2660 VkImage image = VK_NULL_HANDLE;
2661 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2662 ASSERT_VK_SUCCESS(err);
2663 VkBuffer buffer = VK_NULL_HANDLE;
2664 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2665 ASSERT_VK_SUCCESS(err);
2666 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2667 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2668 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2669 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2670 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2671 image_alloc_info.allocationSize = image_mem_reqs.size;
2672 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2673 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2674 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2675 ASSERT_TRUE(pass);
2676 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2677 ASSERT_TRUE(pass);
2678 VkDeviceMemory image_mem, buffer_mem;
2679 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2680 ASSERT_VK_SUCCESS(err);
2681 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2682 ASSERT_VK_SUCCESS(err);
2683
2684 err = vkBindImageMemory(device(), image, image_mem, 0);
2685 ASSERT_VK_SUCCESS(err);
2686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2687 err = vkBindImageMemory(device(), image, image_mem, 0);
2688 (void)err; // This may very well return an error.
2689 m_errorMonitor->VerifyFound();
2690
2691 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2692 ASSERT_VK_SUCCESS(err);
2693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2694 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2695 (void)err; // This may very well return an error.
2696 m_errorMonitor->VerifyFound();
2697
2698 vkFreeMemory(device(), image_mem, NULL);
2699 vkFreeMemory(device(), buffer_mem, NULL);
2700 vkDestroyImage(device(), image, NULL);
2701 vkDestroyBuffer(device(), buffer, NULL);
2702 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002703
Cort6c7dff72017-01-27 18:34:50 -08002704 // Try to bind memory to an object with an out-of-range memoryOffset
2705 {
2706 VkImage image = VK_NULL_HANDLE;
2707 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2708 ASSERT_VK_SUCCESS(err);
2709 VkBuffer buffer = VK_NULL_HANDLE;
2710 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2711 ASSERT_VK_SUCCESS(err);
2712 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2713 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2714 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2715 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2716 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2717 image_alloc_info.allocationSize = image_mem_reqs.size;
2718 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2719 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2720 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2721 ASSERT_TRUE(pass);
2722 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2723 ASSERT_TRUE(pass);
2724 VkDeviceMemory image_mem, buffer_mem;
2725 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2726 ASSERT_VK_SUCCESS(err);
2727 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2728 ASSERT_VK_SUCCESS(err);
2729
2730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2731 VkDeviceSize image_offset = (image_mem_reqs.size + (image_mem_reqs.alignment - 1)) & ~(image_mem_reqs.alignment - 1);
2732 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2733 (void)err; // This may very well return an error.
2734 m_errorMonitor->VerifyFound();
2735
2736 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2737 VkDeviceSize buffer_offset = (buffer_mem_reqs.size + (buffer_mem_reqs.alignment - 1)) & ~(buffer_mem_reqs.alignment - 1);
2738 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2739 (void)err; // This may very well return an error.
2740 m_errorMonitor->VerifyFound();
2741
2742 vkFreeMemory(device(), image_mem, NULL);
2743 vkFreeMemory(device(), buffer_mem, NULL);
2744 vkDestroyImage(device(), image, NULL);
2745 vkDestroyBuffer(device(), buffer, NULL);
2746 }
2747
Cort Stratton4c38bb52017-01-28 13:33:10 -08002748 // Try to bind memory to an object with an invalid memory type
2749 {
2750 VkImage image = VK_NULL_HANDLE;
2751 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2752 ASSERT_VK_SUCCESS(err);
2753 VkBuffer buffer = VK_NULL_HANDLE;
2754 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2755 ASSERT_VK_SUCCESS(err);
2756 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2757 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2758 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2759 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2760 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2761 image_alloc_info.allocationSize = image_mem_reqs.size;
2762 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2763 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002764 // Create a mask of available memory types *not* supported by these resources,
2765 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002766 VkPhysicalDeviceMemoryProperties memory_properties = {};
2767 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002768 VkDeviceMemory image_mem, buffer_mem;
2769
Cort Stratton4c38bb52017-01-28 13:33:10 -08002770 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002771 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002772 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2773 ASSERT_TRUE(pass);
2774 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2775 ASSERT_VK_SUCCESS(err);
2776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2777 err = vkBindImageMemory(device(), image, image_mem, 0);
2778 (void)err; // This may very well return an error.
2779 m_errorMonitor->VerifyFound();
2780 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002781 }
2782
Cort Stratton4c38bb52017-01-28 13:33:10 -08002783 uint32_t buffer_unsupported_mem_type_bits =
2784 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002785 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002786 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2787 ASSERT_TRUE(pass);
2788 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2789 ASSERT_VK_SUCCESS(err);
2790 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2791 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2792 (void)err; // This may very well return an error.
2793 m_errorMonitor->VerifyFound();
2794 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002795 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002796
Cort Stratton4c38bb52017-01-28 13:33:10 -08002797 vkDestroyImage(device(), image, NULL);
2798 vkDestroyBuffer(device(), buffer, NULL);
2799 }
2800
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002801 // Try to bind memory to an image created with sparse memory flags
2802 {
2803 VkImageCreateInfo sparse_image_create_info = image_create_info;
2804 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2805 VkImageFormatProperties image_format_properties = {};
2806 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2807 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2808 sparse_image_create_info.usage, sparse_image_create_info.flags,
2809 &image_format_properties);
2810 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2811 // most likely means sparse formats aren't supported here; skip this test.
2812 } else {
2813 ASSERT_VK_SUCCESS(err);
2814 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002815 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002816 return;
2817 } else {
2818 VkImage sparse_image = VK_NULL_HANDLE;
2819 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2820 ASSERT_VK_SUCCESS(err);
2821 VkMemoryRequirements sparse_mem_reqs = {};
2822 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2823 if (sparse_mem_reqs.memoryTypeBits != 0) {
2824 VkMemoryAllocateInfo sparse_mem_alloc = {};
2825 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2826 sparse_mem_alloc.pNext = NULL;
2827 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2828 sparse_mem_alloc.memoryTypeIndex = 0;
2829 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2830 ASSERT_TRUE(pass);
2831 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2832 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2833 ASSERT_VK_SUCCESS(err);
2834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2835 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2836 // This may very well return an error.
2837 (void)err;
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2840 }
2841 vkDestroyImage(m_device->device(), sparse_image, NULL);
2842 }
2843 }
2844 }
2845
2846 // Try to bind memory to a buffer created with sparse memory flags
2847 {
2848 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2849 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2850 if (!m_device->phy().features().sparseResidencyBuffer) {
2851 // most likely means sparse formats aren't supported here; skip this test.
2852 } else {
2853 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2854 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2855 ASSERT_VK_SUCCESS(err);
2856 VkMemoryRequirements sparse_mem_reqs = {};
2857 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2858 if (sparse_mem_reqs.memoryTypeBits != 0) {
2859 VkMemoryAllocateInfo sparse_mem_alloc = {};
2860 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2861 sparse_mem_alloc.pNext = NULL;
2862 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2863 sparse_mem_alloc.memoryTypeIndex = 0;
2864 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2865 ASSERT_TRUE(pass);
2866 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2867 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2868 ASSERT_VK_SUCCESS(err);
2869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2870 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2871 // This may very well return an error.
2872 (void)err;
2873 m_errorMonitor->VerifyFound();
2874 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2875 }
2876 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2877 }
2878 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002879}
2880
Karl Schultz6addd812016-02-02 17:17:23 -07002881TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2882 VkResult err;
2883 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002884
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002886
Tobin Ehlisec598302015-09-15 15:02:17 -06002887 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002888
Karl Schultz6addd812016-02-02 17:17:23 -07002889 // Create an image object, allocate memory, destroy the object and then try
2890 // to bind it
2891 VkImage image;
2892 VkDeviceMemory mem;
2893 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002894
Karl Schultz6addd812016-02-02 17:17:23 -07002895 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2896 const int32_t tex_width = 32;
2897 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002898
2899 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002900 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2901 image_create_info.pNext = NULL;
2902 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2903 image_create_info.format = tex_format;
2904 image_create_info.extent.width = tex_width;
2905 image_create_info.extent.height = tex_height;
2906 image_create_info.extent.depth = 1;
2907 image_create_info.mipLevels = 1;
2908 image_create_info.arrayLayers = 1;
2909 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2910 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2911 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2912 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002913
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002914 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002915 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2916 mem_alloc.pNext = NULL;
2917 mem_alloc.allocationSize = 0;
2918 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002919
Chia-I Wuf7458c52015-10-26 21:10:41 +08002920 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002921 ASSERT_VK_SUCCESS(err);
2922
Karl Schultz6addd812016-02-02 17:17:23 -07002923 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002924
2925 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002926 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002927 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002928
2929 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002930 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002931 ASSERT_VK_SUCCESS(err);
2932
2933 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002934 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002935 ASSERT_VK_SUCCESS(err);
2936
2937 // Now Try to bind memory to this destroyed object
2938 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2939 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002940 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002941
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002942 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002943
Chia-I Wuf7458c52015-10-26 21:10:41 +08002944 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002945}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002946
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002947TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2948 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2949
2950 ASSERT_NO_FATAL_FAILURE(InitState());
2951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2952
2953 VkVertexInputBindingDescription input_binding;
2954 memset(&input_binding, 0, sizeof(input_binding));
2955
2956 VkVertexInputAttributeDescription input_attribs;
2957 memset(&input_attribs, 0, sizeof(input_attribs));
2958
2959 // Pick a really bad format for this purpose and make sure it should fail
2960 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
2961 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
2962 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002963 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002964 return;
2965 }
2966
2967 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002968 char const *vsSource =
2969 "#version 450\n"
2970 "\n"
2971 "out gl_PerVertex {\n"
2972 " vec4 gl_Position;\n"
2973 "};\n"
2974 "void main(){\n"
2975 " gl_Position = vec4(1);\n"
2976 "}\n";
2977 char const *fsSource =
2978 "#version 450\n"
2979 "\n"
2980 "layout(location=0) out vec4 color;\n"
2981 "void main(){\n"
2982 " color = vec4(1);\n"
2983 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002984
2985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
2986 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
2987 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
2988
2989 VkPipelineObj pipe(m_device);
2990 pipe.AddColorAttachment();
2991 pipe.AddShader(&vs);
2992 pipe.AddShader(&fs);
2993
2994 pipe.AddVertexInputBindings(&input_binding, 1);
2995 pipe.AddVertexInputAttribs(&input_attribs, 1);
2996
2997 VkDescriptorSetObj descriptorSet(m_device);
2998 descriptorSet.AppendDummy();
2999 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3000
3001 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3002
3003 m_errorMonitor->VerifyFound();
3004}
3005
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003006TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003007 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3008 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003009
3010 VkMemoryPropertyFlags reqs = 0;
3011 VkImageCreateInfo image_create_info = {};
3012 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3013 image_create_info.pNext = NULL;
3014 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3015 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3016 image_create_info.extent.width = 256;
3017 image_create_info.extent.height = 256;
3018 image_create_info.extent.depth = 1;
3019 image_create_info.mipLevels = 1;
3020 image_create_info.arrayLayers = 1;
3021 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3022 image_create_info.flags = 0;
3023
3024 VkImageBlit blit_region = {};
3025 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3026 blit_region.srcSubresource.baseArrayLayer = 0;
3027 blit_region.srcSubresource.layerCount = 1;
3028 blit_region.srcSubresource.mipLevel = 0;
3029 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3030 blit_region.dstSubresource.baseArrayLayer = 0;
3031 blit_region.dstSubresource.layerCount = 1;
3032 blit_region.dstSubresource.mipLevel = 0;
3033
3034 // Create two images, the source with sampleCount = 2, and attempt to blit
3035 // between them
3036 {
3037 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003038 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003039 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003040 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003041 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003042 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003043 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003044 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003045 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003046 m_errorMonitor->SetDesiredFailureMsg(
3047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3048 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003049 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3050 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003051 m_errorMonitor->VerifyFound();
3052 m_commandBuffer->EndCommandBuffer();
3053 }
3054
3055 // Create two images, the dest with sampleCount = 4, and attempt to blit
3056 // between them
3057 {
3058 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003059 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003060 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003061 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003062 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003063 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003064 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003065 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003066 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003067 m_errorMonitor->SetDesiredFailureMsg(
3068 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3069 "was created with a sample count of VK_SAMPLE_COUNT_4_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003070 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3071 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003072 m_errorMonitor->VerifyFound();
3073 m_commandBuffer->EndCommandBuffer();
3074 }
3075
3076 VkBufferImageCopy copy_region = {};
3077 copy_region.bufferRowLength = 128;
3078 copy_region.bufferImageHeight = 128;
3079 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3080 copy_region.imageSubresource.layerCount = 1;
3081 copy_region.imageExtent.height = 64;
3082 copy_region.imageExtent.width = 64;
3083 copy_region.imageExtent.depth = 1;
3084
3085 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3086 // buffer to image
3087 {
3088 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003089 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3090 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003091 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003092 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003093 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003094 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003095 m_errorMonitor->SetDesiredFailureMsg(
3096 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3097 "was created with a sample count of VK_SAMPLE_COUNT_8_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003098 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3099 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 m_errorMonitor->VerifyFound();
3101 m_commandBuffer->EndCommandBuffer();
3102 }
3103
3104 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3105 // image to buffer
3106 {
3107 vk_testing::Buffer dst_buffer;
3108 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3109 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003111 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003112 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003113 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003114 m_errorMonitor->SetDesiredFailureMsg(
3115 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3116 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003117 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003118 dst_buffer.handle(), 1, &copy_region);
3119 m_errorMonitor->VerifyFound();
3120 m_commandBuffer->EndCommandBuffer();
3121 }
3122}
3123
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003124TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003125 ASSERT_NO_FATAL_FAILURE(InitState());
3126
3127 VkImageObj src_image(m_device);
3128 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3129 VkImageObj dst_image(m_device);
3130 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3131 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003132 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 -06003133
3134 VkImageBlit blitRegion = {};
3135 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3136 blitRegion.srcSubresource.baseArrayLayer = 0;
3137 blitRegion.srcSubresource.layerCount = 1;
3138 blitRegion.srcSubresource.mipLevel = 0;
3139 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3140 blitRegion.dstSubresource.baseArrayLayer = 0;
3141 blitRegion.dstSubresource.layerCount = 1;
3142 blitRegion.dstSubresource.mipLevel = 0;
3143
Dave Houlton34df4cb2016-12-01 16:43:06 -07003144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3145
3146 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3147 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003148
3149 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003150 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003151 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3152 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003153
3154 m_errorMonitor->VerifyFound();
3155
Dave Houlton34df4cb2016-12-01 16:43:06 -07003156 // Test should generate 2 VU failures
3157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3158 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003159
3160 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003161 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3162 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003163
Dave Houlton34df4cb2016-12-01 16:43:06 -07003164 // TODO: Note that this only verifies that at least one of the VU enums was found
3165 // 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 -06003166 m_errorMonitor->VerifyFound();
3167
Tony Barbour552f6c02016-12-21 14:34:07 -07003168 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003169}
3170
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003171TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3172 VkResult err;
3173 bool pass;
3174
3175 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3176 ASSERT_NO_FATAL_FAILURE(InitState());
3177
3178 // If w/d/h granularity is 1, test is not meaningful
3179 // TODO: When virtual device limits are available, create a set of limits for this test that
3180 // will always have a granularity of > 1 for w, h, and d
3181 auto index = m_device->graphics_queue_node_index_;
3182 auto queue_family_properties = m_device->phy().queue_properties();
3183
3184 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3185 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3186 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3187 return;
3188 }
3189
3190 // Create two images of different types and try to copy between them
3191 VkImage srcImage;
3192 VkImage dstImage;
3193 VkDeviceMemory srcMem;
3194 VkDeviceMemory destMem;
3195 VkMemoryRequirements memReqs;
3196
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003197 VkImageCreateInfo image_create_info = {};
3198 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3199 image_create_info.pNext = NULL;
3200 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3201 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3202 image_create_info.extent.width = 32;
3203 image_create_info.extent.height = 32;
3204 image_create_info.extent.depth = 1;
3205 image_create_info.mipLevels = 1;
3206 image_create_info.arrayLayers = 4;
3207 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3208 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3209 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3210 image_create_info.flags = 0;
3211
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003212 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003213 ASSERT_VK_SUCCESS(err);
3214
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003215 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003216 ASSERT_VK_SUCCESS(err);
3217
3218 // Allocate memory
3219 VkMemoryAllocateInfo memAlloc = {};
3220 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3221 memAlloc.pNext = NULL;
3222 memAlloc.allocationSize = 0;
3223 memAlloc.memoryTypeIndex = 0;
3224
3225 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3226 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003227 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003228 ASSERT_TRUE(pass);
3229 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3230 ASSERT_VK_SUCCESS(err);
3231
3232 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3233 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003234 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003235 ASSERT_VK_SUCCESS(err);
3236 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3237 ASSERT_VK_SUCCESS(err);
3238
3239 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3240 ASSERT_VK_SUCCESS(err);
3241 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3242 ASSERT_VK_SUCCESS(err);
3243
Tony Barbour552f6c02016-12-21 14:34:07 -07003244 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003245 VkImageCopy copyRegion;
3246 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3247 copyRegion.srcSubresource.mipLevel = 0;
3248 copyRegion.srcSubresource.baseArrayLayer = 0;
3249 copyRegion.srcSubresource.layerCount = 1;
3250 copyRegion.srcOffset.x = 0;
3251 copyRegion.srcOffset.y = 0;
3252 copyRegion.srcOffset.z = 0;
3253 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3254 copyRegion.dstSubresource.mipLevel = 0;
3255 copyRegion.dstSubresource.baseArrayLayer = 0;
3256 copyRegion.dstSubresource.layerCount = 1;
3257 copyRegion.dstOffset.x = 0;
3258 copyRegion.dstOffset.y = 0;
3259 copyRegion.dstOffset.z = 0;
3260 copyRegion.extent.width = 1;
3261 copyRegion.extent.height = 1;
3262 copyRegion.extent.depth = 1;
3263
3264 // Introduce failure by setting srcOffset to a bad granularity value
3265 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3267 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003268 m_errorMonitor->VerifyFound();
3269
3270 // Introduce failure by setting extent to a bad granularity value
3271 copyRegion.srcOffset.y = 0;
3272 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003273 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3274 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003275 m_errorMonitor->VerifyFound();
3276
3277 // Now do some buffer/image copies
3278 vk_testing::Buffer buffer;
3279 VkMemoryPropertyFlags reqs = 0;
3280 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3281 VkBufferImageCopy region = {};
3282 region.bufferOffset = 0;
3283 region.bufferRowLength = 3;
3284 region.bufferImageHeight = 128;
3285 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3286 region.imageSubresource.layerCount = 1;
3287 region.imageExtent.height = 16;
3288 region.imageExtent.width = 16;
3289 region.imageExtent.depth = 1;
3290 region.imageOffset.x = 0;
3291 region.imageOffset.y = 0;
3292 region.imageOffset.z = 0;
3293
3294 // Introduce failure by setting bufferRowLength to a bad granularity value
3295 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003296 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3297 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3298 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003299 m_errorMonitor->VerifyFound();
3300 region.bufferRowLength = 128;
3301
3302 // Introduce failure by setting bufferOffset to a bad granularity value
3303 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3305 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3306 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003307 m_errorMonitor->VerifyFound();
3308 region.bufferOffset = 0;
3309
3310 // Introduce failure by setting bufferImageHeight to a bad granularity value
3311 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3313 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3314 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003315 m_errorMonitor->VerifyFound();
3316 region.bufferImageHeight = 128;
3317
3318 // Introduce failure by setting imageExtent to a bad granularity value
3319 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3321 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3322 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003323 m_errorMonitor->VerifyFound();
3324 region.imageExtent.width = 16;
3325
3326 // Introduce failure by setting imageOffset to a bad granularity value
3327 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3329 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3330 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003331 m_errorMonitor->VerifyFound();
3332
Tony Barbour552f6c02016-12-21 14:34:07 -07003333 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003334
3335 vkDestroyImage(m_device->device(), srcImage, NULL);
3336 vkDestroyImage(m_device->device(), dstImage, NULL);
3337 vkFreeMemory(m_device->device(), srcMem, NULL);
3338 vkFreeMemory(m_device->device(), destMem, NULL);
3339}
3340
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003341TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003342 TEST_DESCRIPTION(
3343 "Submit command buffer created using one queue family and "
3344 "attempt to submit them on a queue created in a different "
3345 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003346
Cody Northropc31a84f2016-08-22 10:41:47 -06003347 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003348
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003349 // This test is meaningless unless we have multiple queue families
3350 auto queue_family_properties = m_device->phy().queue_properties();
3351 if (queue_family_properties.size() < 2) {
3352 return;
3353 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003355 // Get safe index of another queue family
3356 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3357 ASSERT_NO_FATAL_FAILURE(InitState());
3358 // Create a second queue using a different queue family
3359 VkQueue other_queue;
3360 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3361
3362 // Record an empty cmd buffer
3363 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3364 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3365 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3366 vkEndCommandBuffer(m_commandBuffer->handle());
3367
3368 // And submit on the wrong queue
3369 VkSubmitInfo submit_info = {};
3370 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3371 submit_info.commandBufferCount = 1;
3372 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003373 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003374
3375 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003376}
3377
Chris Forbes4c24a922016-11-16 08:59:10 +13003378TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3379 ASSERT_NO_FATAL_FAILURE(InitState());
3380
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003381 // There are no attachments, but refer to attachment 0.
3382 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003383 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003384 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003385 };
3386
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003387 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003388 VkRenderPass rp;
3389
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003390 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003392 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3393 m_errorMonitor->VerifyFound();
3394}
3395
Chris Forbesa58c4522016-09-28 15:19:39 +13003396TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3397 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3398 ASSERT_NO_FATAL_FAILURE(InitState());
3399
3400 // A renderpass with two subpasses, both writing the same attachment.
3401 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003402 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3403 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3404 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003405 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003406 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003407 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003408 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3409 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003410 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003411 VkSubpassDependency dep = {0,
3412 1,
3413 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3414 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3415 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3416 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3417 VK_DEPENDENCY_BY_REGION_BIT};
3418 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003419 VkRenderPass rp;
3420 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3421 ASSERT_VK_SUCCESS(err);
3422
3423 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003424 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 +13003425 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3426
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003427 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003428 VkFramebuffer fb;
3429 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3430 ASSERT_VK_SUCCESS(err);
3431
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003432 char const *vsSource =
3433 "#version 450\n"
3434 "void main() { gl_Position = vec4(1); }\n";
3435 char const *fsSource =
3436 "#version 450\n"
3437 "layout(location=0) out vec4 color;\n"
3438 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003439
3440 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3441 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3442 VkPipelineObj pipe(m_device);
3443 pipe.AddColorAttachment();
3444 pipe.AddShader(&vs);
3445 pipe.AddShader(&fs);
3446 VkViewport view_port = {};
3447 m_viewports.push_back(view_port);
3448 pipe.SetViewport(m_viewports);
3449 VkRect2D rect = {};
3450 m_scissors.push_back(rect);
3451 pipe.SetScissor(m_scissors);
3452
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003453 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003454 VkPipelineLayout pl;
3455 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3456 ASSERT_VK_SUCCESS(err);
3457 pipe.CreateVKPipeline(pl, rp);
3458
Tony Barbour552f6c02016-12-21 14:34:07 -07003459 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003460
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003461 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3462 nullptr,
3463 rp,
3464 fb,
3465 {{
3466 0, 0,
3467 },
3468 {32, 32}},
3469 0,
3470 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003471
3472 // subtest 1: bind in the wrong subpass
3473 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3474 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003475 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 +13003476 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3477 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3478 m_errorMonitor->VerifyFound();
3479
3480 vkCmdEndRenderPass(m_commandBuffer->handle());
3481
3482 // subtest 2: bind in correct subpass, then transition to next subpass
3483 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3484 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3485 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 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 +13003487 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3488 m_errorMonitor->VerifyFound();
3489
3490 vkCmdEndRenderPass(m_commandBuffer->handle());
3491
Tony Barbour552f6c02016-12-21 14:34:07 -07003492 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003493
3494 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3495 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3496 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3497}
3498
Tony Barbour4e919972016-08-09 13:27:40 -06003499TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003500 TEST_DESCRIPTION(
3501 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3502 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003503 ASSERT_NO_FATAL_FAILURE(InitState());
3504 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3505
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003506 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3507 "Cannot execute a render pass with renderArea "
3508 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003509
3510 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3511 m_renderPassBeginInfo.renderArea.extent.width = 257;
3512 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003513 m_commandBuffer->BeginCommandBuffer();
3514 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003515 m_errorMonitor->VerifyFound();
3516}
3517
3518TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003519 TEST_DESCRIPTION(
3520 "Generate INDEPENDENT_BLEND by disabling independent "
3521 "blend and then specifying different blend states for two "
3522 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003523 VkPhysicalDeviceFeatures features = {};
3524 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003525 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003526
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3528 "Invalid Pipeline CreateInfo: If independent blend feature not "
3529 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003530
Cody Northropc31a84f2016-08-22 10:41:47 -06003531 VkDescriptorSetObj descriptorSet(m_device);
3532 descriptorSet.AppendDummy();
3533 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003534
Cody Northropc31a84f2016-08-22 10:41:47 -06003535 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003536 // Create a renderPass with two color attachments
3537 VkAttachmentReference attachments[2] = {};
3538 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
3539 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3540
3541 VkSubpassDescription subpass = {};
3542 subpass.pColorAttachments = attachments;
3543 subpass.colorAttachmentCount = 2;
3544
3545 VkRenderPassCreateInfo rpci = {};
3546 rpci.subpassCount = 1;
3547 rpci.pSubpasses = &subpass;
3548 rpci.attachmentCount = 1;
3549
3550 VkAttachmentDescription attach_desc = {};
3551 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3552 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3553 attach_desc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3554 attach_desc.finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3555
3556 rpci.pAttachments = &attach_desc;
3557 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3558
3559 VkRenderPass renderpass;
3560 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003561 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003562 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003563
Cody Northropc31a84f2016-08-22 10:41:47 -06003564 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3565 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3566 att_state1.blendEnable = VK_TRUE;
3567 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3568 att_state2.blendEnable = VK_FALSE;
3569 pipeline.AddColorAttachment(0, &att_state1);
3570 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003571 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003572 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003573 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003574}
3575
Mike Weiblen40b160e2017-02-06 19:21:52 -07003576// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3577TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3578 TEST_DESCRIPTION(
3579 "Create a graphics pipeline that is incompatible with the requirements "
3580 "of its contained Renderpass/subpasses.");
3581 ASSERT_NO_FATAL_FAILURE(InitState());
3582
3583 VkDescriptorSetObj ds_obj(m_device);
3584 ds_obj.AppendDummy();
3585 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3586
3587 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3588
3589 VkPipelineColorBlendAttachmentState att_state1 = {};
3590 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3591 att_state1.blendEnable = VK_TRUE;
3592
3593 VkRenderpassObj rp_obj(m_device);
3594
3595 {
3596 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3597 VkPipelineObj pipeline(m_device);
3598 pipeline.AddShader(&vs_obj);
3599 pipeline.AddColorAttachment(0, &att_state1);
3600
3601 VkGraphicsPipelineCreateInfo info = {};
3602 pipeline.InitGraphicsPipelineCreateInfo(&info);
3603 info.pColorBlendState = nullptr;
3604
3605 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3606 m_errorMonitor->VerifyFound();
3607 }
3608}
3609
Chris Forbes26ec2122016-11-29 08:58:33 +13003610#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003611TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3612 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3613 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003614 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003615
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003616 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3617 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003618
3619 // Create a renderPass with a single color attachment
3620 VkAttachmentReference attach = {};
3621 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3622 VkSubpassDescription subpass = {};
3623 VkRenderPassCreateInfo rpci = {};
3624 rpci.subpassCount = 1;
3625 rpci.pSubpasses = &subpass;
3626 rpci.attachmentCount = 1;
3627 VkAttachmentDescription attach_desc = {};
3628 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3629 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3630 rpci.pAttachments = &attach_desc;
3631 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3632 VkRenderPass rp;
3633 subpass.pDepthStencilAttachment = &attach;
3634 subpass.pColorAttachments = NULL;
3635 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3636 m_errorMonitor->VerifyFound();
3637}
Chris Forbes26ec2122016-11-29 08:58:33 +13003638#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003639
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003640TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003641 TEST_DESCRIPTION(
3642 "Create a framebuffer where a subpass has a preserve "
3643 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003644
3645 ASSERT_NO_FATAL_FAILURE(InitState());
3646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3647
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003649
3650 VkAttachmentReference color_attach = {};
3651 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3652 color_attach.attachment = 0;
3653 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3654 VkSubpassDescription subpass = {};
3655 subpass.colorAttachmentCount = 1;
3656 subpass.pColorAttachments = &color_attach;
3657 subpass.preserveAttachmentCount = 1;
3658 subpass.pPreserveAttachments = &preserve_attachment;
3659
3660 VkRenderPassCreateInfo rpci = {};
3661 rpci.subpassCount = 1;
3662 rpci.pSubpasses = &subpass;
3663 rpci.attachmentCount = 1;
3664 VkAttachmentDescription attach_desc = {};
3665 attach_desc.format = VK_FORMAT_UNDEFINED;
3666 rpci.pAttachments = &attach_desc;
3667 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3668 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003669 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003670
3671 m_errorMonitor->VerifyFound();
3672
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003673 if (result == VK_SUCCESS) {
3674 vkDestroyRenderPass(m_device->device(), rp, NULL);
3675 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003676}
3677
Chris Forbesc5389742016-06-29 11:49:23 +12003678TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003679 TEST_DESCRIPTION(
3680 "Ensure that CreateRenderPass produces a validation error "
3681 "when the source of a subpass multisample resolve "
3682 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003683
Chris Forbesc5389742016-06-29 11:49:23 +12003684 ASSERT_NO_FATAL_FAILURE(InitState());
3685
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3687 "Subpass 0 requests multisample resolve from attachment 0 which has "
3688 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003689
3690 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003691 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3692 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3693 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3694 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3695 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3696 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003697 };
3698
3699 VkAttachmentReference color = {
3700 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3701 };
3702
3703 VkAttachmentReference resolve = {
3704 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3705 };
3706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003707 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003708
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003709 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003710
3711 VkRenderPass rp;
3712 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3713
3714 m_errorMonitor->VerifyFound();
3715
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003716 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003717}
3718
3719TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003720 TEST_DESCRIPTION(
3721 "Ensure CreateRenderPass produces a validation error "
3722 "when a subpass multisample resolve operation is "
3723 "requested, and the destination of that resolve has "
3724 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003725
Chris Forbesc5389742016-06-29 11:49:23 +12003726 ASSERT_NO_FATAL_FAILURE(InitState());
3727
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003728 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3729 "Subpass 0 requests multisample resolve into attachment 1, which "
3730 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003731
3732 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003733 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3734 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3735 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3736 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3737 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3738 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003739 };
3740
3741 VkAttachmentReference color = {
3742 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3743 };
3744
3745 VkAttachmentReference resolve = {
3746 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3747 };
3748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003749 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003751 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003752
3753 VkRenderPass rp;
3754 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3755
3756 m_errorMonitor->VerifyFound();
3757
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003758 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003759}
3760
Chris Forbes3f128ef2016-06-29 14:58:53 +12003761TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003762 TEST_DESCRIPTION(
3763 "Ensure CreateRenderPass produces a validation error "
3764 "when the color and depth attachments used by a subpass "
3765 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003766
Chris Forbes3f128ef2016-06-29 14:58:53 +12003767 ASSERT_NO_FATAL_FAILURE(InitState());
3768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3770 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003771
3772 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3774 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3775 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3776 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3777 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3778 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003779 };
3780
3781 VkAttachmentReference color[] = {
3782 {
3783 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3784 },
3785 {
3786 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3787 },
3788 };
3789
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003790 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003792 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003793
3794 VkRenderPass rp;
3795 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3796
3797 m_errorMonitor->VerifyFound();
3798
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003799 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003800}
3801
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003802TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003803 TEST_DESCRIPTION(
3804 "Hit errors when attempting to create a framebuffer :\n"
3805 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3806 " 2. Use a color image as depthStencil attachment\n"
3807 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3808 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3809 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3810 " 6. Framebuffer attachment where dimensions don't match\n"
3811 " 7. Framebuffer attachment w/o identity swizzle\n"
3812 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003813
3814 ASSERT_NO_FATAL_FAILURE(InitState());
3815 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3816
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003817 m_errorMonitor->SetDesiredFailureMsg(
3818 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3819 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003820
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003821 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003822 VkAttachmentReference attach = {};
3823 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3824 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003825 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003826 VkRenderPassCreateInfo rpci = {};
3827 rpci.subpassCount = 1;
3828 rpci.pSubpasses = &subpass;
3829 rpci.attachmentCount = 1;
3830 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003831 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003832 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003833 rpci.pAttachments = &attach_desc;
3834 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3835 VkRenderPass rp;
3836 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3837 ASSERT_VK_SUCCESS(err);
3838
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003839 VkImageView ivs[2];
3840 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3841 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003842 VkFramebufferCreateInfo fb_info = {};
3843 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3844 fb_info.pNext = NULL;
3845 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003846 // Set mis-matching attachmentCount
3847 fb_info.attachmentCount = 2;
3848 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003849 fb_info.width = 100;
3850 fb_info.height = 100;
3851 fb_info.layers = 1;
3852
3853 VkFramebuffer fb;
3854 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3855
3856 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003857 if (err == VK_SUCCESS) {
3858 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3859 }
3860 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003861
3862 // Create a renderPass with a depth-stencil attachment created with
3863 // IMAGE_USAGE_COLOR_ATTACHMENT
3864 // Add our color attachment to pDepthStencilAttachment
3865 subpass.pDepthStencilAttachment = &attach;
3866 subpass.pColorAttachments = NULL;
3867 VkRenderPass rp_ds;
3868 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3869 ASSERT_VK_SUCCESS(err);
3870 // Set correct attachment count, but attachment has COLOR usage bit set
3871 fb_info.attachmentCount = 1;
3872 fb_info.renderPass = rp_ds;
3873
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003875 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3876
3877 m_errorMonitor->VerifyFound();
3878 if (err == VK_SUCCESS) {
3879 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3880 }
3881 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003882
3883 // Create new renderpass with alternate attachment format from fb
3884 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3885 subpass.pDepthStencilAttachment = NULL;
3886 subpass.pColorAttachments = &attach;
3887 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3888 ASSERT_VK_SUCCESS(err);
3889
3890 // Cause error due to mis-matched formats between rp & fb
3891 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3892 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3894 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003895 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3896
3897 m_errorMonitor->VerifyFound();
3898 if (err == VK_SUCCESS) {
3899 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3900 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003901 vkDestroyRenderPass(m_device->device(), rp, NULL);
3902
3903 // Create new renderpass with alternate sample count from fb
3904 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3905 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3906 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3907 ASSERT_VK_SUCCESS(err);
3908
3909 // Cause error due to mis-matched sample count between rp & fb
3910 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003911 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003912 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003913 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3914
3915 m_errorMonitor->VerifyFound();
3916 if (err == VK_SUCCESS) {
3917 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3918 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003919
3920 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003921
3922 // Create a custom imageView with non-1 mip levels
3923 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003924 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 -06003925 ASSERT_TRUE(image.initialized());
3926
3927 VkImageView view;
3928 VkImageViewCreateInfo ivci = {};
3929 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3930 ivci.image = image.handle();
3931 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3932 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3933 ivci.subresourceRange.layerCount = 1;
3934 ivci.subresourceRange.baseMipLevel = 0;
3935 // Set level count 2 (only 1 is allowed for FB attachment)
3936 ivci.subresourceRange.levelCount = 2;
3937 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3938 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3939 ASSERT_VK_SUCCESS(err);
3940 // Re-create renderpass to have matching sample count
3941 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3942 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3943 ASSERT_VK_SUCCESS(err);
3944
3945 fb_info.renderPass = rp;
3946 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003948 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3949
3950 m_errorMonitor->VerifyFound();
3951 if (err == VK_SUCCESS) {
3952 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3953 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003954 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003955 // Update view to original color buffer and grow FB dimensions too big
3956 fb_info.pAttachments = ivs;
3957 fb_info.height = 1024;
3958 fb_info.width = 1024;
3959 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06003961 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3962
3963 m_errorMonitor->VerifyFound();
3964 if (err == VK_SUCCESS) {
3965 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3966 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003967 // Create view attachment with non-identity swizzle
3968 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3969 ivci.image = image.handle();
3970 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3971 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3972 ivci.subresourceRange.layerCount = 1;
3973 ivci.subresourceRange.baseMipLevel = 0;
3974 ivci.subresourceRange.levelCount = 1;
3975 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3976 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
3977 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
3978 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
3979 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
3980 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3981 ASSERT_VK_SUCCESS(err);
3982
3983 fb_info.pAttachments = &view;
3984 fb_info.height = 100;
3985 fb_info.width = 100;
3986 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003987 m_errorMonitor->SetDesiredFailureMsg(
3988 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3989 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06003990 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3991
3992 m_errorMonitor->VerifyFound();
3993 if (err == VK_SUCCESS) {
3994 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3995 }
3996 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06003997 // reset attachment to color attachment
3998 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07003999
4000 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004001 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004002 fb_info.height = 100;
4003 fb_info.layers = 1;
4004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004005 m_errorMonitor->SetDesiredFailureMsg(
4006 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004007 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4008 "Here are the respective dimensions for attachment");
4009
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004010 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4011
4012 m_errorMonitor->VerifyFound();
4013 if (err == VK_SUCCESS) {
4014 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4015 }
4016
4017 // Request fb that exceeds max height
4018 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004019 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004020 fb_info.layers = 1;
4021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004022 m_errorMonitor->SetDesiredFailureMsg(
4023 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004024 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4025 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004026 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4027
4028 m_errorMonitor->VerifyFound();
4029 if (err == VK_SUCCESS) {
4030 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4031 }
4032
4033 // Request fb that exceeds max layers
4034 fb_info.width = 100;
4035 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004036 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004038 m_errorMonitor->SetDesiredFailureMsg(
4039 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004040 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4041 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004042 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4043
4044 m_errorMonitor->VerifyFound();
4045 if (err == VK_SUCCESS) {
4046 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4047 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004048
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004049 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004050}
4051
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004052TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004053 TEST_DESCRIPTION(
4054 "Run a simple draw calls to validate failure when Depth Bias 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 Ehlisb1a87992016-05-25 16:42:47 -06004058 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4060 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004061 m_errorMonitor->VerifyFound();
4062}
4063
4064TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004065 TEST_DESCRIPTION(
4066 "Run a simple draw calls to validate failure when Line Width dynamic "
4067 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004068
Cody Northropc31a84f2016-08-22 10:41:47 -06004069 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004070 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004071 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4072 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004073 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004074}
4075
4076TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004077 TEST_DESCRIPTION(
4078 "Run a simple draw calls to validate failure when Viewport dynamic "
4079 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004080
Cody Northropc31a84f2016-08-22 10:41:47 -06004081 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004082 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4084 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004085 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004086 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004087}
4088
4089TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004090 TEST_DESCRIPTION(
4091 "Run a simple draw calls to validate failure when Scissor dynamic "
4092 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004093
Cody Northropc31a84f2016-08-22 10:41:47 -06004094 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004095 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4097 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004098 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004099 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004100}
4101
Cortd713fe82016-07-27 09:51:27 -07004102TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004103 TEST_DESCRIPTION(
4104 "Run a simple draw calls to validate failure when Blend Constants "
4105 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004106
4107 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004108 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4110 "Dynamic blend constants state not set for this command buffer");
4111 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004112 m_errorMonitor->VerifyFound();
4113}
4114
4115TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004116 TEST_DESCRIPTION(
4117 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4118 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004119
4120 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004121 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004122 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004123 return;
4124 }
4125 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004126 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4127 "Dynamic depth bounds state not set for this command buffer");
4128 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004129 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004130}
4131
4132TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004133 TEST_DESCRIPTION(
4134 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4135 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004136
4137 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004138 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004139 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4140 "Dynamic stencil read mask state not set for this command buffer");
4141 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004142 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004143}
4144
4145TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004146 TEST_DESCRIPTION(
4147 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4148 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004149
4150 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004151 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4153 "Dynamic stencil write mask state not set for this command buffer");
4154 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004155 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004156}
4157
4158TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004159 TEST_DESCRIPTION(
4160 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4161 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004162
4163 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004164 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004165 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4166 "Dynamic stencil reference state not set for this command buffer");
4167 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004168 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004169}
4170
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004171TEST_F(VkLayerTest, IndexBufferNotBound) {
4172 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004173
4174 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4176 "Index buffer object not bound to this command buffer when Indexed ");
4177 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004178 m_errorMonitor->VerifyFound();
4179}
4180
Karl Schultz6addd812016-02-02 17:17:23 -07004181TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004182 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4183 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4184 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004185
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004186 ASSERT_NO_FATAL_FAILURE(InitState());
4187 ASSERT_NO_FATAL_FAILURE(InitViewport());
4188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4189
Karl Schultz6addd812016-02-02 17:17:23 -07004190 // We luck out b/c by default the framework creates CB w/ the
4191 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004192 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004193 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004194 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004195
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004196 // Bypass framework since it does the waits automatically
4197 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004198 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004199 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4200 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004201 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004202 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004203 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004204 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004205 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004206 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004207 submit_info.pSignalSemaphores = NULL;
4208
Chris Forbes40028e22016-06-13 09:59:34 +12004209 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004210 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004211 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004212
Karl Schultz6addd812016-02-02 17:17:23 -07004213 // Cause validation error by re-submitting cmd buffer that should only be
4214 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004215 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004216 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004217
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004218 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004219}
4220
Karl Schultz6addd812016-02-02 17:17:23 -07004221TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004222 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004223 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004224
4225 ASSERT_NO_FATAL_FAILURE(InitState());
4226 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004227
Karl Schultz6addd812016-02-02 17:17:23 -07004228 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4229 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004230 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004231 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004232 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004233
4234 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004235 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4236 ds_pool_ci.pNext = NULL;
4237 ds_pool_ci.flags = 0;
4238 ds_pool_ci.maxSets = 1;
4239 ds_pool_ci.poolSizeCount = 1;
4240 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004241
4242 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004243 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004244 ASSERT_VK_SUCCESS(err);
4245
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004246 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4247 dsl_binding_samp.binding = 0;
4248 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4249 dsl_binding_samp.descriptorCount = 1;
4250 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4251 dsl_binding_samp.pImmutableSamplers = NULL;
4252
4253 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4254 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4255 ds_layout_ci.pNext = NULL;
4256 ds_layout_ci.bindingCount = 1;
4257 ds_layout_ci.pBindings = &dsl_binding_samp;
4258
4259 VkDescriptorSetLayout ds_layout_samp;
4260 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4261 ASSERT_VK_SUCCESS(err);
4262
4263 // Try to allocate 2 sets when pool only has 1 set
4264 VkDescriptorSet descriptor_sets[2];
4265 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4266 VkDescriptorSetAllocateInfo alloc_info = {};
4267 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4268 alloc_info.descriptorSetCount = 2;
4269 alloc_info.descriptorPool = ds_pool;
4270 alloc_info.pSetLayouts = set_layouts;
4271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4272 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4273 m_errorMonitor->VerifyFound();
4274
4275 alloc_info.descriptorSetCount = 1;
4276 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004277 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004278 dsl_binding.binding = 0;
4279 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4280 dsl_binding.descriptorCount = 1;
4281 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4282 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004283
Karl Schultz6addd812016-02-02 17:17:23 -07004284 ds_layout_ci.bindingCount = 1;
4285 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004286
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004287 VkDescriptorSetLayout ds_layout_ub;
4288 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004289 ASSERT_VK_SUCCESS(err);
4290
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004291 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004292 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004293 alloc_info.pSetLayouts = &ds_layout_ub;
4294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4295 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004297 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004298
Karl Schultz2825ab92016-12-02 08:23:14 -07004299 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004300 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004301 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004302}
4303
Karl Schultz6addd812016-02-02 17:17:23 -07004304TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4305 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004306
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004308
Tobin Ehlise735c692015-10-08 13:13:50 -06004309 ASSERT_NO_FATAL_FAILURE(InitState());
4310 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004311
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004312 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004313 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4314 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004315
4316 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004317 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4318 ds_pool_ci.pNext = NULL;
4319 ds_pool_ci.maxSets = 1;
4320 ds_pool_ci.poolSizeCount = 1;
4321 ds_pool_ci.flags = 0;
4322 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4323 // app can only call vkResetDescriptorPool on this pool.;
4324 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004325
4326 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004327 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004328 ASSERT_VK_SUCCESS(err);
4329
4330 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004331 dsl_binding.binding = 0;
4332 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4333 dsl_binding.descriptorCount = 1;
4334 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4335 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004336
4337 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004338 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4339 ds_layout_ci.pNext = NULL;
4340 ds_layout_ci.bindingCount = 1;
4341 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004342
4343 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004344 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004345 ASSERT_VK_SUCCESS(err);
4346
4347 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004348 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004349 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004350 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004351 alloc_info.descriptorPool = ds_pool;
4352 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004353 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004354 ASSERT_VK_SUCCESS(err);
4355
4356 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004357 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004358
Chia-I Wuf7458c52015-10-26 21:10:41 +08004359 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4360 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004361}
4362
Karl Schultz6addd812016-02-02 17:17:23 -07004363TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004364 // Attempt to clear Descriptor Pool with bad object.
4365 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004366
4367 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004369 uint64_t fake_pool_handle = 0xbaad6001;
4370 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4371 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004372 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004373}
4374
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004375TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004376 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4377 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004378 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004379 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004380
4381 uint64_t fake_set_handle = 0xbaad6001;
4382 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004383 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004384 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004385
4386 ASSERT_NO_FATAL_FAILURE(InitState());
4387
4388 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4389 layout_bindings[0].binding = 0;
4390 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4391 layout_bindings[0].descriptorCount = 1;
4392 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4393 layout_bindings[0].pImmutableSamplers = NULL;
4394
4395 VkDescriptorSetLayout descriptor_set_layout;
4396 VkDescriptorSetLayoutCreateInfo dslci = {};
4397 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4398 dslci.pNext = NULL;
4399 dslci.bindingCount = 1;
4400 dslci.pBindings = layout_bindings;
4401 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004402 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004403
4404 VkPipelineLayout pipeline_layout;
4405 VkPipelineLayoutCreateInfo plci = {};
4406 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4407 plci.pNext = NULL;
4408 plci.setLayoutCount = 1;
4409 plci.pSetLayouts = &descriptor_set_layout;
4410 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004411 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004412
Tony Barbour552f6c02016-12-21 14:34:07 -07004413 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004414 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4415 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004416 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004417 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004418 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4419 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004420}
4421
Karl Schultz6addd812016-02-02 17:17:23 -07004422TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004423 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4424 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004425 uint64_t fake_layout_handle = 0xbaad6001;
4426 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004428 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004429 VkPipelineLayout pipeline_layout;
4430 VkPipelineLayoutCreateInfo plci = {};
4431 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4432 plci.pNext = NULL;
4433 plci.setLayoutCount = 1;
4434 plci.pSetLayouts = &bad_layout;
4435 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4436
4437 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004438}
4439
Mark Muellerd4914412016-06-13 17:52:06 -06004440TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004441 TEST_DESCRIPTION(
4442 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4443 "1) A uniform buffer update must have a valid buffer index."
4444 "2) When using an array of descriptors in a single WriteDescriptor,"
4445 " the descriptor types and stageflags must all be the same."
4446 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004447
Mike Weiblena6666382017-01-05 15:16:11 -07004448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004449
4450 ASSERT_NO_FATAL_FAILURE(InitState());
4451 VkDescriptorPoolSize ds_type_count[4] = {};
4452 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4453 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004454 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004455 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004456 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004457 ds_type_count[2].descriptorCount = 1;
4458 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4459 ds_type_count[3].descriptorCount = 1;
4460
4461 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4462 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4463 ds_pool_ci.maxSets = 1;
4464 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4465 ds_pool_ci.pPoolSizes = ds_type_count;
4466
4467 VkDescriptorPool ds_pool;
4468 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4469 ASSERT_VK_SUCCESS(err);
4470
Mark Muellerb9896722016-06-16 09:54:29 -06004471 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004472 layout_binding[0].binding = 0;
4473 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4474 layout_binding[0].descriptorCount = 1;
4475 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4476 layout_binding[0].pImmutableSamplers = NULL;
4477
4478 layout_binding[1].binding = 1;
4479 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4480 layout_binding[1].descriptorCount = 1;
4481 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4482 layout_binding[1].pImmutableSamplers = NULL;
4483
4484 VkSamplerCreateInfo sampler_ci = {};
4485 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4486 sampler_ci.pNext = NULL;
4487 sampler_ci.magFilter = VK_FILTER_NEAREST;
4488 sampler_ci.minFilter = VK_FILTER_NEAREST;
4489 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4490 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4491 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4492 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4493 sampler_ci.mipLodBias = 1.0;
4494 sampler_ci.anisotropyEnable = VK_FALSE;
4495 sampler_ci.maxAnisotropy = 1;
4496 sampler_ci.compareEnable = VK_FALSE;
4497 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4498 sampler_ci.minLod = 1.0;
4499 sampler_ci.maxLod = 1.0;
4500 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4501 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4502 VkSampler sampler;
4503
4504 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4505 ASSERT_VK_SUCCESS(err);
4506
4507 layout_binding[2].binding = 2;
4508 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4509 layout_binding[2].descriptorCount = 1;
4510 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4511 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4512
Mark Muellerd4914412016-06-13 17:52:06 -06004513 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4514 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4515 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4516 ds_layout_ci.pBindings = layout_binding;
4517 VkDescriptorSetLayout ds_layout;
4518 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4519 ASSERT_VK_SUCCESS(err);
4520
4521 VkDescriptorSetAllocateInfo alloc_info = {};
4522 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4523 alloc_info.descriptorSetCount = 1;
4524 alloc_info.descriptorPool = ds_pool;
4525 alloc_info.pSetLayouts = &ds_layout;
4526 VkDescriptorSet descriptorSet;
4527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4528 ASSERT_VK_SUCCESS(err);
4529
4530 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4531 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4532 pipeline_layout_ci.pNext = NULL;
4533 pipeline_layout_ci.setLayoutCount = 1;
4534 pipeline_layout_ci.pSetLayouts = &ds_layout;
4535
4536 VkPipelineLayout pipeline_layout;
4537 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4538 ASSERT_VK_SUCCESS(err);
4539
Mark Mueller5c838ce2016-06-16 09:54:29 -06004540 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004541 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4542 descriptor_write.dstSet = descriptorSet;
4543 descriptor_write.dstBinding = 0;
4544 descriptor_write.descriptorCount = 1;
4545 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4546
Mark Mueller5c838ce2016-06-16 09:54:29 -06004547 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004548 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4549 m_errorMonitor->VerifyFound();
4550
4551 // Create a buffer to update the descriptor with
4552 uint32_t qfi = 0;
4553 VkBufferCreateInfo buffCI = {};
4554 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4555 buffCI.size = 1024;
4556 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4557 buffCI.queueFamilyIndexCount = 1;
4558 buffCI.pQueueFamilyIndices = &qfi;
4559
4560 VkBuffer dyub;
4561 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4562 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004563
Tony Barboure132c5f2016-12-12 11:50:20 -07004564 VkDeviceMemory mem;
4565 VkMemoryRequirements mem_reqs;
4566 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4567
4568 VkMemoryAllocateInfo mem_alloc_info = {};
4569 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4570 mem_alloc_info.allocationSize = mem_reqs.size;
4571 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4572 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4573 ASSERT_VK_SUCCESS(err);
4574
4575 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4576 ASSERT_VK_SUCCESS(err);
4577
4578 VkDescriptorBufferInfo buffInfo[2] = {};
4579 buffInfo[0].buffer = dyub;
4580 buffInfo[0].offset = 0;
4581 buffInfo[0].range = 1024;
4582 buffInfo[1].buffer = dyub;
4583 buffInfo[1].offset = 0;
4584 buffInfo[1].range = 1024;
4585 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004586 descriptor_write.descriptorCount = 2;
4587
Mark Mueller5c838ce2016-06-16 09:54:29 -06004588 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004590 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4591 m_errorMonitor->VerifyFound();
4592
Mark Mueller5c838ce2016-06-16 09:54:29 -06004593 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4594 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004595 descriptor_write.dstBinding = 1;
4596 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004597
Mark Mueller5c838ce2016-06-16 09:54:29 -06004598 // Make pImageInfo index non-null to avoid complaints of it missing
4599 VkDescriptorImageInfo imageInfo = {};
4600 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4601 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004603 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4604 m_errorMonitor->VerifyFound();
4605
Mark Muellerd4914412016-06-13 17:52:06 -06004606 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004607 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004608 vkDestroySampler(m_device->device(), sampler, NULL);
4609 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4610 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4611 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4612}
4613
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004614TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004615 TEST_DESCRIPTION(
4616 "Attempt to draw with a command buffer that is invalid "
4617 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004618 ASSERT_NO_FATAL_FAILURE(InitState());
4619
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004620 VkBuffer buffer;
4621 VkDeviceMemory mem;
4622 VkMemoryRequirements mem_reqs;
4623
4624 VkBufferCreateInfo buf_info = {};
4625 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004626 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004627 buf_info.size = 256;
4628 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4629 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4630 ASSERT_VK_SUCCESS(err);
4631
4632 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4633
4634 VkMemoryAllocateInfo alloc_info = {};
4635 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4636 alloc_info.allocationSize = 256;
4637 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004638 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 -06004639 if (!pass) {
4640 vkDestroyBuffer(m_device->device(), buffer, NULL);
4641 return;
4642 }
4643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4644 ASSERT_VK_SUCCESS(err);
4645
4646 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4647 ASSERT_VK_SUCCESS(err);
4648
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004649 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004650 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004651 m_commandBuffer->EndCommandBuffer();
4652
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004654 // Destroy buffer dependency prior to submit to cause ERROR
4655 vkDestroyBuffer(m_device->device(), buffer, NULL);
4656
4657 VkSubmitInfo submit_info = {};
4658 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4659 submit_info.commandBufferCount = 1;
4660 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4661 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4662
4663 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004664 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004665 vkFreeMemory(m_device->handle(), mem, NULL);
4666}
4667
Tobin Ehlisea413442016-09-28 10:23:59 -06004668TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4669 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4670
4671 ASSERT_NO_FATAL_FAILURE(InitState());
4672 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4673
4674 VkDescriptorPoolSize ds_type_count;
4675 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4676 ds_type_count.descriptorCount = 1;
4677
4678 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4679 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4680 ds_pool_ci.maxSets = 1;
4681 ds_pool_ci.poolSizeCount = 1;
4682 ds_pool_ci.pPoolSizes = &ds_type_count;
4683
4684 VkDescriptorPool ds_pool;
4685 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4686 ASSERT_VK_SUCCESS(err);
4687
4688 VkDescriptorSetLayoutBinding layout_binding;
4689 layout_binding.binding = 0;
4690 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4691 layout_binding.descriptorCount = 1;
4692 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4693 layout_binding.pImmutableSamplers = NULL;
4694
4695 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4696 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4697 ds_layout_ci.bindingCount = 1;
4698 ds_layout_ci.pBindings = &layout_binding;
4699 VkDescriptorSetLayout ds_layout;
4700 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4701 ASSERT_VK_SUCCESS(err);
4702
4703 VkDescriptorSetAllocateInfo alloc_info = {};
4704 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4705 alloc_info.descriptorSetCount = 1;
4706 alloc_info.descriptorPool = ds_pool;
4707 alloc_info.pSetLayouts = &ds_layout;
4708 VkDescriptorSet descriptor_set;
4709 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4710 ASSERT_VK_SUCCESS(err);
4711
4712 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4713 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4714 pipeline_layout_ci.pNext = NULL;
4715 pipeline_layout_ci.setLayoutCount = 1;
4716 pipeline_layout_ci.pSetLayouts = &ds_layout;
4717
4718 VkPipelineLayout pipeline_layout;
4719 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4720 ASSERT_VK_SUCCESS(err);
4721
4722 VkBuffer buffer;
4723 uint32_t queue_family_index = 0;
4724 VkBufferCreateInfo buffer_create_info = {};
4725 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4726 buffer_create_info.size = 1024;
4727 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4728 buffer_create_info.queueFamilyIndexCount = 1;
4729 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4730
4731 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4732 ASSERT_VK_SUCCESS(err);
4733
4734 VkMemoryRequirements memory_reqs;
4735 VkDeviceMemory buffer_memory;
4736
4737 VkMemoryAllocateInfo memory_info = {};
4738 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4739 memory_info.allocationSize = 0;
4740 memory_info.memoryTypeIndex = 0;
4741
4742 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4743 memory_info.allocationSize = memory_reqs.size;
4744 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4745 ASSERT_TRUE(pass);
4746
4747 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4748 ASSERT_VK_SUCCESS(err);
4749 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4750 ASSERT_VK_SUCCESS(err);
4751
4752 VkBufferView view;
4753 VkBufferViewCreateInfo bvci = {};
4754 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4755 bvci.buffer = buffer;
4756 bvci.format = VK_FORMAT_R8_UNORM;
4757 bvci.range = VK_WHOLE_SIZE;
4758
4759 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4760 ASSERT_VK_SUCCESS(err);
4761
4762 VkWriteDescriptorSet descriptor_write = {};
4763 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4764 descriptor_write.dstSet = descriptor_set;
4765 descriptor_write.dstBinding = 0;
4766 descriptor_write.descriptorCount = 1;
4767 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4768 descriptor_write.pTexelBufferView = &view;
4769
4770 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4771
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004772 char const *vsSource =
4773 "#version 450\n"
4774 "\n"
4775 "out gl_PerVertex { \n"
4776 " vec4 gl_Position;\n"
4777 "};\n"
4778 "void main(){\n"
4779 " gl_Position = vec4(1);\n"
4780 "}\n";
4781 char const *fsSource =
4782 "#version 450\n"
4783 "\n"
4784 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4785 "layout(location=0) out vec4 x;\n"
4786 "void main(){\n"
4787 " x = imageLoad(s, 0);\n"
4788 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004789 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4790 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4791 VkPipelineObj pipe(m_device);
4792 pipe.AddShader(&vs);
4793 pipe.AddShader(&fs);
4794 pipe.AddColorAttachment();
4795 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4796
Tobin Ehlisea413442016-09-28 10:23:59 -06004797 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4798
Tony Barbour552f6c02016-12-21 14:34:07 -07004799 m_commandBuffer->BeginCommandBuffer();
4800 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4801
Tobin Ehlisea413442016-09-28 10:23:59 -06004802 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4803 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4804 VkRect2D scissor = {{0, 0}, {16, 16}};
4805 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4806 // Bind pipeline to cmd buffer
4807 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4808 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4809 &descriptor_set, 0, nullptr);
4810 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004811 m_commandBuffer->EndRenderPass();
4812 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004813
4814 // Delete BufferView in order to invalidate cmd buffer
4815 vkDestroyBufferView(m_device->device(), view, NULL);
4816 // Now attempt submit of cmd buffer
4817 VkSubmitInfo submit_info = {};
4818 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4819 submit_info.commandBufferCount = 1;
4820 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4821 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4822 m_errorMonitor->VerifyFound();
4823
4824 // Clean-up
4825 vkDestroyBuffer(m_device->device(), buffer, NULL);
4826 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4827 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4828 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4829 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4830}
4831
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004832TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004833 TEST_DESCRIPTION(
4834 "Attempt to draw with a command buffer that is invalid "
4835 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004836 ASSERT_NO_FATAL_FAILURE(InitState());
4837
4838 VkImage image;
4839 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4840 VkImageCreateInfo image_create_info = {};
4841 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4842 image_create_info.pNext = NULL;
4843 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4844 image_create_info.format = tex_format;
4845 image_create_info.extent.width = 32;
4846 image_create_info.extent.height = 32;
4847 image_create_info.extent.depth = 1;
4848 image_create_info.mipLevels = 1;
4849 image_create_info.arrayLayers = 1;
4850 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4851 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004852 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004853 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004854 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004855 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004856 // Have to bind memory to image before recording cmd in cmd buffer using it
4857 VkMemoryRequirements mem_reqs;
4858 VkDeviceMemory image_mem;
4859 bool pass;
4860 VkMemoryAllocateInfo mem_alloc = {};
4861 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4862 mem_alloc.pNext = NULL;
4863 mem_alloc.memoryTypeIndex = 0;
4864 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4865 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004866 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004867 ASSERT_TRUE(pass);
4868 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4869 ASSERT_VK_SUCCESS(err);
4870 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4871 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004872
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004873 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004874 VkClearColorValue ccv;
4875 ccv.float32[0] = 1.0f;
4876 ccv.float32[1] = 1.0f;
4877 ccv.float32[2] = 1.0f;
4878 ccv.float32[3] = 1.0f;
4879 VkImageSubresourceRange isr = {};
4880 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004881 isr.baseArrayLayer = 0;
4882 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004883 isr.layerCount = 1;
4884 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004885 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004886 m_commandBuffer->EndCommandBuffer();
4887
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004889 // Destroy image dependency prior to submit to cause ERROR
4890 vkDestroyImage(m_device->device(), image, NULL);
4891
4892 VkSubmitInfo submit_info = {};
4893 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4894 submit_info.commandBufferCount = 1;
4895 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4896 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4897
4898 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004899 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900}
4901
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004902TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004903 TEST_DESCRIPTION(
4904 "Attempt to draw with a command buffer that is invalid "
4905 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004906 VkFormatProperties format_properties;
4907 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004908 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4909 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004910 return;
4911 }
4912
4913 ASSERT_NO_FATAL_FAILURE(InitState());
4914 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4915
4916 VkImageCreateInfo image_ci = {};
4917 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4918 image_ci.pNext = NULL;
4919 image_ci.imageType = VK_IMAGE_TYPE_2D;
4920 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4921 image_ci.extent.width = 32;
4922 image_ci.extent.height = 32;
4923 image_ci.extent.depth = 1;
4924 image_ci.mipLevels = 1;
4925 image_ci.arrayLayers = 1;
4926 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4927 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004928 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004929 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4930 image_ci.flags = 0;
4931 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004932 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004933
4934 VkMemoryRequirements memory_reqs;
4935 VkDeviceMemory image_memory;
4936 bool pass;
4937 VkMemoryAllocateInfo memory_info = {};
4938 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4939 memory_info.pNext = NULL;
4940 memory_info.allocationSize = 0;
4941 memory_info.memoryTypeIndex = 0;
4942 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4943 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004944 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004945 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004946 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004947 ASSERT_VK_SUCCESS(err);
4948 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4949 ASSERT_VK_SUCCESS(err);
4950
4951 VkImageViewCreateInfo ivci = {
4952 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4953 nullptr,
4954 0,
4955 image,
4956 VK_IMAGE_VIEW_TYPE_2D,
4957 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004958 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004959 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4960 };
4961 VkImageView view;
4962 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4963 ASSERT_VK_SUCCESS(err);
4964
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004965 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004966 VkFramebuffer fb;
4967 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4968 ASSERT_VK_SUCCESS(err);
4969
4970 // Just use default renderpass with our framebuffer
4971 m_renderPassBeginInfo.framebuffer = fb;
4972 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004973 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004974 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07004975 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4976 m_commandBuffer->EndRenderPass();
4977 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004978 // Destroy image attached to framebuffer to invalidate cmd buffer
4979 vkDestroyImage(m_device->device(), image, NULL);
4980 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004981 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004982 QueueCommandBuffer(false);
4983 m_errorMonitor->VerifyFound();
4984
4985 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4986 vkDestroyImageView(m_device->device(), view, nullptr);
4987 vkFreeMemory(m_device->device(), image_memory, nullptr);
4988}
4989
Tobin Ehlisb329f992016-10-12 13:20:29 -06004990TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4991 TEST_DESCRIPTION("Delete in-use framebuffer.");
4992 VkFormatProperties format_properties;
4993 VkResult err = VK_SUCCESS;
4994 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4995
4996 ASSERT_NO_FATAL_FAILURE(InitState());
4997 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4998
4999 VkImageObj image(m_device);
5000 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5001 ASSERT_TRUE(image.initialized());
5002 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5003
5004 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5005 VkFramebuffer fb;
5006 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5007 ASSERT_VK_SUCCESS(err);
5008
5009 // Just use default renderpass with our framebuffer
5010 m_renderPassBeginInfo.framebuffer = fb;
5011 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005012 m_commandBuffer->BeginCommandBuffer();
5013 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5014 m_commandBuffer->EndRenderPass();
5015 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005016 // Submit cmd buffer to put it in-flight
5017 VkSubmitInfo submit_info = {};
5018 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5019 submit_info.commandBufferCount = 1;
5020 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5021 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5022 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005024 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5025 m_errorMonitor->VerifyFound();
5026 // Wait for queue to complete so we can safely destroy everything
5027 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005028 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5029 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005030 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5031}
5032
Tobin Ehlis88becd72016-09-21 14:33:41 -06005033TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5034 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5035 VkFormatProperties format_properties;
5036 VkResult err = VK_SUCCESS;
5037 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005038
5039 ASSERT_NO_FATAL_FAILURE(InitState());
5040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5041
5042 VkImageCreateInfo image_ci = {};
5043 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5044 image_ci.pNext = NULL;
5045 image_ci.imageType = VK_IMAGE_TYPE_2D;
5046 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5047 image_ci.extent.width = 256;
5048 image_ci.extent.height = 256;
5049 image_ci.extent.depth = 1;
5050 image_ci.mipLevels = 1;
5051 image_ci.arrayLayers = 1;
5052 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5053 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005054 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005055 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5056 image_ci.flags = 0;
5057 VkImage image;
5058 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5059
5060 VkMemoryRequirements memory_reqs;
5061 VkDeviceMemory image_memory;
5062 bool pass;
5063 VkMemoryAllocateInfo memory_info = {};
5064 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5065 memory_info.pNext = NULL;
5066 memory_info.allocationSize = 0;
5067 memory_info.memoryTypeIndex = 0;
5068 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5069 memory_info.allocationSize = memory_reqs.size;
5070 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5071 ASSERT_TRUE(pass);
5072 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5073 ASSERT_VK_SUCCESS(err);
5074 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5075 ASSERT_VK_SUCCESS(err);
5076
5077 VkImageViewCreateInfo ivci = {
5078 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5079 nullptr,
5080 0,
5081 image,
5082 VK_IMAGE_VIEW_TYPE_2D,
5083 VK_FORMAT_B8G8R8A8_UNORM,
5084 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5085 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5086 };
5087 VkImageView view;
5088 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5089 ASSERT_VK_SUCCESS(err);
5090
5091 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5092 VkFramebuffer fb;
5093 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5094 ASSERT_VK_SUCCESS(err);
5095
5096 // Just use default renderpass with our framebuffer
5097 m_renderPassBeginInfo.framebuffer = fb;
5098 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005099 m_commandBuffer->BeginCommandBuffer();
5100 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5101 m_commandBuffer->EndRenderPass();
5102 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005103 // Submit cmd buffer to put it (and attached imageView) in-flight
5104 VkSubmitInfo submit_info = {};
5105 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5106 submit_info.commandBufferCount = 1;
5107 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5108 // Submit cmd buffer to put framebuffer and children in-flight
5109 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5110 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005111 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005112 vkDestroyImage(m_device->device(), image, NULL);
5113 m_errorMonitor->VerifyFound();
5114 // Wait for queue to complete so we can safely destroy image and other objects
5115 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005116 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5117 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005118 vkDestroyImage(m_device->device(), image, NULL);
5119 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5120 vkDestroyImageView(m_device->device(), view, nullptr);
5121 vkFreeMemory(m_device->device(), image_memory, nullptr);
5122}
5123
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005124TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5125 TEST_DESCRIPTION("Delete in-use renderPass.");
5126
5127 ASSERT_NO_FATAL_FAILURE(InitState());
5128 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5129
5130 // Create simple renderpass
5131 VkAttachmentReference attach = {};
5132 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5133 VkSubpassDescription subpass = {};
5134 subpass.pColorAttachments = &attach;
5135 VkRenderPassCreateInfo rpci = {};
5136 rpci.subpassCount = 1;
5137 rpci.pSubpasses = &subpass;
5138 rpci.attachmentCount = 1;
5139 VkAttachmentDescription attach_desc = {};
5140 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5141 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5142 rpci.pAttachments = &attach_desc;
5143 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5144 VkRenderPass rp;
5145 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5146 ASSERT_VK_SUCCESS(err);
5147
5148 // Create a pipeline that uses the given renderpass
5149 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5150 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5151
5152 VkPipelineLayout pipeline_layout;
5153 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5154 ASSERT_VK_SUCCESS(err);
5155
5156 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5157 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5158 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005159 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005160 vp_state_ci.pViewports = &vp;
5161 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005162 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005163 vp_state_ci.pScissors = &scissors;
5164
5165 VkPipelineShaderStageCreateInfo shaderStages[2];
5166 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5167
5168 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005169 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 -06005170 // but add it to be able to run on more devices
5171 shaderStages[0] = vs.GetStageCreateInfo();
5172 shaderStages[1] = fs.GetStageCreateInfo();
5173
5174 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5175 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5176
5177 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5178 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5179 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5180
5181 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5182 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5183 rs_ci.rasterizerDiscardEnable = true;
5184 rs_ci.lineWidth = 1.0f;
5185
5186 VkPipelineColorBlendAttachmentState att = {};
5187 att.blendEnable = VK_FALSE;
5188 att.colorWriteMask = 0xf;
5189
5190 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5191 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5192 cb_ci.attachmentCount = 1;
5193 cb_ci.pAttachments = &att;
5194
5195 VkGraphicsPipelineCreateInfo gp_ci = {};
5196 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5197 gp_ci.stageCount = 2;
5198 gp_ci.pStages = shaderStages;
5199 gp_ci.pVertexInputState = &vi_ci;
5200 gp_ci.pInputAssemblyState = &ia_ci;
5201 gp_ci.pViewportState = &vp_state_ci;
5202 gp_ci.pRasterizationState = &rs_ci;
5203 gp_ci.pColorBlendState = &cb_ci;
5204 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5205 gp_ci.layout = pipeline_layout;
5206 gp_ci.renderPass = rp;
5207
5208 VkPipelineCacheCreateInfo pc_ci = {};
5209 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5210
5211 VkPipeline pipeline;
5212 VkPipelineCache pipe_cache;
5213 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5214 ASSERT_VK_SUCCESS(err);
5215
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005216 m_errorMonitor->SetUnexpectedError(
5217 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5218 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005219 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5220 ASSERT_VK_SUCCESS(err);
5221 // Bind pipeline to cmd buffer, will also bind renderpass
5222 m_commandBuffer->BeginCommandBuffer();
5223 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5224 m_commandBuffer->EndCommandBuffer();
5225
5226 VkSubmitInfo submit_info = {};
5227 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5228 submit_info.commandBufferCount = 1;
5229 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5230 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5231
5232 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5233 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5234 m_errorMonitor->VerifyFound();
5235
5236 // Wait for queue to complete so we can safely destroy everything
5237 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005238 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5239 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005240 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5241 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5242 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5243 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5244}
5245
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005246TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005247 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005248 ASSERT_NO_FATAL_FAILURE(InitState());
5249
5250 VkImage image;
5251 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5252 VkImageCreateInfo image_create_info = {};
5253 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5254 image_create_info.pNext = NULL;
5255 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5256 image_create_info.format = tex_format;
5257 image_create_info.extent.width = 32;
5258 image_create_info.extent.height = 32;
5259 image_create_info.extent.depth = 1;
5260 image_create_info.mipLevels = 1;
5261 image_create_info.arrayLayers = 1;
5262 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5263 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005264 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005265 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005266 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005267 ASSERT_VK_SUCCESS(err);
5268 // Have to bind memory to image before recording cmd in cmd buffer using it
5269 VkMemoryRequirements mem_reqs;
5270 VkDeviceMemory image_mem;
5271 bool pass;
5272 VkMemoryAllocateInfo mem_alloc = {};
5273 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5274 mem_alloc.pNext = NULL;
5275 mem_alloc.memoryTypeIndex = 0;
5276 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5277 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005278 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005279 ASSERT_TRUE(pass);
5280 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5281 ASSERT_VK_SUCCESS(err);
5282
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005283 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005285 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005286
5287 m_commandBuffer->BeginCommandBuffer();
5288 VkClearColorValue ccv;
5289 ccv.float32[0] = 1.0f;
5290 ccv.float32[1] = 1.0f;
5291 ccv.float32[2] = 1.0f;
5292 ccv.float32[3] = 1.0f;
5293 VkImageSubresourceRange isr = {};
5294 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5295 isr.baseArrayLayer = 0;
5296 isr.baseMipLevel = 0;
5297 isr.layerCount = 1;
5298 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005299 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005300 m_commandBuffer->EndCommandBuffer();
5301
5302 m_errorMonitor->VerifyFound();
5303 vkDestroyImage(m_device->device(), image, NULL);
5304 vkFreeMemory(m_device->device(), image_mem, nullptr);
5305}
5306
5307TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005308 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005309 ASSERT_NO_FATAL_FAILURE(InitState());
5310
5311 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005312 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 -06005313 VK_IMAGE_TILING_OPTIMAL, 0);
5314 ASSERT_TRUE(image.initialized());
5315
5316 VkBuffer buffer;
5317 VkDeviceMemory mem;
5318 VkMemoryRequirements mem_reqs;
5319
5320 VkBufferCreateInfo buf_info = {};
5321 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005322 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005323 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005324 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5325 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5326 ASSERT_VK_SUCCESS(err);
5327
5328 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5329
5330 VkMemoryAllocateInfo alloc_info = {};
5331 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005332 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005333 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005334 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 -06005335 if (!pass) {
5336 vkDestroyBuffer(m_device->device(), buffer, NULL);
5337 return;
5338 }
5339 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5340 ASSERT_VK_SUCCESS(err);
5341
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005342 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005344 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005345 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005346 region.bufferRowLength = 16;
5347 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005348 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5349
5350 region.imageSubresource.layerCount = 1;
5351 region.imageExtent.height = 4;
5352 region.imageExtent.width = 4;
5353 region.imageExtent.depth = 1;
5354 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005355 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5356 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005357 m_commandBuffer->EndCommandBuffer();
5358
5359 m_errorMonitor->VerifyFound();
5360
5361 vkDestroyBuffer(m_device->device(), buffer, NULL);
5362 vkFreeMemory(m_device->handle(), mem, NULL);
5363}
5364
Tobin Ehlis85940f52016-07-07 16:57:21 -06005365TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005366 TEST_DESCRIPTION(
5367 "Attempt to draw with a command buffer that is invalid "
5368 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005369 ASSERT_NO_FATAL_FAILURE(InitState());
5370
5371 VkEvent event;
5372 VkEventCreateInfo evci = {};
5373 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5374 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5375 ASSERT_VK_SUCCESS(result);
5376
5377 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005378 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005379 m_commandBuffer->EndCommandBuffer();
5380
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005382 // Destroy event dependency prior to submit to cause ERROR
5383 vkDestroyEvent(m_device->device(), event, NULL);
5384
5385 VkSubmitInfo submit_info = {};
5386 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5387 submit_info.commandBufferCount = 1;
5388 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5389 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5390
5391 m_errorMonitor->VerifyFound();
5392}
5393
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005394TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005395 TEST_DESCRIPTION(
5396 "Attempt to draw with a command buffer that is invalid "
5397 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005398 ASSERT_NO_FATAL_FAILURE(InitState());
5399
5400 VkQueryPool query_pool;
5401 VkQueryPoolCreateInfo qpci{};
5402 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5403 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5404 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005405 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005406 ASSERT_VK_SUCCESS(result);
5407
5408 m_commandBuffer->BeginCommandBuffer();
5409 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5410 m_commandBuffer->EndCommandBuffer();
5411
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005412 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005413 // Destroy query pool dependency prior to submit to cause ERROR
5414 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5415
5416 VkSubmitInfo submit_info = {};
5417 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5418 submit_info.commandBufferCount = 1;
5419 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5420 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5421
5422 m_errorMonitor->VerifyFound();
5423}
5424
Tobin Ehlis24130d92016-07-08 15:50:53 -06005425TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005426 TEST_DESCRIPTION(
5427 "Attempt to draw with a command buffer that is invalid "
5428 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005429 ASSERT_NO_FATAL_FAILURE(InitState());
5430 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5431
5432 VkResult err;
5433
5434 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5435 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5436
5437 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005438 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005439 ASSERT_VK_SUCCESS(err);
5440
5441 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5442 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5443 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005444 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005445 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005446 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005447 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005448 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005449
5450 VkPipelineShaderStageCreateInfo shaderStages[2];
5451 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5452
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005453 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005454 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 -06005455 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005456 shaderStages[0] = vs.GetStageCreateInfo();
5457 shaderStages[1] = fs.GetStageCreateInfo();
5458
5459 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5460 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5461
5462 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5463 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5464 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5465
5466 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5467 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005468 rs_ci.rasterizerDiscardEnable = true;
5469 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005470
5471 VkPipelineColorBlendAttachmentState att = {};
5472 att.blendEnable = VK_FALSE;
5473 att.colorWriteMask = 0xf;
5474
5475 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5476 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5477 cb_ci.attachmentCount = 1;
5478 cb_ci.pAttachments = &att;
5479
5480 VkGraphicsPipelineCreateInfo gp_ci = {};
5481 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5482 gp_ci.stageCount = 2;
5483 gp_ci.pStages = shaderStages;
5484 gp_ci.pVertexInputState = &vi_ci;
5485 gp_ci.pInputAssemblyState = &ia_ci;
5486 gp_ci.pViewportState = &vp_state_ci;
5487 gp_ci.pRasterizationState = &rs_ci;
5488 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005489 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5490 gp_ci.layout = pipeline_layout;
5491 gp_ci.renderPass = renderPass();
5492
5493 VkPipelineCacheCreateInfo pc_ci = {};
5494 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5495
5496 VkPipeline pipeline;
5497 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005498 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005499 ASSERT_VK_SUCCESS(err);
5500
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005501 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005502 ASSERT_VK_SUCCESS(err);
5503
5504 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005505 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005506 m_commandBuffer->EndCommandBuffer();
5507 // Now destroy pipeline in order to cause error when submitting
5508 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5509
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005511
5512 VkSubmitInfo submit_info = {};
5513 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5514 submit_info.commandBufferCount = 1;
5515 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5516 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5517
5518 m_errorMonitor->VerifyFound();
5519 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5520 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5521}
5522
Tobin Ehlis31289162016-08-17 14:57:58 -06005523TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005524 TEST_DESCRIPTION(
5525 "Attempt to draw with a command buffer that is invalid "
5526 "due to a bound descriptor set with a buffer dependency "
5527 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005528 ASSERT_NO_FATAL_FAILURE(InitState());
5529 ASSERT_NO_FATAL_FAILURE(InitViewport());
5530 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5531
5532 VkDescriptorPoolSize ds_type_count = {};
5533 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5534 ds_type_count.descriptorCount = 1;
5535
5536 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5537 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5538 ds_pool_ci.pNext = NULL;
5539 ds_pool_ci.maxSets = 1;
5540 ds_pool_ci.poolSizeCount = 1;
5541 ds_pool_ci.pPoolSizes = &ds_type_count;
5542
5543 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005544 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005545 ASSERT_VK_SUCCESS(err);
5546
5547 VkDescriptorSetLayoutBinding dsl_binding = {};
5548 dsl_binding.binding = 0;
5549 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5550 dsl_binding.descriptorCount = 1;
5551 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5552 dsl_binding.pImmutableSamplers = NULL;
5553
5554 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5555 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5556 ds_layout_ci.pNext = NULL;
5557 ds_layout_ci.bindingCount = 1;
5558 ds_layout_ci.pBindings = &dsl_binding;
5559 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005560 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005561 ASSERT_VK_SUCCESS(err);
5562
5563 VkDescriptorSet descriptorSet;
5564 VkDescriptorSetAllocateInfo alloc_info = {};
5565 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5566 alloc_info.descriptorSetCount = 1;
5567 alloc_info.descriptorPool = ds_pool;
5568 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005569 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005570 ASSERT_VK_SUCCESS(err);
5571
5572 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5573 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5574 pipeline_layout_ci.pNext = NULL;
5575 pipeline_layout_ci.setLayoutCount = 1;
5576 pipeline_layout_ci.pSetLayouts = &ds_layout;
5577
5578 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005579 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005580 ASSERT_VK_SUCCESS(err);
5581
5582 // Create a buffer to update the descriptor with
5583 uint32_t qfi = 0;
5584 VkBufferCreateInfo buffCI = {};
5585 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5586 buffCI.size = 1024;
5587 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5588 buffCI.queueFamilyIndexCount = 1;
5589 buffCI.pQueueFamilyIndices = &qfi;
5590
5591 VkBuffer buffer;
5592 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5593 ASSERT_VK_SUCCESS(err);
5594 // Allocate memory and bind to buffer so we can make it to the appropriate
5595 // error
5596 VkMemoryAllocateInfo mem_alloc = {};
5597 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5598 mem_alloc.pNext = NULL;
5599 mem_alloc.allocationSize = 1024;
5600 mem_alloc.memoryTypeIndex = 0;
5601
5602 VkMemoryRequirements memReqs;
5603 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005604 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005605 if (!pass) {
5606 vkDestroyBuffer(m_device->device(), buffer, NULL);
5607 return;
5608 }
5609
5610 VkDeviceMemory mem;
5611 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5612 ASSERT_VK_SUCCESS(err);
5613 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5614 ASSERT_VK_SUCCESS(err);
5615 // Correctly update descriptor to avoid "NOT_UPDATED" error
5616 VkDescriptorBufferInfo buffInfo = {};
5617 buffInfo.buffer = buffer;
5618 buffInfo.offset = 0;
5619 buffInfo.range = 1024;
5620
5621 VkWriteDescriptorSet descriptor_write;
5622 memset(&descriptor_write, 0, sizeof(descriptor_write));
5623 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5624 descriptor_write.dstSet = descriptorSet;
5625 descriptor_write.dstBinding = 0;
5626 descriptor_write.descriptorCount = 1;
5627 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5628 descriptor_write.pBufferInfo = &buffInfo;
5629
5630 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5631
5632 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005633 char const *vsSource =
5634 "#version 450\n"
5635 "\n"
5636 "out gl_PerVertex { \n"
5637 " vec4 gl_Position;\n"
5638 "};\n"
5639 "void main(){\n"
5640 " gl_Position = vec4(1);\n"
5641 "}\n";
5642 char const *fsSource =
5643 "#version 450\n"
5644 "\n"
5645 "layout(location=0) out vec4 x;\n"
5646 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5647 "void main(){\n"
5648 " x = vec4(bar.y);\n"
5649 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005650 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5651 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5652 VkPipelineObj pipe(m_device);
5653 pipe.AddShader(&vs);
5654 pipe.AddShader(&fs);
5655 pipe.AddColorAttachment();
5656 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5657
Tony Barbour552f6c02016-12-21 14:34:07 -07005658 m_commandBuffer->BeginCommandBuffer();
5659 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005660 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5661 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5662 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005663
5664 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5665 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5666
Tobin Ehlis31289162016-08-17 14:57:58 -06005667 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005668 m_commandBuffer->EndRenderPass();
5669 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005671 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5672 vkDestroyBuffer(m_device->device(), buffer, NULL);
5673 // Attempt to submit cmd buffer
5674 VkSubmitInfo submit_info = {};
5675 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5676 submit_info.commandBufferCount = 1;
5677 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5678 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5679 m_errorMonitor->VerifyFound();
5680 // Cleanup
5681 vkFreeMemory(m_device->device(), mem, NULL);
5682
5683 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5684 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5685 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5686}
5687
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005688TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005689 TEST_DESCRIPTION(
5690 "Attempt to draw with a command buffer that is invalid "
5691 "due to a bound descriptor sets with a combined image "
5692 "sampler having their image, sampler, and descriptor set "
5693 "each respectively destroyed and then attempting to "
5694 "submit associated cmd buffers. Attempt to destroy a "
5695 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005696 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005697 ASSERT_NO_FATAL_FAILURE(InitViewport());
5698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5699
5700 VkDescriptorPoolSize ds_type_count = {};
5701 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5702 ds_type_count.descriptorCount = 1;
5703
5704 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5705 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5706 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005707 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005708 ds_pool_ci.maxSets = 1;
5709 ds_pool_ci.poolSizeCount = 1;
5710 ds_pool_ci.pPoolSizes = &ds_type_count;
5711
5712 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005713 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005714 ASSERT_VK_SUCCESS(err);
5715
5716 VkDescriptorSetLayoutBinding dsl_binding = {};
5717 dsl_binding.binding = 0;
5718 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5719 dsl_binding.descriptorCount = 1;
5720 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5721 dsl_binding.pImmutableSamplers = NULL;
5722
5723 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5724 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5725 ds_layout_ci.pNext = NULL;
5726 ds_layout_ci.bindingCount = 1;
5727 ds_layout_ci.pBindings = &dsl_binding;
5728 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005729 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005730 ASSERT_VK_SUCCESS(err);
5731
5732 VkDescriptorSet descriptorSet;
5733 VkDescriptorSetAllocateInfo alloc_info = {};
5734 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5735 alloc_info.descriptorSetCount = 1;
5736 alloc_info.descriptorPool = ds_pool;
5737 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005738 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005739 ASSERT_VK_SUCCESS(err);
5740
5741 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5742 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5743 pipeline_layout_ci.pNext = NULL;
5744 pipeline_layout_ci.setLayoutCount = 1;
5745 pipeline_layout_ci.pSetLayouts = &ds_layout;
5746
5747 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005748 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005749 ASSERT_VK_SUCCESS(err);
5750
5751 // Create images to update the descriptor with
5752 VkImage image;
5753 VkImage image2;
5754 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5755 const int32_t tex_width = 32;
5756 const int32_t tex_height = 32;
5757 VkImageCreateInfo image_create_info = {};
5758 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5759 image_create_info.pNext = NULL;
5760 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5761 image_create_info.format = tex_format;
5762 image_create_info.extent.width = tex_width;
5763 image_create_info.extent.height = tex_height;
5764 image_create_info.extent.depth = 1;
5765 image_create_info.mipLevels = 1;
5766 image_create_info.arrayLayers = 1;
5767 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5768 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5769 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5770 image_create_info.flags = 0;
5771 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5772 ASSERT_VK_SUCCESS(err);
5773 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5774 ASSERT_VK_SUCCESS(err);
5775
5776 VkMemoryRequirements memory_reqs;
5777 VkDeviceMemory image_memory;
5778 bool pass;
5779 VkMemoryAllocateInfo memory_info = {};
5780 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5781 memory_info.pNext = NULL;
5782 memory_info.allocationSize = 0;
5783 memory_info.memoryTypeIndex = 0;
5784 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5785 // Allocate enough memory for both images
5786 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005787 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005788 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005789 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005790 ASSERT_VK_SUCCESS(err);
5791 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5792 ASSERT_VK_SUCCESS(err);
5793 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005795 ASSERT_VK_SUCCESS(err);
5796
5797 VkImageViewCreateInfo image_view_create_info = {};
5798 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5799 image_view_create_info.image = image;
5800 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5801 image_view_create_info.format = tex_format;
5802 image_view_create_info.subresourceRange.layerCount = 1;
5803 image_view_create_info.subresourceRange.baseMipLevel = 0;
5804 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005805 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005806
5807 VkImageView view;
5808 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005809 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005810 ASSERT_VK_SUCCESS(err);
5811 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005812 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005813 ASSERT_VK_SUCCESS(err);
5814 // Create Samplers
5815 VkSamplerCreateInfo sampler_ci = {};
5816 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5817 sampler_ci.pNext = NULL;
5818 sampler_ci.magFilter = VK_FILTER_NEAREST;
5819 sampler_ci.minFilter = VK_FILTER_NEAREST;
5820 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5821 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5822 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5823 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5824 sampler_ci.mipLodBias = 1.0;
5825 sampler_ci.anisotropyEnable = VK_FALSE;
5826 sampler_ci.maxAnisotropy = 1;
5827 sampler_ci.compareEnable = VK_FALSE;
5828 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5829 sampler_ci.minLod = 1.0;
5830 sampler_ci.maxLod = 1.0;
5831 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5832 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5833 VkSampler sampler;
5834 VkSampler sampler2;
5835 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5836 ASSERT_VK_SUCCESS(err);
5837 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5838 ASSERT_VK_SUCCESS(err);
5839 // Update descriptor with image and sampler
5840 VkDescriptorImageInfo img_info = {};
5841 img_info.sampler = sampler;
5842 img_info.imageView = view;
5843 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5844
5845 VkWriteDescriptorSet descriptor_write;
5846 memset(&descriptor_write, 0, sizeof(descriptor_write));
5847 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5848 descriptor_write.dstSet = descriptorSet;
5849 descriptor_write.dstBinding = 0;
5850 descriptor_write.descriptorCount = 1;
5851 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5852 descriptor_write.pImageInfo = &img_info;
5853
5854 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5855
5856 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005857 char const *vsSource =
5858 "#version 450\n"
5859 "\n"
5860 "out gl_PerVertex { \n"
5861 " vec4 gl_Position;\n"
5862 "};\n"
5863 "void main(){\n"
5864 " gl_Position = vec4(1);\n"
5865 "}\n";
5866 char const *fsSource =
5867 "#version 450\n"
5868 "\n"
5869 "layout(set=0, binding=0) uniform sampler2D s;\n"
5870 "layout(location=0) out vec4 x;\n"
5871 "void main(){\n"
5872 " x = texture(s, vec2(1));\n"
5873 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005874 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5875 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5876 VkPipelineObj pipe(m_device);
5877 pipe.AddShader(&vs);
5878 pipe.AddShader(&fs);
5879 pipe.AddColorAttachment();
5880 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5881
5882 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005884 m_commandBuffer->BeginCommandBuffer();
5885 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005886 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5887 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5888 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005889 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5890 VkRect2D scissor = {{0, 0}, {16, 16}};
5891 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5892 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005893 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005894 m_commandBuffer->EndRenderPass();
5895 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005896 // Destroy sampler invalidates the cmd buffer, causing error on submit
5897 vkDestroySampler(m_device->device(), sampler, NULL);
5898 // Attempt to submit cmd buffer
5899 VkSubmitInfo submit_info = {};
5900 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5901 submit_info.commandBufferCount = 1;
5902 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5903 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5904 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005905
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005906 // Now re-update descriptor with valid sampler and delete image
5907 img_info.sampler = sampler2;
5908 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005909
5910 VkCommandBufferBeginInfo info = {};
5911 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5912 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5913
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005915 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005916 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005917 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5918 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5919 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005920 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5921 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005922 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005923 m_commandBuffer->EndRenderPass();
5924 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005925 // Destroy image invalidates the cmd buffer, causing error on submit
5926 vkDestroyImage(m_device->device(), image, NULL);
5927 // Attempt to submit cmd buffer
5928 submit_info = {};
5929 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5930 submit_info.commandBufferCount = 1;
5931 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5932 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5933 m_errorMonitor->VerifyFound();
5934 // Now update descriptor to be valid, but then free descriptor
5935 img_info.imageView = view2;
5936 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005937 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005938 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005939 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5940 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5941 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005942 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5943 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005944 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005945 m_commandBuffer->EndRenderPass();
5946 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005947 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005948
5949 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005951 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005952 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005953
5954 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005955 // 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 -07005956 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005957 m_errorMonitor->SetUnexpectedError(
5958 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
5959 "either be a valid handle or VK_NULL_HANDLE");
5960 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07005961 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5962
5963 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005964 submit_info = {};
5965 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5966 submit_info.commandBufferCount = 1;
5967 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005969 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5970 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005971
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005972 // Cleanup
5973 vkFreeMemory(m_device->device(), image_memory, NULL);
5974 vkDestroySampler(m_device->device(), sampler2, NULL);
5975 vkDestroyImage(m_device->device(), image2, NULL);
5976 vkDestroyImageView(m_device->device(), view, NULL);
5977 vkDestroyImageView(m_device->device(), view2, NULL);
5978 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5980 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5981}
5982
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005983TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5984 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5985 ASSERT_NO_FATAL_FAILURE(InitState());
5986 ASSERT_NO_FATAL_FAILURE(InitViewport());
5987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5988
5989 VkDescriptorPoolSize ds_type_count = {};
5990 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5991 ds_type_count.descriptorCount = 1;
5992
5993 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5994 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5995 ds_pool_ci.pNext = NULL;
5996 ds_pool_ci.maxSets = 1;
5997 ds_pool_ci.poolSizeCount = 1;
5998 ds_pool_ci.pPoolSizes = &ds_type_count;
5999
6000 VkDescriptorPool ds_pool;
6001 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6002 ASSERT_VK_SUCCESS(err);
6003
6004 VkDescriptorSetLayoutBinding dsl_binding = {};
6005 dsl_binding.binding = 0;
6006 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6007 dsl_binding.descriptorCount = 1;
6008 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6009 dsl_binding.pImmutableSamplers = NULL;
6010
6011 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6012 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6013 ds_layout_ci.pNext = NULL;
6014 ds_layout_ci.bindingCount = 1;
6015 ds_layout_ci.pBindings = &dsl_binding;
6016 VkDescriptorSetLayout ds_layout;
6017 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6018 ASSERT_VK_SUCCESS(err);
6019
6020 VkDescriptorSet descriptor_set;
6021 VkDescriptorSetAllocateInfo alloc_info = {};
6022 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6023 alloc_info.descriptorSetCount = 1;
6024 alloc_info.descriptorPool = ds_pool;
6025 alloc_info.pSetLayouts = &ds_layout;
6026 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6027 ASSERT_VK_SUCCESS(err);
6028
6029 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6030 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6031 pipeline_layout_ci.pNext = NULL;
6032 pipeline_layout_ci.setLayoutCount = 1;
6033 pipeline_layout_ci.pSetLayouts = &ds_layout;
6034
6035 VkPipelineLayout pipeline_layout;
6036 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6037 ASSERT_VK_SUCCESS(err);
6038
6039 // Create image to update the descriptor with
6040 VkImageObj image(m_device);
6041 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6042 ASSERT_TRUE(image.initialized());
6043
6044 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6045 // Create Sampler
6046 VkSamplerCreateInfo sampler_ci = {};
6047 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6048 sampler_ci.pNext = NULL;
6049 sampler_ci.magFilter = VK_FILTER_NEAREST;
6050 sampler_ci.minFilter = VK_FILTER_NEAREST;
6051 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6052 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6053 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6054 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6055 sampler_ci.mipLodBias = 1.0;
6056 sampler_ci.anisotropyEnable = VK_FALSE;
6057 sampler_ci.maxAnisotropy = 1;
6058 sampler_ci.compareEnable = VK_FALSE;
6059 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6060 sampler_ci.minLod = 1.0;
6061 sampler_ci.maxLod = 1.0;
6062 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6063 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6064 VkSampler sampler;
6065 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6066 ASSERT_VK_SUCCESS(err);
6067 // Update descriptor with image and sampler
6068 VkDescriptorImageInfo img_info = {};
6069 img_info.sampler = sampler;
6070 img_info.imageView = view;
6071 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6072
6073 VkWriteDescriptorSet descriptor_write;
6074 memset(&descriptor_write, 0, sizeof(descriptor_write));
6075 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6076 descriptor_write.dstSet = descriptor_set;
6077 descriptor_write.dstBinding = 0;
6078 descriptor_write.descriptorCount = 1;
6079 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6080 descriptor_write.pImageInfo = &img_info;
6081
6082 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6083
6084 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006085 char const *vsSource =
6086 "#version 450\n"
6087 "\n"
6088 "out gl_PerVertex { \n"
6089 " vec4 gl_Position;\n"
6090 "};\n"
6091 "void main(){\n"
6092 " gl_Position = vec4(1);\n"
6093 "}\n";
6094 char const *fsSource =
6095 "#version 450\n"
6096 "\n"
6097 "layout(set=0, binding=0) uniform sampler2D s;\n"
6098 "layout(location=0) out vec4 x;\n"
6099 "void main(){\n"
6100 " x = texture(s, vec2(1));\n"
6101 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006102 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6103 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6104 VkPipelineObj pipe(m_device);
6105 pipe.AddShader(&vs);
6106 pipe.AddShader(&fs);
6107 pipe.AddColorAttachment();
6108 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6109
Tony Barbour552f6c02016-12-21 14:34:07 -07006110 m_commandBuffer->BeginCommandBuffer();
6111 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006112 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6113 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6114 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006115
6116 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6117 VkRect2D scissor = {{0, 0}, {16, 16}};
6118 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6119 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6120
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006121 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006122 m_commandBuffer->EndRenderPass();
6123 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006124 // Submit cmd buffer to put pool in-flight
6125 VkSubmitInfo submit_info = {};
6126 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6127 submit_info.commandBufferCount = 1;
6128 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6129 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6130 // Destroy pool while in-flight, causing error
6131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6132 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6133 m_errorMonitor->VerifyFound();
6134 vkQueueWaitIdle(m_device->m_queue);
6135 // Cleanup
6136 vkDestroySampler(m_device->device(), sampler, NULL);
6137 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6138 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006139 m_errorMonitor->SetUnexpectedError(
6140 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6141 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006143 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006144}
6145
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006146TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6147 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6148 ASSERT_NO_FATAL_FAILURE(InitState());
6149 ASSERT_NO_FATAL_FAILURE(InitViewport());
6150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6151
6152 VkDescriptorPoolSize ds_type_count = {};
6153 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6154 ds_type_count.descriptorCount = 1;
6155
6156 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6157 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6158 ds_pool_ci.pNext = NULL;
6159 ds_pool_ci.maxSets = 1;
6160 ds_pool_ci.poolSizeCount = 1;
6161 ds_pool_ci.pPoolSizes = &ds_type_count;
6162
6163 VkDescriptorPool ds_pool;
6164 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6165 ASSERT_VK_SUCCESS(err);
6166
6167 VkDescriptorSetLayoutBinding dsl_binding = {};
6168 dsl_binding.binding = 0;
6169 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6170 dsl_binding.descriptorCount = 1;
6171 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6172 dsl_binding.pImmutableSamplers = NULL;
6173
6174 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6175 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6176 ds_layout_ci.pNext = NULL;
6177 ds_layout_ci.bindingCount = 1;
6178 ds_layout_ci.pBindings = &dsl_binding;
6179 VkDescriptorSetLayout ds_layout;
6180 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6181 ASSERT_VK_SUCCESS(err);
6182
6183 VkDescriptorSet descriptorSet;
6184 VkDescriptorSetAllocateInfo alloc_info = {};
6185 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6186 alloc_info.descriptorSetCount = 1;
6187 alloc_info.descriptorPool = ds_pool;
6188 alloc_info.pSetLayouts = &ds_layout;
6189 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6190 ASSERT_VK_SUCCESS(err);
6191
6192 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6193 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6194 pipeline_layout_ci.pNext = NULL;
6195 pipeline_layout_ci.setLayoutCount = 1;
6196 pipeline_layout_ci.pSetLayouts = &ds_layout;
6197
6198 VkPipelineLayout pipeline_layout;
6199 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6200 ASSERT_VK_SUCCESS(err);
6201
6202 // Create images to update the descriptor with
6203 VkImage image;
6204 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6205 const int32_t tex_width = 32;
6206 const int32_t tex_height = 32;
6207 VkImageCreateInfo image_create_info = {};
6208 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6209 image_create_info.pNext = NULL;
6210 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6211 image_create_info.format = tex_format;
6212 image_create_info.extent.width = tex_width;
6213 image_create_info.extent.height = tex_height;
6214 image_create_info.extent.depth = 1;
6215 image_create_info.mipLevels = 1;
6216 image_create_info.arrayLayers = 1;
6217 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6218 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6219 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6220 image_create_info.flags = 0;
6221 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6222 ASSERT_VK_SUCCESS(err);
6223 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6224 VkMemoryRequirements memory_reqs;
6225 VkDeviceMemory image_memory;
6226 bool pass;
6227 VkMemoryAllocateInfo memory_info = {};
6228 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6229 memory_info.pNext = NULL;
6230 memory_info.allocationSize = 0;
6231 memory_info.memoryTypeIndex = 0;
6232 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6233 // Allocate enough memory for image
6234 memory_info.allocationSize = memory_reqs.size;
6235 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6236 ASSERT_TRUE(pass);
6237 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6238 ASSERT_VK_SUCCESS(err);
6239 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6240 ASSERT_VK_SUCCESS(err);
6241
6242 VkImageViewCreateInfo image_view_create_info = {};
6243 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6244 image_view_create_info.image = image;
6245 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6246 image_view_create_info.format = tex_format;
6247 image_view_create_info.subresourceRange.layerCount = 1;
6248 image_view_create_info.subresourceRange.baseMipLevel = 0;
6249 image_view_create_info.subresourceRange.levelCount = 1;
6250 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6251
6252 VkImageView view;
6253 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6254 ASSERT_VK_SUCCESS(err);
6255 // Create Samplers
6256 VkSamplerCreateInfo sampler_ci = {};
6257 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6258 sampler_ci.pNext = NULL;
6259 sampler_ci.magFilter = VK_FILTER_NEAREST;
6260 sampler_ci.minFilter = VK_FILTER_NEAREST;
6261 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6262 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6263 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6264 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6265 sampler_ci.mipLodBias = 1.0;
6266 sampler_ci.anisotropyEnable = VK_FALSE;
6267 sampler_ci.maxAnisotropy = 1;
6268 sampler_ci.compareEnable = VK_FALSE;
6269 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6270 sampler_ci.minLod = 1.0;
6271 sampler_ci.maxLod = 1.0;
6272 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6273 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6274 VkSampler sampler;
6275 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6276 ASSERT_VK_SUCCESS(err);
6277 // Update descriptor with image and sampler
6278 VkDescriptorImageInfo img_info = {};
6279 img_info.sampler = sampler;
6280 img_info.imageView = view;
6281 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6282
6283 VkWriteDescriptorSet descriptor_write;
6284 memset(&descriptor_write, 0, sizeof(descriptor_write));
6285 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6286 descriptor_write.dstSet = descriptorSet;
6287 descriptor_write.dstBinding = 0;
6288 descriptor_write.descriptorCount = 1;
6289 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6290 descriptor_write.pImageInfo = &img_info;
6291 // Break memory binding and attempt update
6292 vkFreeMemory(m_device->device(), image_memory, nullptr);
6293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006294 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6296 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6297 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6298 m_errorMonitor->VerifyFound();
6299 // Cleanup
6300 vkDestroyImage(m_device->device(), image, NULL);
6301 vkDestroySampler(m_device->device(), sampler, NULL);
6302 vkDestroyImageView(m_device->device(), view, NULL);
6303 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6304 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6305 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6306}
6307
Karl Schultz6addd812016-02-02 17:17:23 -07006308TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006309 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6310 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006311 // Create a valid cmd buffer
6312 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006313 uint64_t fake_pipeline_handle = 0xbaad6001;
6314 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006315 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006316 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6317
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006319 m_commandBuffer->BeginCommandBuffer();
6320 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006321 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006322 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006323
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006324 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006325 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 -06006326 Draw(1, 0, 0, 0);
6327 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006328
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006329 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006330 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 -07006331 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006332 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6333 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006334}
6335
Karl Schultz6addd812016-02-02 17:17:23 -07006336TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006337 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006338 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006339
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006341
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006342 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006343 ASSERT_NO_FATAL_FAILURE(InitViewport());
6344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006345 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006346 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6347 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006348
6349 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006350 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6351 ds_pool_ci.pNext = NULL;
6352 ds_pool_ci.maxSets = 1;
6353 ds_pool_ci.poolSizeCount = 1;
6354 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006355
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006356 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006357 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006358 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006359
Tony Barboureb254902015-07-15 12:50:33 -06006360 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006361 dsl_binding.binding = 0;
6362 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6363 dsl_binding.descriptorCount = 1;
6364 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6365 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006366
Tony Barboureb254902015-07-15 12:50:33 -06006367 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006368 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6369 ds_layout_ci.pNext = NULL;
6370 ds_layout_ci.bindingCount = 1;
6371 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006372 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006373 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006374 ASSERT_VK_SUCCESS(err);
6375
6376 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006377 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006378 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006379 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006380 alloc_info.descriptorPool = ds_pool;
6381 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006382 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006383 ASSERT_VK_SUCCESS(err);
6384
Tony Barboureb254902015-07-15 12:50:33 -06006385 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006386 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6387 pipeline_layout_ci.pNext = NULL;
6388 pipeline_layout_ci.setLayoutCount = 1;
6389 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006390
6391 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006392 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006393 ASSERT_VK_SUCCESS(err);
6394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006396 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006397 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006398 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006399
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006400 VkPipelineObj pipe(m_device);
6401 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006402 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006403 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006404 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006405
Tony Barbour552f6c02016-12-21 14:34:07 -07006406 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006407 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6408 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6409 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006410
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006411 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006412
Chia-I Wuf7458c52015-10-26 21:10:41 +08006413 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6414 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6415 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006416}
6417
Karl Schultz6addd812016-02-02 17:17:23 -07006418TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006419 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006420 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006421
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006423
6424 ASSERT_NO_FATAL_FAILURE(InitState());
6425 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006426 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6427 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006428
6429 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006430 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6431 ds_pool_ci.pNext = NULL;
6432 ds_pool_ci.maxSets = 1;
6433 ds_pool_ci.poolSizeCount = 1;
6434 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006435
6436 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006437 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006438 ASSERT_VK_SUCCESS(err);
6439
6440 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006441 dsl_binding.binding = 0;
6442 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6443 dsl_binding.descriptorCount = 1;
6444 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6445 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006446
6447 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006448 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6449 ds_layout_ci.pNext = NULL;
6450 ds_layout_ci.bindingCount = 1;
6451 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006452 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006454 ASSERT_VK_SUCCESS(err);
6455
6456 VkDescriptorSet descriptorSet;
6457 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006458 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006459 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006460 alloc_info.descriptorPool = ds_pool;
6461 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006463 ASSERT_VK_SUCCESS(err);
6464
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006465 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006466 VkWriteDescriptorSet descriptor_write;
6467 memset(&descriptor_write, 0, sizeof(descriptor_write));
6468 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6469 descriptor_write.dstSet = descriptorSet;
6470 descriptor_write.dstBinding = 0;
6471 descriptor_write.descriptorCount = 1;
6472 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6473 descriptor_write.pTexelBufferView = &view;
6474
6475 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6476
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006477 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006478
6479 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6480 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6481}
6482
Mark Youngd339ba32016-05-30 13:28:35 -06006483TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006484 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 -06006485
6486 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006488 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006489
6490 ASSERT_NO_FATAL_FAILURE(InitState());
6491
6492 // Create a buffer with no bound memory and then attempt to create
6493 // a buffer view.
6494 VkBufferCreateInfo buff_ci = {};
6495 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006496 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006497 buff_ci.size = 256;
6498 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6499 VkBuffer buffer;
6500 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6501 ASSERT_VK_SUCCESS(err);
6502
6503 VkBufferViewCreateInfo buff_view_ci = {};
6504 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6505 buff_view_ci.buffer = buffer;
6506 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6507 buff_view_ci.range = VK_WHOLE_SIZE;
6508 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006509 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006510
6511 m_errorMonitor->VerifyFound();
6512 vkDestroyBuffer(m_device->device(), buffer, NULL);
6513 // If last error is success, it still created the view, so delete it.
6514 if (err == VK_SUCCESS) {
6515 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6516 }
6517}
6518
Karl Schultz6addd812016-02-02 17:17:23 -07006519TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6520 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6521 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006522 // 1. No dynamicOffset supplied
6523 // 2. Too many dynamicOffsets supplied
6524 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006525 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6527 " requires 1 dynamicOffsets, but only "
6528 "0 dynamicOffsets are left in "
6529 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006530
6531 ASSERT_NO_FATAL_FAILURE(InitState());
6532 ASSERT_NO_FATAL_FAILURE(InitViewport());
6533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6534
6535 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006536 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6537 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006538
6539 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006540 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6541 ds_pool_ci.pNext = NULL;
6542 ds_pool_ci.maxSets = 1;
6543 ds_pool_ci.poolSizeCount = 1;
6544 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006545
6546 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006547 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006548 ASSERT_VK_SUCCESS(err);
6549
6550 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006551 dsl_binding.binding = 0;
6552 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6553 dsl_binding.descriptorCount = 1;
6554 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6555 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006556
6557 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006558 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6559 ds_layout_ci.pNext = NULL;
6560 ds_layout_ci.bindingCount = 1;
6561 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006562 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006563 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006564 ASSERT_VK_SUCCESS(err);
6565
6566 VkDescriptorSet descriptorSet;
6567 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006568 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006569 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006570 alloc_info.descriptorPool = ds_pool;
6571 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006572 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006573 ASSERT_VK_SUCCESS(err);
6574
6575 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006576 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6577 pipeline_layout_ci.pNext = NULL;
6578 pipeline_layout_ci.setLayoutCount = 1;
6579 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006580
6581 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006582 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006583 ASSERT_VK_SUCCESS(err);
6584
6585 // Create a buffer to update the descriptor with
6586 uint32_t qfi = 0;
6587 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006588 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6589 buffCI.size = 1024;
6590 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6591 buffCI.queueFamilyIndexCount = 1;
6592 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006593
6594 VkBuffer dyub;
6595 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6596 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006597 // Allocate memory and bind to buffer so we can make it to the appropriate
6598 // error
6599 VkMemoryAllocateInfo mem_alloc = {};
6600 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6601 mem_alloc.pNext = NULL;
6602 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006603 mem_alloc.memoryTypeIndex = 0;
6604
6605 VkMemoryRequirements memReqs;
6606 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006607 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006608 if (!pass) {
6609 vkDestroyBuffer(m_device->device(), dyub, NULL);
6610 return;
6611 }
6612
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006613 VkDeviceMemory mem;
6614 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6615 ASSERT_VK_SUCCESS(err);
6616 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6617 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006618 // Correctly update descriptor to avoid "NOT_UPDATED" error
6619 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006620 buffInfo.buffer = dyub;
6621 buffInfo.offset = 0;
6622 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006623
6624 VkWriteDescriptorSet descriptor_write;
6625 memset(&descriptor_write, 0, sizeof(descriptor_write));
6626 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6627 descriptor_write.dstSet = descriptorSet;
6628 descriptor_write.dstBinding = 0;
6629 descriptor_write.descriptorCount = 1;
6630 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6631 descriptor_write.pBufferInfo = &buffInfo;
6632
6633 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6634
Tony Barbour552f6c02016-12-21 14:34:07 -07006635 m_commandBuffer->BeginCommandBuffer();
6636 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006637 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6638 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006639 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006640 uint32_t pDynOff[2] = {512, 756};
6641 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6643 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6644 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6645 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006646 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006647 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6649 " dynamic offset 512 combined with "
6650 "offset 0 and range 1024 that "
6651 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006652 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006653 char const *vsSource =
6654 "#version 450\n"
6655 "\n"
6656 "out gl_PerVertex { \n"
6657 " vec4 gl_Position;\n"
6658 "};\n"
6659 "void main(){\n"
6660 " gl_Position = vec4(1);\n"
6661 "}\n";
6662 char const *fsSource =
6663 "#version 450\n"
6664 "\n"
6665 "layout(location=0) out vec4 x;\n"
6666 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6667 "void main(){\n"
6668 " x = vec4(bar.y);\n"
6669 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006670 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6671 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6672 VkPipelineObj pipe(m_device);
6673 pipe.AddShader(&vs);
6674 pipe.AddShader(&fs);
6675 pipe.AddColorAttachment();
6676 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6677
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006678 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6679 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6680 VkRect2D scissor = {{0, 0}, {16, 16}};
6681 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6682
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006683 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006684 // This update should succeed, but offset size of 512 will overstep buffer
6685 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006686 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6687 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006688 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006689 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006690
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006691 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006692 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006693
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006694 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006695 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006696 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6697}
6698
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006699TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006700 TEST_DESCRIPTION(
6701 "Attempt to update a descriptor with a non-sparse buffer "
6702 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006703 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006704 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006705 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6707 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006708
6709 ASSERT_NO_FATAL_FAILURE(InitState());
6710 ASSERT_NO_FATAL_FAILURE(InitViewport());
6711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6712
6713 VkDescriptorPoolSize ds_type_count = {};
6714 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6715 ds_type_count.descriptorCount = 1;
6716
6717 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6718 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6719 ds_pool_ci.pNext = NULL;
6720 ds_pool_ci.maxSets = 1;
6721 ds_pool_ci.poolSizeCount = 1;
6722 ds_pool_ci.pPoolSizes = &ds_type_count;
6723
6724 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006725 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006726 ASSERT_VK_SUCCESS(err);
6727
6728 VkDescriptorSetLayoutBinding dsl_binding = {};
6729 dsl_binding.binding = 0;
6730 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6731 dsl_binding.descriptorCount = 1;
6732 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6733 dsl_binding.pImmutableSamplers = NULL;
6734
6735 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6736 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6737 ds_layout_ci.pNext = NULL;
6738 ds_layout_ci.bindingCount = 1;
6739 ds_layout_ci.pBindings = &dsl_binding;
6740 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006741 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006742 ASSERT_VK_SUCCESS(err);
6743
6744 VkDescriptorSet descriptorSet;
6745 VkDescriptorSetAllocateInfo alloc_info = {};
6746 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6747 alloc_info.descriptorSetCount = 1;
6748 alloc_info.descriptorPool = ds_pool;
6749 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006750 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006751 ASSERT_VK_SUCCESS(err);
6752
6753 // Create a buffer to update the descriptor with
6754 uint32_t qfi = 0;
6755 VkBufferCreateInfo buffCI = {};
6756 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6757 buffCI.size = 1024;
6758 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6759 buffCI.queueFamilyIndexCount = 1;
6760 buffCI.pQueueFamilyIndices = &qfi;
6761
6762 VkBuffer dyub;
6763 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6764 ASSERT_VK_SUCCESS(err);
6765
6766 // Attempt to update descriptor without binding memory to it
6767 VkDescriptorBufferInfo buffInfo = {};
6768 buffInfo.buffer = dyub;
6769 buffInfo.offset = 0;
6770 buffInfo.range = 1024;
6771
6772 VkWriteDescriptorSet descriptor_write;
6773 memset(&descriptor_write, 0, sizeof(descriptor_write));
6774 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6775 descriptor_write.dstSet = descriptorSet;
6776 descriptor_write.dstBinding = 0;
6777 descriptor_write.descriptorCount = 1;
6778 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6779 descriptor_write.pBufferInfo = &buffInfo;
6780
6781 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6782 m_errorMonitor->VerifyFound();
6783
6784 vkDestroyBuffer(m_device->device(), dyub, NULL);
6785 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6786 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6787}
6788
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006789TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006790 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006791 ASSERT_NO_FATAL_FAILURE(InitState());
6792 ASSERT_NO_FATAL_FAILURE(InitViewport());
6793 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6794
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006795 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006796 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006797 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6798 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6799 pipeline_layout_ci.pushConstantRangeCount = 1;
6800 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6801
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006802 //
6803 // Check for invalid push constant ranges in pipeline layouts.
6804 //
6805 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006806 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006807 char const *msg;
6808 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006809
Karl Schultzc81037d2016-05-12 08:11:23 -06006810 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6811 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6812 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6813 "vkCreatePipelineLayout() call has push constants index 0 with "
6814 "size 0."},
6815 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6816 "vkCreatePipelineLayout() call has push constants index 0 with "
6817 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006818 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006819 "vkCreatePipelineLayout() call has push constants index 0 with "
6820 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006821 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006822 "vkCreatePipelineLayout() call has push constants index 0 with "
6823 "size 0."},
6824 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6825 "vkCreatePipelineLayout() call has push constants index 0 with "
6826 "offset 1. Offset must"},
6827 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6828 "vkCreatePipelineLayout() call has push constants index 0 "
6829 "with offset "},
6830 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6831 "vkCreatePipelineLayout() call has push constants "
6832 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006833 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006834 "vkCreatePipelineLayout() call has push constants index 0 "
6835 "with offset "},
6836 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6837 "vkCreatePipelineLayout() call has push "
6838 "constants index 0 with offset "},
6839 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6840 "vkCreatePipelineLayout() call has push "
6841 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006842 }};
6843
6844 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006845 for (const auto &iter : range_tests) {
6846 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6848 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006849 m_errorMonitor->VerifyFound();
6850 if (VK_SUCCESS == err) {
6851 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6852 }
6853 }
6854
6855 // Check for invalid stage flag
6856 pc_range.offset = 0;
6857 pc_range.size = 16;
6858 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006859 m_errorMonitor->SetDesiredFailureMsg(
6860 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6861 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006862 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006863 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006864 if (VK_SUCCESS == err) {
6865 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6866 }
6867
6868 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006869 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006870 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006871 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006872 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006873 };
6874
Karl Schultzc81037d2016-05-12 08:11:23 -06006875 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006876 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6877 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6878 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6879 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6880 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006881 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6882 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6883 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6884 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6885 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6886 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6887 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6888 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6889 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6890 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006891 {
6892 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6893 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6894 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6895 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6896 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006897 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006898 },
6899 {
6900 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6901 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6902 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6903 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6904 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006905 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006906 },
6907 {
6908 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6909 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6910 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6911 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6912 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006913 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006914 },
6915 {
6916 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6917 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6918 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6919 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6920 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006921 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6922 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6923 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6924 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006925 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006926
Karl Schultzc81037d2016-05-12 08:11:23 -06006927 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006928 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006929 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006930 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006931 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006932 m_errorMonitor->VerifyFound();
6933 if (VK_SUCCESS == err) {
6934 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6935 }
6936 }
6937
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006938 //
6939 // CmdPushConstants tests
6940 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006941 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006942
6943 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006944 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6945 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006946 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006947 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6948 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006949 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006950 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6951 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006952 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006953 "vkCmdPushConstants() call has push constants with offset 1. "
6954 "Offset must be a multiple of 4."},
6955 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6956 "vkCmdPushConstants() call has push constants with offset 1. "
6957 "Offset must be a multiple of 4."},
6958 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6959 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6960 "0x1 not within flag-matching ranges in pipeline layout"},
6961 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6962 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6963 "0x1 not within flag-matching ranges in pipeline layout"},
6964 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6965 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6966 "0x1 not within flag-matching ranges in pipeline layout"},
6967 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6968 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6969 "0x1 not within flag-matching ranges in pipeline layout"},
6970 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6971 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6972 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006973 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006974 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6975 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006976 }};
6977
Tony Barbour552f6c02016-12-21 14:34:07 -07006978 m_commandBuffer->BeginCommandBuffer();
6979 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006980
6981 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006982 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006983 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006984 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006985 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006986 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006987 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006988 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06006989 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006990 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6991 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06006992 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006993 m_errorMonitor->VerifyFound();
6994 }
6995
6996 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006998 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006999 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06007000 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007001
Karl Schultzc81037d2016-05-12 08:11:23 -06007002 // overlapping range tests with cmd
7003 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
7004 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
7005 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
7006 "0x1 not within flag-matching ranges in pipeline layout"},
7007 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
7008 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
7009 "0x1 not within flag-matching ranges in pipeline layout"},
7010 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
7011 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
7012 "0x1 not within flag-matching ranges in pipeline layout"},
7013 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007014 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007015 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007016 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7017 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007018 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007019 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007020 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007021 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007022 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007023 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7025 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007026 iter.range.size, dummy_values);
7027 m_errorMonitor->VerifyFound();
7028 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007029 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7030
Tony Barbour552f6c02016-12-21 14:34:07 -07007031 m_commandBuffer->EndRenderPass();
7032 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007033}
7034
Karl Schultz6addd812016-02-02 17:17:23 -07007035TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007036 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007037 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007038
7039 ASSERT_NO_FATAL_FAILURE(InitState());
7040 ASSERT_NO_FATAL_FAILURE(InitViewport());
7041 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7042
7043 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7044 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007045 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7046 ds_type_count[0].descriptorCount = 10;
7047 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7048 ds_type_count[1].descriptorCount = 2;
7049 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7050 ds_type_count[2].descriptorCount = 2;
7051 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7052 ds_type_count[3].descriptorCount = 5;
7053 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7054 // type
7055 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7056 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7057 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007058
7059 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007060 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7061 ds_pool_ci.pNext = NULL;
7062 ds_pool_ci.maxSets = 5;
7063 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7064 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007065
7066 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007067 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007068 ASSERT_VK_SUCCESS(err);
7069
7070 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7071 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007072 dsl_binding[0].binding = 0;
7073 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7074 dsl_binding[0].descriptorCount = 5;
7075 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7076 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007077
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007078 // Create layout identical to set0 layout but w/ different stageFlags
7079 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007080 dsl_fs_stage_only.binding = 0;
7081 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7082 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007083 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7084 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007085 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007086 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007087 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7088 ds_layout_ci.pNext = NULL;
7089 ds_layout_ci.bindingCount = 1;
7090 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007091 static const uint32_t NUM_LAYOUTS = 4;
7092 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007093 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007094 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7095 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007096 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007097 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007098 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007099 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007100 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007101 dsl_binding[0].binding = 0;
7102 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007103 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007104 dsl_binding[1].binding = 1;
7105 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7106 dsl_binding[1].descriptorCount = 2;
7107 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7108 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007109 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007111 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007112 ASSERT_VK_SUCCESS(err);
7113 dsl_binding[0].binding = 0;
7114 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007115 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007116 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007117 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007118 ASSERT_VK_SUCCESS(err);
7119 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007120 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007121 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007122 ASSERT_VK_SUCCESS(err);
7123
7124 static const uint32_t NUM_SETS = 4;
7125 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7126 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007127 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007128 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007129 alloc_info.descriptorPool = ds_pool;
7130 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007131 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007132 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007133 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007134 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007135 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007136 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007137 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007138
7139 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007140 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7141 pipeline_layout_ci.pNext = NULL;
7142 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7143 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007144
7145 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007146 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007147 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007148 // Create pipelineLayout with only one setLayout
7149 pipeline_layout_ci.setLayoutCount = 1;
7150 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007151 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007152 ASSERT_VK_SUCCESS(err);
7153 // Create pipelineLayout with 2 descriptor setLayout at index 0
7154 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7155 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007156 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007157 ASSERT_VK_SUCCESS(err);
7158 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7159 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7160 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007161 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007162 ASSERT_VK_SUCCESS(err);
7163 // Create pipelineLayout with UB type, but stageFlags for FS only
7164 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7165 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007166 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007167 ASSERT_VK_SUCCESS(err);
7168 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7169 VkDescriptorSetLayout pl_bad_s0[2] = {};
7170 pl_bad_s0[0] = ds_layout_fs_only;
7171 pl_bad_s0[1] = ds_layout[1];
7172 pipeline_layout_ci.setLayoutCount = 2;
7173 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7174 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007176 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007177
Tobin Ehlis88452832015-12-03 09:40:56 -07007178 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007179 char const *vsSource =
7180 "#version 450\n"
7181 "\n"
7182 "out gl_PerVertex {\n"
7183 " vec4 gl_Position;\n"
7184 "};\n"
7185 "void main(){\n"
7186 " gl_Position = vec4(1);\n"
7187 "}\n";
7188 char const *fsSource =
7189 "#version 450\n"
7190 "\n"
7191 "layout(location=0) out vec4 x;\n"
7192 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7193 "void main(){\n"
7194 " x = vec4(bar.y);\n"
7195 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007196 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7197 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007198 VkPipelineObj pipe(m_device);
7199 pipe.AddShader(&vs);
7200 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007201 pipe.AddColorAttachment();
7202 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007203
Tony Barbour552f6c02016-12-21 14:34:07 -07007204 m_commandBuffer->BeginCommandBuffer();
7205 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007206
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007207 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007208 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7209 // of PSO
7210 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7211 // cmd_pipeline.c
7212 // due to the fact that cmd_alloc_dset_data() has not been called in
7213 // cmd_bind_graphics_pipeline()
7214 // TODO : Want to cause various binding incompatibility issues here to test
7215 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007216 // First cause various verify_layout_compatibility() fails
7217 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007218 // verify_set_layout_compatibility fail cases:
7219 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007221 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7222 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007223 m_errorMonitor->VerifyFound();
7224
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007225 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007226 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7227 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7228 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007229 m_errorMonitor->VerifyFound();
7230
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007231 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007232 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7233 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7235 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7236 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007237 m_errorMonitor->VerifyFound();
7238
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007239 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7240 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7242 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7243 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007244 m_errorMonitor->VerifyFound();
7245
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007246 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7247 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007248 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7249 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7250 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7251 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007252 m_errorMonitor->VerifyFound();
7253
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007254 // Cause INFO messages due to disturbing previously bound Sets
7255 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007256 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7257 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007258 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7260 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7261 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007262 m_errorMonitor->VerifyFound();
7263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007264 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7265 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007266 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7268 " newly bound as set #0 so set #1 and "
7269 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007270 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7271 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007272 m_errorMonitor->VerifyFound();
7273
Tobin Ehlis10fad692016-07-07 12:00:36 -06007274 // Now that we're done actively using the pipelineLayout that gfx pipeline
7275 // was created with, we should be able to delete it. Do that now to verify
7276 // that validation obeys pipelineLayout lifetime
7277 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7278
Tobin Ehlis88452832015-12-03 09:40:56 -07007279 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007280 // 1. Error due to not binding required set (we actually use same code as
7281 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007282 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7283 &descriptorSet[0], 0, NULL);
7284 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7285 &descriptorSet[1], 0, NULL);
7286 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 -07007287
7288 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7289 VkRect2D scissor = {{0, 0}, {16, 16}};
7290 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7291 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7292
Tobin Ehlis88452832015-12-03 09:40:56 -07007293 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007294 m_errorMonitor->VerifyFound();
7295
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007296 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007297 // 2. Error due to bound set not being compatible with PSO's
7298 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007299 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7300 &descriptorSet[0], 0, NULL);
7301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007302 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007303 m_errorMonitor->VerifyFound();
7304
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007305 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007306 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007307 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7308 }
7309 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007310 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7311 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7312}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007313
Karl Schultz6addd812016-02-02 17:17:23 -07007314TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7316 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007317
7318 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007319 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007320 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007321 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007322
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007323 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007324}
7325
Karl Schultz6addd812016-02-02 17:17:23 -07007326TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7327 VkResult err;
7328 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007329
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007331
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007332 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007333
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007334 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007335 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007336 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007337 cmd.commandPool = m_commandPool;
7338 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007339 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007340
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007341 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007342 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007343
7344 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007345 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007346 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7347
7348 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007349 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007350 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007351 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 -07007352 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007353
7354 // The error should be caught by validation of the BeginCommandBuffer call
7355 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7356
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007357 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007358 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007359}
7360
Karl Schultz6addd812016-02-02 17:17:23 -07007361TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007362 // Cause error due to Begin while recording CB
7363 // Then cause 2 errors for attempting to reset CB w/o having
7364 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7365 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007367
7368 ASSERT_NO_FATAL_FAILURE(InitState());
7369
7370 // Calls AllocateCommandBuffers
7371 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7372
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007373 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007374 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007375 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7376 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007377 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7378 cmd_buf_info.pNext = NULL;
7379 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007380 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007381
7382 // Begin CB to transition to recording state
7383 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7384 // Can't re-begin. This should trigger error
7385 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007386 m_errorMonitor->VerifyFound();
7387
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007389 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007390 // Reset attempt will trigger error due to incorrect CommandPool state
7391 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007392 m_errorMonitor->VerifyFound();
7393
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007395 // Transition CB to RECORDED state
7396 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7397 // Now attempting to Begin will implicitly reset, which triggers error
7398 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007399 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007400}
7401
Karl Schultz6addd812016-02-02 17:17:23 -07007402TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007403 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007404 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007405
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7407 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007408
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007409 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007410 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007411
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007412 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007413 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7414 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007415
7416 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007417 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7418 ds_pool_ci.pNext = NULL;
7419 ds_pool_ci.maxSets = 1;
7420 ds_pool_ci.poolSizeCount = 1;
7421 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007422
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007423 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007424 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007425 ASSERT_VK_SUCCESS(err);
7426
Tony Barboureb254902015-07-15 12:50:33 -06007427 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007428 dsl_binding.binding = 0;
7429 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7430 dsl_binding.descriptorCount = 1;
7431 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7432 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007433
Tony Barboureb254902015-07-15 12:50:33 -06007434 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007435 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7436 ds_layout_ci.pNext = NULL;
7437 ds_layout_ci.bindingCount = 1;
7438 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007439
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007440 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007441 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007442 ASSERT_VK_SUCCESS(err);
7443
7444 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007445 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007446 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007447 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007448 alloc_info.descriptorPool = ds_pool;
7449 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007451 ASSERT_VK_SUCCESS(err);
7452
Tony Barboureb254902015-07-15 12:50:33 -06007453 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007454 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7455 pipeline_layout_ci.setLayoutCount = 1;
7456 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007457
7458 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007460 ASSERT_VK_SUCCESS(err);
7461
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007462 VkViewport vp = {}; // Just need dummy vp to point to
7463 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007464
7465 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007466 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7467 vp_state_ci.scissorCount = 1;
7468 vp_state_ci.pScissors = &sc;
7469 vp_state_ci.viewportCount = 1;
7470 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007471
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007472 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7473 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7474 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7475 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7476 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7477 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007478 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007479 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007480 rs_state_ci.lineWidth = 1.0f;
7481
7482 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7483 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7484 vi_ci.pNext = nullptr;
7485 vi_ci.vertexBindingDescriptionCount = 0;
7486 vi_ci.pVertexBindingDescriptions = nullptr;
7487 vi_ci.vertexAttributeDescriptionCount = 0;
7488 vi_ci.pVertexAttributeDescriptions = nullptr;
7489
7490 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7491 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7492 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7493
7494 VkPipelineShaderStageCreateInfo shaderStages[2];
7495 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7496
7497 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7498 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007499 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007500 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007501
Tony Barboureb254902015-07-15 12:50:33 -06007502 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007503 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7504 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007505 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007506 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7507 gp_ci.layout = pipeline_layout;
7508 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007509 gp_ci.pVertexInputState = &vi_ci;
7510 gp_ci.pInputAssemblyState = &ia_ci;
7511
7512 gp_ci.stageCount = 1;
7513 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007514
7515 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007516 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7517 pc_ci.initialDataSize = 0;
7518 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007519
7520 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007521 VkPipelineCache pipelineCache;
7522
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007523 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007524 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007525 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007526 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007527
Chia-I Wuf7458c52015-10-26 21:10:41 +08007528 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7529 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7530 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007532}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007533
Tobin Ehlis912df022015-09-17 08:46:18 -06007534/*// TODO : This test should be good, but needs Tess support in compiler to run
7535TEST_F(VkLayerTest, InvalidPatchControlPoints)
7536{
7537 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007538 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007539
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007541 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7542primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007543
Tobin Ehlis912df022015-09-17 08:46:18 -06007544 ASSERT_NO_FATAL_FAILURE(InitState());
7545 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007546
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007547 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007548 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007549 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007550
7551 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7552 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7553 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007554 ds_pool_ci.poolSizeCount = 1;
7555 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007556
7557 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007558 err = vkCreateDescriptorPool(m_device->device(),
7559VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007560 ASSERT_VK_SUCCESS(err);
7561
7562 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007563 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007564 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007565 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007566 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7567 dsl_binding.pImmutableSamplers = NULL;
7568
7569 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007570 ds_layout_ci.sType =
7571VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007572 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007573 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007574 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007575
7576 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007577 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7578&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007579 ASSERT_VK_SUCCESS(err);
7580
7581 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007582 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7583VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007584 ASSERT_VK_SUCCESS(err);
7585
7586 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007587 pipeline_layout_ci.sType =
7588VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007589 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007590 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007591 pipeline_layout_ci.pSetLayouts = &ds_layout;
7592
7593 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007594 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7595&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007596 ASSERT_VK_SUCCESS(err);
7597
7598 VkPipelineShaderStageCreateInfo shaderStages[3];
7599 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7600
Karl Schultz6addd812016-02-02 17:17:23 -07007601 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7602this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007603 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007604 VkShaderObj
7605tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7606this);
7607 VkShaderObj
7608te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7609this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007610
Karl Schultz6addd812016-02-02 17:17:23 -07007611 shaderStages[0].sType =
7612VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007613 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007614 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007615 shaderStages[1].sType =
7616VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007617 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007618 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007619 shaderStages[2].sType =
7620VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007621 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007622 shaderStages[2].shader = te.handle();
7623
7624 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007625 iaCI.sType =
7626VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007627 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007628
7629 VkPipelineTessellationStateCreateInfo tsCI = {};
7630 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7631 tsCI.patchControlPoints = 0; // This will cause an error
7632
7633 VkGraphicsPipelineCreateInfo gp_ci = {};
7634 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7635 gp_ci.pNext = NULL;
7636 gp_ci.stageCount = 3;
7637 gp_ci.pStages = shaderStages;
7638 gp_ci.pVertexInputState = NULL;
7639 gp_ci.pInputAssemblyState = &iaCI;
7640 gp_ci.pTessellationState = &tsCI;
7641 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007642 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007643 gp_ci.pMultisampleState = NULL;
7644 gp_ci.pDepthStencilState = NULL;
7645 gp_ci.pColorBlendState = NULL;
7646 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7647 gp_ci.layout = pipeline_layout;
7648 gp_ci.renderPass = renderPass();
7649
7650 VkPipelineCacheCreateInfo pc_ci = {};
7651 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7652 pc_ci.pNext = NULL;
7653 pc_ci.initialSize = 0;
7654 pc_ci.initialData = 0;
7655 pc_ci.maxSize = 0;
7656
7657 VkPipeline pipeline;
7658 VkPipelineCache pipelineCache;
7659
Karl Schultz6addd812016-02-02 17:17:23 -07007660 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7661&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007662 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007663 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7664&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007665
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007666 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007667
Chia-I Wuf7458c52015-10-26 21:10:41 +08007668 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7669 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7670 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7671 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007672}
7673*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007674
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007675TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007676 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007677
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007678 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007679
Tobin Ehlise68360f2015-10-01 11:15:13 -06007680 ASSERT_NO_FATAL_FAILURE(InitState());
7681 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007682
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007683 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007684 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7685 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007686
7687 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007688 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7689 ds_pool_ci.maxSets = 1;
7690 ds_pool_ci.poolSizeCount = 1;
7691 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007692
7693 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007694 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007695 ASSERT_VK_SUCCESS(err);
7696
7697 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007698 dsl_binding.binding = 0;
7699 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7700 dsl_binding.descriptorCount = 1;
7701 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007702
7703 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007704 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7705 ds_layout_ci.bindingCount = 1;
7706 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007707
7708 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007709 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007710 ASSERT_VK_SUCCESS(err);
7711
7712 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007713 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007714 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007715 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007716 alloc_info.descriptorPool = ds_pool;
7717 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007719 ASSERT_VK_SUCCESS(err);
7720
7721 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007722 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7723 pipeline_layout_ci.setLayoutCount = 1;
7724 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007725
7726 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007727 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007728 ASSERT_VK_SUCCESS(err);
7729
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007730 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007731 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007732 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007733 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007734 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007735 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007736
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007737 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7738 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7739 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7740 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7741 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7742 rs_state_ci.depthClampEnable = VK_FALSE;
7743 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7744 rs_state_ci.depthBiasEnable = VK_FALSE;
7745
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007746 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7747 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7748 vi_ci.pNext = nullptr;
7749 vi_ci.vertexBindingDescriptionCount = 0;
7750 vi_ci.pVertexBindingDescriptions = nullptr;
7751 vi_ci.vertexAttributeDescriptionCount = 0;
7752 vi_ci.pVertexAttributeDescriptions = nullptr;
7753
7754 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7755 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7756 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7757
7758 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7759 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7760 pipe_ms_state_ci.pNext = NULL;
7761 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7762 pipe_ms_state_ci.sampleShadingEnable = 0;
7763 pipe_ms_state_ci.minSampleShading = 1.0;
7764 pipe_ms_state_ci.pSampleMask = NULL;
7765
Cody Northropeb3a6c12015-10-05 14:44:45 -06007766 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007767 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007768
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007769 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007770 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007771 shaderStages[0] = vs.GetStageCreateInfo();
7772 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007773
7774 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007775 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7776 gp_ci.stageCount = 2;
7777 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007778 gp_ci.pVertexInputState = &vi_ci;
7779 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007780 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007781 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007782 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007783 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7784 gp_ci.layout = pipeline_layout;
7785 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007786
7787 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007788 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007789
7790 VkPipeline pipeline;
7791 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007792 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007793 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007794
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007795 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007796 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007797
7798 // Check case where multiViewport is disabled and viewport count is not 1
7799 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7801 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7802 vp_state_ci.scissorCount = 0;
7803 vp_state_ci.viewportCount = 0;
7804 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7805 m_errorMonitor->VerifyFound();
7806 } else {
7807 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007808 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007809 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007810 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007811
7812 // Check is that viewportcount and scissorcount match
7813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7814 vp_state_ci.scissorCount = 1;
7815 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7816 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7817 m_errorMonitor->VerifyFound();
7818
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007819 // Check case where multiViewport is enabled and viewport count is greater than max
7820 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7823 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7824 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7825 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7826 m_errorMonitor->VerifyFound();
7827 }
7828 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007829
Chia-I Wuf7458c52015-10-26 21:10:41 +08007830 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7831 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7832 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7833 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007834}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007835
7836// 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
7837// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007838TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007839 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007840
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007841 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7842
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007844
Tobin Ehlise68360f2015-10-01 11:15:13 -06007845 ASSERT_NO_FATAL_FAILURE(InitState());
7846 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007847
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007848 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007849 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7850 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007851
7852 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007853 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7854 ds_pool_ci.maxSets = 1;
7855 ds_pool_ci.poolSizeCount = 1;
7856 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007857
7858 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007859 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007860 ASSERT_VK_SUCCESS(err);
7861
7862 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007863 dsl_binding.binding = 0;
7864 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7865 dsl_binding.descriptorCount = 1;
7866 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007867
7868 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007869 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7870 ds_layout_ci.bindingCount = 1;
7871 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007872
7873 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007874 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007875 ASSERT_VK_SUCCESS(err);
7876
7877 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007878 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007879 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007880 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007881 alloc_info.descriptorPool = ds_pool;
7882 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007883 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007884 ASSERT_VK_SUCCESS(err);
7885
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007886 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7887 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7888 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7889
7890 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7891 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7892 vi_ci.pNext = nullptr;
7893 vi_ci.vertexBindingDescriptionCount = 0;
7894 vi_ci.pVertexBindingDescriptions = nullptr;
7895 vi_ci.vertexAttributeDescriptionCount = 0;
7896 vi_ci.pVertexAttributeDescriptions = nullptr;
7897
7898 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7899 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7900 pipe_ms_state_ci.pNext = NULL;
7901 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7902 pipe_ms_state_ci.sampleShadingEnable = 0;
7903 pipe_ms_state_ci.minSampleShading = 1.0;
7904 pipe_ms_state_ci.pSampleMask = NULL;
7905
Tobin Ehlise68360f2015-10-01 11:15:13 -06007906 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007907 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7908 pipeline_layout_ci.setLayoutCount = 1;
7909 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007910
7911 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007912 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007913 ASSERT_VK_SUCCESS(err);
7914
7915 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7916 // Set scissor as dynamic to avoid second error
7917 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007918 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7919 dyn_state_ci.dynamicStateCount = 1;
7920 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007921
Cody Northropeb3a6c12015-10-05 14:44:45 -06007922 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007923 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007924
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007925 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007926 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7927 // 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 +08007928 shaderStages[0] = vs.GetStageCreateInfo();
7929 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007930
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007931 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7932 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7933 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7934 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7935 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7936 rs_state_ci.depthClampEnable = VK_FALSE;
7937 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7938 rs_state_ci.depthBiasEnable = VK_FALSE;
7939
Tobin Ehlise68360f2015-10-01 11:15:13 -06007940 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007941 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7942 gp_ci.stageCount = 2;
7943 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007944 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007945 // Not setting VP state w/o dynamic vp state should cause validation error
7946 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007947 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007948 gp_ci.pVertexInputState = &vi_ci;
7949 gp_ci.pInputAssemblyState = &ia_ci;
7950 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007951 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7952 gp_ci.layout = pipeline_layout;
7953 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007954
7955 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007956 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007957
7958 VkPipeline pipeline;
7959 VkPipelineCache pipelineCache;
7960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007961 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007962 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007963 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007964
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007965 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
Chia-I Wuf7458c52015-10-26 21:10:41 +08007967 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7968 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7969 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7970 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007972
7973// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7974// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007975TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7976 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007977
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007979
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007981
7982 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007983 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007984 return;
7985 }
7986
Tobin Ehlise68360f2015-10-01 11:15:13 -06007987 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007988
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007989 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007990 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7991 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007992
7993 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007994 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7995 ds_pool_ci.maxSets = 1;
7996 ds_pool_ci.poolSizeCount = 1;
7997 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007998
7999 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008000 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001 ASSERT_VK_SUCCESS(err);
8002
8003 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008004 dsl_binding.binding = 0;
8005 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8006 dsl_binding.descriptorCount = 1;
8007 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008008
8009 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008010 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8011 ds_layout_ci.bindingCount = 1;
8012 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008013
8014 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008015 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008016 ASSERT_VK_SUCCESS(err);
8017
8018 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008019 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008021 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008022 alloc_info.descriptorPool = ds_pool;
8023 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025 ASSERT_VK_SUCCESS(err);
8026
8027 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008028 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8029 pipeline_layout_ci.setLayoutCount = 1;
8030 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008031
8032 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008033 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008034 ASSERT_VK_SUCCESS(err);
8035
8036 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008037 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8038 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008039 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008040 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008041 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008042
8043 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8044 // Set scissor as dynamic to avoid that error
8045 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008046 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8047 dyn_state_ci.dynamicStateCount = 1;
8048 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008049
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008050 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8051 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8052 pipe_ms_state_ci.pNext = NULL;
8053 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8054 pipe_ms_state_ci.sampleShadingEnable = 0;
8055 pipe_ms_state_ci.minSampleShading = 1.0;
8056 pipe_ms_state_ci.pSampleMask = NULL;
8057
Cody Northropeb3a6c12015-10-05 14:44:45 -06008058 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008059 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008060
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008061 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008062 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8063 // 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 +08008064 shaderStages[0] = vs.GetStageCreateInfo();
8065 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008066
Cody Northropf6622dc2015-10-06 10:33:21 -06008067 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8068 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8069 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008070 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008071 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008072 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008073 vi_ci.pVertexAttributeDescriptions = nullptr;
8074
8075 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8076 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8077 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008079 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008080 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008081 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008082 rs_ci.pNext = nullptr;
8083
Mark Youngc89c6312016-03-31 16:03:20 -06008084 VkPipelineColorBlendAttachmentState att = {};
8085 att.blendEnable = VK_FALSE;
8086 att.colorWriteMask = 0xf;
8087
Cody Northropf6622dc2015-10-06 10:33:21 -06008088 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8089 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8090 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008091 cb_ci.attachmentCount = 1;
8092 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008093
Tobin Ehlise68360f2015-10-01 11:15:13 -06008094 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008095 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8096 gp_ci.stageCount = 2;
8097 gp_ci.pStages = shaderStages;
8098 gp_ci.pVertexInputState = &vi_ci;
8099 gp_ci.pInputAssemblyState = &ia_ci;
8100 gp_ci.pViewportState = &vp_state_ci;
8101 gp_ci.pRasterizationState = &rs_ci;
8102 gp_ci.pColorBlendState = &cb_ci;
8103 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008104 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008105 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8106 gp_ci.layout = pipeline_layout;
8107 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008108
8109 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008110 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008111
8112 VkPipeline pipeline;
8113 VkPipelineCache pipelineCache;
8114
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008115 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008116 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008117 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008118
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008119 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008120
Tobin Ehlisd332f282015-10-02 11:00:56 -06008121 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008122 // First need to successfully create the PSO from above by setting
8123 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008124 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 -07008125
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008126 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008127 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008128 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008129 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008130 m_commandBuffer->BeginCommandBuffer();
8131 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008132 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008133 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008134 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008135 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008136 Draw(1, 0, 0, 0);
8137
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008138 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008139
8140 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8141 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8142 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8143 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008144 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008145}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008146
8147// 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 -07008148// viewportCount
8149TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8150 VkResult err;
8151
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008152 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008153
8154 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008155
8156 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008157 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008158 return;
8159 }
8160
Karl Schultz6addd812016-02-02 17:17:23 -07008161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8162
8163 VkDescriptorPoolSize ds_type_count = {};
8164 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8165 ds_type_count.descriptorCount = 1;
8166
8167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8169 ds_pool_ci.maxSets = 1;
8170 ds_pool_ci.poolSizeCount = 1;
8171 ds_pool_ci.pPoolSizes = &ds_type_count;
8172
8173 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008174 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008175 ASSERT_VK_SUCCESS(err);
8176
8177 VkDescriptorSetLayoutBinding dsl_binding = {};
8178 dsl_binding.binding = 0;
8179 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8180 dsl_binding.descriptorCount = 1;
8181 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8182
8183 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8184 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8185 ds_layout_ci.bindingCount = 1;
8186 ds_layout_ci.pBindings = &dsl_binding;
8187
8188 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008189 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008190 ASSERT_VK_SUCCESS(err);
8191
8192 VkDescriptorSet descriptorSet;
8193 VkDescriptorSetAllocateInfo alloc_info = {};
8194 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8195 alloc_info.descriptorSetCount = 1;
8196 alloc_info.descriptorPool = ds_pool;
8197 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008199 ASSERT_VK_SUCCESS(err);
8200
8201 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8202 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8203 pipeline_layout_ci.setLayoutCount = 1;
8204 pipeline_layout_ci.pSetLayouts = &ds_layout;
8205
8206 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008207 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008208 ASSERT_VK_SUCCESS(err);
8209
8210 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8211 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8212 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008213 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008214 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008215 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008216
8217 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8218 // Set scissor as dynamic to avoid that error
8219 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8220 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8221 dyn_state_ci.dynamicStateCount = 1;
8222 dyn_state_ci.pDynamicStates = &vp_state;
8223
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008224 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8225 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8226 pipe_ms_state_ci.pNext = NULL;
8227 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8228 pipe_ms_state_ci.sampleShadingEnable = 0;
8229 pipe_ms_state_ci.minSampleShading = 1.0;
8230 pipe_ms_state_ci.pSampleMask = NULL;
8231
Karl Schultz6addd812016-02-02 17:17:23 -07008232 VkPipelineShaderStageCreateInfo shaderStages[2];
8233 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8234
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008235 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008236 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8237 // 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 -07008238 shaderStages[0] = vs.GetStageCreateInfo();
8239 shaderStages[1] = fs.GetStageCreateInfo();
8240
8241 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8242 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8243 vi_ci.pNext = nullptr;
8244 vi_ci.vertexBindingDescriptionCount = 0;
8245 vi_ci.pVertexBindingDescriptions = nullptr;
8246 vi_ci.vertexAttributeDescriptionCount = 0;
8247 vi_ci.pVertexAttributeDescriptions = nullptr;
8248
8249 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8250 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8251 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8252
8253 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8254 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008255 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008256 rs_ci.pNext = nullptr;
8257
Mark Youngc89c6312016-03-31 16:03:20 -06008258 VkPipelineColorBlendAttachmentState att = {};
8259 att.blendEnable = VK_FALSE;
8260 att.colorWriteMask = 0xf;
8261
Karl Schultz6addd812016-02-02 17:17:23 -07008262 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8263 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8264 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008265 cb_ci.attachmentCount = 1;
8266 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008267
8268 VkGraphicsPipelineCreateInfo gp_ci = {};
8269 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8270 gp_ci.stageCount = 2;
8271 gp_ci.pStages = shaderStages;
8272 gp_ci.pVertexInputState = &vi_ci;
8273 gp_ci.pInputAssemblyState = &ia_ci;
8274 gp_ci.pViewportState = &vp_state_ci;
8275 gp_ci.pRasterizationState = &rs_ci;
8276 gp_ci.pColorBlendState = &cb_ci;
8277 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008278 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008279 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8280 gp_ci.layout = pipeline_layout;
8281 gp_ci.renderPass = renderPass();
8282
8283 VkPipelineCacheCreateInfo pc_ci = {};
8284 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8285
8286 VkPipeline pipeline;
8287 VkPipelineCache pipelineCache;
8288
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008289 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008290 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008291 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008292
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008293 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008294
8295 // Now hit second fail case where we set scissor w/ different count than PSO
8296 // First need to successfully create the PSO from above by setting
8297 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8299 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008300
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008301 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008302 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008303 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008304 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008305 m_commandBuffer->BeginCommandBuffer();
8306 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008307 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008308 VkViewport viewports[1] = {};
8309 viewports[0].width = 8;
8310 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008311 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008312 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008313 Draw(1, 0, 0, 0);
8314
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008315 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008316
Chia-I Wuf7458c52015-10-26 21:10:41 +08008317 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8318 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8319 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008321 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008322}
8323
Mark Young7394fdd2016-03-31 14:56:43 -06008324TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8325 VkResult err;
8326
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008328
8329 ASSERT_NO_FATAL_FAILURE(InitState());
8330 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8331
8332 VkDescriptorPoolSize ds_type_count = {};
8333 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8334 ds_type_count.descriptorCount = 1;
8335
8336 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8337 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8338 ds_pool_ci.maxSets = 1;
8339 ds_pool_ci.poolSizeCount = 1;
8340 ds_pool_ci.pPoolSizes = &ds_type_count;
8341
8342 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008343 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008344 ASSERT_VK_SUCCESS(err);
8345
8346 VkDescriptorSetLayoutBinding dsl_binding = {};
8347 dsl_binding.binding = 0;
8348 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8349 dsl_binding.descriptorCount = 1;
8350 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8351
8352 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8353 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8354 ds_layout_ci.bindingCount = 1;
8355 ds_layout_ci.pBindings = &dsl_binding;
8356
8357 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008358 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008359 ASSERT_VK_SUCCESS(err);
8360
8361 VkDescriptorSet descriptorSet;
8362 VkDescriptorSetAllocateInfo alloc_info = {};
8363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8364 alloc_info.descriptorSetCount = 1;
8365 alloc_info.descriptorPool = ds_pool;
8366 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008368 ASSERT_VK_SUCCESS(err);
8369
8370 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8371 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8372 pipeline_layout_ci.setLayoutCount = 1;
8373 pipeline_layout_ci.pSetLayouts = &ds_layout;
8374
8375 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008376 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008377 ASSERT_VK_SUCCESS(err);
8378
8379 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8380 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8381 vp_state_ci.scissorCount = 1;
8382 vp_state_ci.pScissors = NULL;
8383 vp_state_ci.viewportCount = 1;
8384 vp_state_ci.pViewports = NULL;
8385
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008386 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008387 // Set scissor as dynamic to avoid that error
8388 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8389 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8390 dyn_state_ci.dynamicStateCount = 2;
8391 dyn_state_ci.pDynamicStates = dynamic_states;
8392
8393 VkPipelineShaderStageCreateInfo shaderStages[2];
8394 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8395
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008396 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8397 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008398 this); // TODO - We shouldn't need a fragment shader
8399 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008400 shaderStages[0] = vs.GetStageCreateInfo();
8401 shaderStages[1] = fs.GetStageCreateInfo();
8402
8403 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8404 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8405 vi_ci.pNext = nullptr;
8406 vi_ci.vertexBindingDescriptionCount = 0;
8407 vi_ci.pVertexBindingDescriptions = nullptr;
8408 vi_ci.vertexAttributeDescriptionCount = 0;
8409 vi_ci.pVertexAttributeDescriptions = nullptr;
8410
8411 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8412 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8413 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8414
8415 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8416 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8417 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008418 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008419
Mark Young47107952016-05-02 15:59:55 -06008420 // Check too low (line width of -1.0f).
8421 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008422
8423 VkPipelineColorBlendAttachmentState att = {};
8424 att.blendEnable = VK_FALSE;
8425 att.colorWriteMask = 0xf;
8426
8427 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8428 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8429 cb_ci.pNext = nullptr;
8430 cb_ci.attachmentCount = 1;
8431 cb_ci.pAttachments = &att;
8432
8433 VkGraphicsPipelineCreateInfo gp_ci = {};
8434 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8435 gp_ci.stageCount = 2;
8436 gp_ci.pStages = shaderStages;
8437 gp_ci.pVertexInputState = &vi_ci;
8438 gp_ci.pInputAssemblyState = &ia_ci;
8439 gp_ci.pViewportState = &vp_state_ci;
8440 gp_ci.pRasterizationState = &rs_ci;
8441 gp_ci.pColorBlendState = &cb_ci;
8442 gp_ci.pDynamicState = &dyn_state_ci;
8443 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8444 gp_ci.layout = pipeline_layout;
8445 gp_ci.renderPass = renderPass();
8446
8447 VkPipelineCacheCreateInfo pc_ci = {};
8448 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8449
8450 VkPipeline pipeline;
8451 VkPipelineCache pipelineCache;
8452
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008453 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008454 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008455 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008456
8457 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008458 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008461
8462 // Check too high (line width of 65536.0f).
8463 rs_ci.lineWidth = 65536.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);
Mark Young7394fdd2016-03-31 14:56:43 -06008468
8469 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008470 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008471
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008472 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008473
8474 dyn_state_ci.dynamicStateCount = 3;
8475
8476 rs_ci.lineWidth = 1.0f;
8477
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008478 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008479 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008480 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008481 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008482 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008483
8484 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008485 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008486 m_errorMonitor->VerifyFound();
8487
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008488 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008489
8490 // Check too high with dynamic setting.
8491 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8492 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008493 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008494
8495 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8496 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8497 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8498 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008499 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008500}
8501
Karl Schultz6addd812016-02-02 17:17:23 -07008502TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008503 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008505 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008506
8507 ASSERT_NO_FATAL_FAILURE(InitState());
8508 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008509
Tony Barbour552f6c02016-12-21 14:34:07 -07008510 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008511 // Don't care about RenderPass handle b/c error should be flagged before
8512 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008514
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008515 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008516}
8517
Karl Schultz6addd812016-02-02 17:17:23 -07008518TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008519 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8521 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008522
8523 ASSERT_NO_FATAL_FAILURE(InitState());
8524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008525
Tony Barbour552f6c02016-12-21 14:34:07 -07008526 m_commandBuffer->BeginCommandBuffer();
8527 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008528 // Just create a dummy Renderpass that's non-NULL so we can get to the
8529 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008530 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008531
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008532 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008533}
8534
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008535TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008536 TEST_DESCRIPTION(
8537 "Begin a renderPass where clearValueCount is less than"
8538 "the number of renderPass attachments that use loadOp"
8539 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008540
8541 ASSERT_NO_FATAL_FAILURE(InitState());
8542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8543
8544 // Create a renderPass with a single attachment that uses loadOp CLEAR
8545 VkAttachmentReference attach = {};
8546 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8547 VkSubpassDescription subpass = {};
8548 subpass.inputAttachmentCount = 1;
8549 subpass.pInputAttachments = &attach;
8550 VkRenderPassCreateInfo rpci = {};
8551 rpci.subpassCount = 1;
8552 rpci.pSubpasses = &subpass;
8553 rpci.attachmentCount = 1;
8554 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008555 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008556 // Set loadOp to CLEAR
8557 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8558 rpci.pAttachments = &attach_desc;
8559 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8560 VkRenderPass rp;
8561 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8562
8563 VkCommandBufferInheritanceInfo hinfo = {};
8564 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8565 hinfo.renderPass = VK_NULL_HANDLE;
8566 hinfo.subpass = 0;
8567 hinfo.framebuffer = VK_NULL_HANDLE;
8568 hinfo.occlusionQueryEnable = VK_FALSE;
8569 hinfo.queryFlags = 0;
8570 hinfo.pipelineStatistics = 0;
8571 VkCommandBufferBeginInfo info = {};
8572 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8573 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8574 info.pInheritanceInfo = &hinfo;
8575
8576 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8577 VkRenderPassBeginInfo rp_begin = {};
8578 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8579 rp_begin.pNext = NULL;
8580 rp_begin.renderPass = renderPass();
8581 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008582 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008583
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008586 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008587
8588 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008589
8590 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008591}
8592
Slawomir Cygan0808f392016-11-28 17:53:23 +01008593TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008594 TEST_DESCRIPTION(
8595 "Begin a renderPass where clearValueCount is greater than"
8596 "the number of renderPass attachments that use loadOp"
8597 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008598
8599 ASSERT_NO_FATAL_FAILURE(InitState());
8600 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8601
8602 // Create a renderPass with a single attachment that uses loadOp CLEAR
8603 VkAttachmentReference attach = {};
8604 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8605 VkSubpassDescription subpass = {};
8606 subpass.inputAttachmentCount = 1;
8607 subpass.pInputAttachments = &attach;
8608 VkRenderPassCreateInfo rpci = {};
8609 rpci.subpassCount = 1;
8610 rpci.pSubpasses = &subpass;
8611 rpci.attachmentCount = 1;
8612 VkAttachmentDescription attach_desc = {};
8613 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8614 // Set loadOp to CLEAR
8615 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8616 rpci.pAttachments = &attach_desc;
8617 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8618 VkRenderPass rp;
8619 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8620
8621 VkCommandBufferBeginInfo info = {};
8622 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8623 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8624
8625 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8626 VkRenderPassBeginInfo rp_begin = {};
8627 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8628 rp_begin.pNext = NULL;
8629 rp_begin.renderPass = renderPass();
8630 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008631 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008632
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8634 " has a clearValueCount of"
8635 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008636
8637 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8638
8639 m_errorMonitor->VerifyFound();
8640
8641 vkDestroyRenderPass(m_device->device(), rp, NULL);
8642}
8643
Cody Northrop3bb4d962016-05-09 16:15:57 -06008644TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008645 TEST_DESCRIPTION("End a command buffer with an active render pass");
8646
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8648 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008649
8650 ASSERT_NO_FATAL_FAILURE(InitState());
8651 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8652
Tony Barbour552f6c02016-12-21 14:34:07 -07008653 m_commandBuffer->BeginCommandBuffer();
8654 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8655 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008656
8657 m_errorMonitor->VerifyFound();
8658
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008659 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8660 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008661}
8662
Karl Schultz6addd812016-02-02 17:17:23 -07008663TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008664 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008665 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8666 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008667
8668 ASSERT_NO_FATAL_FAILURE(InitState());
8669 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008670
Tony Barbour552f6c02016-12-21 14:34:07 -07008671 m_commandBuffer->BeginCommandBuffer();
8672 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008673
8674 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008675 vk_testing::Buffer dstBuffer;
8676 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008677
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008678 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008680 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008681}
8682
Karl Schultz6addd812016-02-02 17:17:23 -07008683TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008684 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8686 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008687
8688 ASSERT_NO_FATAL_FAILURE(InitState());
8689 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690
Tony Barbour552f6c02016-12-21 14:34:07 -07008691 m_commandBuffer->BeginCommandBuffer();
8692 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693
8694 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008695 vk_testing::Buffer dstBuffer;
8696 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008697
Karl Schultz6addd812016-02-02 17:17:23 -07008698 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008699 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8700 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8701 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008703 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008704}
8705
Karl Schultz6addd812016-02-02 17:17:23 -07008706TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008707 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8709 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008710
8711 ASSERT_NO_FATAL_FAILURE(InitState());
8712 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008713
Tony Barbour552f6c02016-12-21 14:34:07 -07008714 m_commandBuffer->BeginCommandBuffer();
8715 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716
Michael Lentine0a369f62016-02-03 16:51:46 -06008717 VkClearColorValue clear_color;
8718 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008719 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8720 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8721 const int32_t tex_width = 32;
8722 const int32_t tex_height = 32;
8723 VkImageCreateInfo image_create_info = {};
8724 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8725 image_create_info.pNext = NULL;
8726 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8727 image_create_info.format = tex_format;
8728 image_create_info.extent.width = tex_width;
8729 image_create_info.extent.height = tex_height;
8730 image_create_info.extent.depth = 1;
8731 image_create_info.mipLevels = 1;
8732 image_create_info.arrayLayers = 1;
8733 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8734 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8735 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008736
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008737 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008738 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008740 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008741
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008742 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008743 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008744
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008745 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008746}
8747
Karl Schultz6addd812016-02-02 17:17:23 -07008748TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008749 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8751 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008752
8753 ASSERT_NO_FATAL_FAILURE(InitState());
8754 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008755
Tony Barbour552f6c02016-12-21 14:34:07 -07008756 m_commandBuffer->BeginCommandBuffer();
8757 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008758
8759 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008760 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008761 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8762 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8763 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8764 image_create_info.extent.width = 64;
8765 image_create_info.extent.height = 64;
8766 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8767 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008768
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008769 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008770 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008771
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008772 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008773
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008774 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8775 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008776
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008777 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008778}
8779
Karl Schultz6addd812016-02-02 17:17:23 -07008780TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008781 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008782 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008783
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8785 "vkCmdClearAttachments(): This call "
8786 "must be issued inside an active "
8787 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008788
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008789 ASSERT_NO_FATAL_FAILURE(InitState());
8790 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008791
8792 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008793 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794 ASSERT_VK_SUCCESS(err);
8795
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008796 VkClearAttachment color_attachment;
8797 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8798 color_attachment.clearValue.color.float32[0] = 0;
8799 color_attachment.clearValue.color.float32[1] = 0;
8800 color_attachment.clearValue.color.float32[2] = 0;
8801 color_attachment.clearValue.color.float32[3] = 0;
8802 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008803 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008804 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008805
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008806 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008807}
8808
Chris Forbes3b97e932016-09-07 11:29:24 +12008809TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008810 TEST_DESCRIPTION(
8811 "Test that an error is produced when CmdNextSubpass is "
8812 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008813
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008814 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8815 "vkCmdNextSubpass(): Attempted to advance "
8816 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008817
8818 ASSERT_NO_FATAL_FAILURE(InitState());
8819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8820
Tony Barbour552f6c02016-12-21 14:34:07 -07008821 m_commandBuffer->BeginCommandBuffer();
8822 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008823
8824 // error here.
8825 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8826 m_errorMonitor->VerifyFound();
8827
Tony Barbour552f6c02016-12-21 14:34:07 -07008828 m_commandBuffer->EndRenderPass();
8829 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008830}
8831
Chris Forbes6d624702016-09-07 13:57:05 +12008832TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008833 TEST_DESCRIPTION(
8834 "Test that an error is produced when CmdEndRenderPass is "
8835 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008836
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8838 "vkCmdEndRenderPass(): Called before reaching "
8839 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008840
8841 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008842 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8843 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008844
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008845 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008846
8847 VkRenderPass rp;
8848 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8849 ASSERT_VK_SUCCESS(err);
8850
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008851 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008852
8853 VkFramebuffer fb;
8854 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8855 ASSERT_VK_SUCCESS(err);
8856
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008857 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 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 +12008860
8861 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8862
8863 // Error here.
8864 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8865 m_errorMonitor->VerifyFound();
8866
8867 // Clean up.
8868 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8869 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8870}
8871
Karl Schultz9e66a292016-04-21 15:57:51 -06008872TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8873 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8875 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008876
8877 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008878 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008879
8880 VkBufferMemoryBarrier buf_barrier = {};
8881 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8882 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8883 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8884 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8885 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8886 buf_barrier.buffer = VK_NULL_HANDLE;
8887 buf_barrier.offset = 0;
8888 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008889 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8890 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008891
8892 m_errorMonitor->VerifyFound();
8893}
8894
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008895TEST_F(VkLayerTest, InvalidBarriers) {
8896 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8897
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008898 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008899
8900 ASSERT_NO_FATAL_FAILURE(InitState());
8901 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8902
8903 VkMemoryBarrier mem_barrier = {};
8904 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8905 mem_barrier.pNext = NULL;
8906 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8907 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008908 m_commandBuffer->BeginCommandBuffer();
8909 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008910 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008911 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008912 &mem_barrier, 0, nullptr, 0, nullptr);
8913 m_errorMonitor->VerifyFound();
8914
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008915 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008916 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008917 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 -06008918 ASSERT_TRUE(image.initialized());
8919 VkImageMemoryBarrier img_barrier = {};
8920 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8921 img_barrier.pNext = NULL;
8922 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8923 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8924 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8925 // New layout can't be UNDEFINED
8926 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8927 img_barrier.image = image.handle();
8928 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8929 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8930 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8931 img_barrier.subresourceRange.baseArrayLayer = 0;
8932 img_barrier.subresourceRange.baseMipLevel = 0;
8933 img_barrier.subresourceRange.layerCount = 1;
8934 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008935 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8936 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008937 m_errorMonitor->VerifyFound();
8938 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8939
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008940 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8941 "Subresource must have the sum of the "
8942 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008943 // baseArrayLayer + layerCount must be <= image's arrayLayers
8944 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008945 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8946 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008947 m_errorMonitor->VerifyFound();
8948 img_barrier.subresourceRange.baseArrayLayer = 0;
8949
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008950 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008951 // baseMipLevel + levelCount must be <= image's mipLevels
8952 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008953 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8954 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008955 m_errorMonitor->VerifyFound();
8956 img_barrier.subresourceRange.baseMipLevel = 0;
8957
Mike Weiblen7053aa32017-01-25 15:21:10 -07008958 // levelCount must be non-zero.
8959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8960 img_barrier.subresourceRange.levelCount = 0;
8961 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8962 nullptr, 0, nullptr, 1, &img_barrier);
8963 m_errorMonitor->VerifyFound();
8964 img_barrier.subresourceRange.levelCount = 1;
8965
8966 // layerCount must be non-zero.
8967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8968 img_barrier.subresourceRange.layerCount = 0;
8969 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8970 nullptr, 0, nullptr, 1, &img_barrier);
8971 m_errorMonitor->VerifyFound();
8972 img_barrier.subresourceRange.layerCount = 1;
8973
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008974 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 -06008975 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008976 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8977 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008978 VkBufferMemoryBarrier buf_barrier = {};
8979 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8980 buf_barrier.pNext = NULL;
8981 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8982 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8983 buf_barrier.buffer = buffer.handle();
8984 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8985 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8986 buf_barrier.offset = 0;
8987 buf_barrier.size = VK_WHOLE_SIZE;
8988 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008989 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8990 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008991 m_errorMonitor->VerifyFound();
8992 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8993
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008995 buf_barrier.offset = 257;
8996 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008997 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8998 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008999 m_errorMonitor->VerifyFound();
9000 buf_barrier.offset = 0;
9001
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009002 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009003 buf_barrier.size = 257;
9004 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9006 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009007 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009008
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009009 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009010 m_errorMonitor->SetDesiredFailureMsg(
9011 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009012 "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 -06009013 VkDepthStencilObj ds_image(m_device);
9014 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9015 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009016 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9017 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009018 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009019
9020 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009021 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009022 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9023 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009024 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009025
9026 // Having anything other than DEPTH or STENCIL is an error
9027 m_errorMonitor->SetDesiredFailureMsg(
9028 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9029 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9030 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9031 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9032 nullptr, 0, nullptr, 1, &img_barrier);
9033 m_errorMonitor->VerifyFound();
9034
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009035 // Now test depth-only
9036 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009037 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9038 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009039 VkDepthStencilObj d_image(m_device);
9040 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9041 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009042 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009043 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009044 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009045
9046 // DEPTH bit must be set
9047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9048 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009049 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009050 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9051 0, nullptr, 0, nullptr, 1, &img_barrier);
9052 m_errorMonitor->VerifyFound();
9053
9054 // No bits other than DEPTH may be set
9055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9056 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9057 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009058 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9059 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009060 m_errorMonitor->VerifyFound();
9061 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009062
9063 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009064 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9065 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009066 VkDepthStencilObj s_image(m_device);
9067 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9068 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009069 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009070 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009071 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009072 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9074 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009075 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009076 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9077 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009078 m_errorMonitor->VerifyFound();
9079 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009080
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009081 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009082 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 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 -06009084 ASSERT_TRUE(c_image.initialized());
9085 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9086 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9087 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009088
9089 // COLOR bit must be set
9090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9091 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009092 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009093 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9094 nullptr, 0, nullptr, 1, &img_barrier);
9095 m_errorMonitor->VerifyFound();
9096
9097 // No bits other than COLOR may be set
9098 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9099 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9100 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009101 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9102 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009103 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009104
9105 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9106
9107 // Create command pool with incompatible queueflags
9108 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9109 uint32_t queue_family_index = UINT32_MAX;
9110 for (uint32_t i = 0; i < queue_props.size(); i++) {
9111 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9112 queue_family_index = i;
9113 break;
9114 }
9115 }
9116 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009117 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009118 return;
9119 }
9120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9121
9122 VkCommandPool command_pool;
9123 VkCommandPoolCreateInfo pool_create_info{};
9124 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9125 pool_create_info.queueFamilyIndex = queue_family_index;
9126 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9127 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9128
9129 // Allocate a command buffer
9130 VkCommandBuffer bad_command_buffer;
9131 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9132 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9133 command_buffer_allocate_info.commandPool = command_pool;
9134 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9135 command_buffer_allocate_info.commandBufferCount = 1;
9136 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9137
9138 VkCommandBufferBeginInfo cbbi = {};
9139 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9140 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9141 buf_barrier.offset = 0;
9142 buf_barrier.size = VK_WHOLE_SIZE;
9143 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9144 &buf_barrier, 0, nullptr);
9145 m_errorMonitor->VerifyFound();
9146
9147 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9148 vkEndCommandBuffer(bad_command_buffer);
9149 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009150 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009151 return;
9152 }
9153 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9154 VkEvent event;
9155 VkEventCreateInfo event_create_info{};
9156 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9157 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9158 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9159 nullptr, 0, nullptr);
9160 m_errorMonitor->VerifyFound();
9161
9162 vkEndCommandBuffer(bad_command_buffer);
9163 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009164}
9165
Tony Barbour18ba25c2016-09-29 13:42:40 -06009166TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9167 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9168
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009170 ASSERT_NO_FATAL_FAILURE(InitState());
9171 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009172 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 -06009173 ASSERT_TRUE(image.initialized());
9174
9175 VkImageMemoryBarrier barrier = {};
9176 VkImageSubresourceRange range;
9177 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9178 barrier.srcAccessMask = 0;
9179 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9180 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9181 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9182 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9183 barrier.image = image.handle();
9184 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9185 range.baseMipLevel = 0;
9186 range.levelCount = 1;
9187 range.baseArrayLayer = 0;
9188 range.layerCount = 1;
9189 barrier.subresourceRange = range;
9190 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9191 cmdbuf.BeginCommandBuffer();
9192 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9193 &barrier);
9194 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9195 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9196 barrier.srcAccessMask = 0;
9197 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9198 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9199 &barrier);
9200
9201 m_errorMonitor->VerifyFound();
9202}
9203
Karl Schultz6addd812016-02-02 17:17:23 -07009204TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009205 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009206 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009207
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009209
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009210 ASSERT_NO_FATAL_FAILURE(InitState());
9211 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009212 uint32_t qfi = 0;
9213 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009214 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9215 buffCI.size = 1024;
9216 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9217 buffCI.queueFamilyIndexCount = 1;
9218 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009219
9220 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009221 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009222 ASSERT_VK_SUCCESS(err);
9223
Tony Barbour552f6c02016-12-21 14:34:07 -07009224 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009225 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009226 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9227 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009228 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009229 m_errorMonitor->SetUnexpectedError(
9230 "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 -06009231 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009232
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009233 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009234
Chia-I Wuf7458c52015-10-26 21:10:41 +08009235 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009236}
9237
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009238TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9239 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9241 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9242 "of the indices specified when the device was created, via the "
9243 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009244
9245 ASSERT_NO_FATAL_FAILURE(InitState());
9246 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9247 VkBufferCreateInfo buffCI = {};
9248 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9249 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009250 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009251 buffCI.queueFamilyIndexCount = 1;
9252 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009253 uint32_t qfi[2];
9254 qfi[0] = 777;
9255
9256 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009257 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009258
9259 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009260 m_errorMonitor->SetUnexpectedError(
9261 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009262 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9263
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009264 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009265
9266 if (m_device->queue_props.size() > 2) {
9267 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9268
9269 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9270 buffCI.queueFamilyIndexCount = 2;
9271 qfi[0] = 1;
9272 qfi[1] = 2;
9273 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9274 VkDeviceMemory mem;
9275 VkMemoryRequirements mem_reqs;
9276 vkGetBufferMemoryRequirements(m_device->device(), ib, &mem_reqs);
9277
9278 VkMemoryAllocateInfo alloc_info = {};
9279 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9280 alloc_info.allocationSize = 1024;
9281 bool pass = false;
9282 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9283 if (!pass) {
9284 vkDestroyBuffer(m_device->device(), ib, NULL);
9285 return;
9286 }
9287 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
9288 vkBindBufferMemory(m_device->device(), ib, mem, 0);
9289
9290 m_commandBuffer->begin();
9291 vkCmdFillBuffer(m_commandBuffer->handle(), ib, 0, 16, 5);
9292 m_commandBuffer->end();
9293 QueueCommandBuffer(false);
9294 m_errorMonitor->VerifyFound();
9295 }
9296
Tony Barbourdf4c0042016-06-01 15:55:43 -06009297 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009298}
9299
Karl Schultz6addd812016-02-02 17:17:23 -07009300TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009301 TEST_DESCRIPTION(
9302 "Attempt vkCmdExecuteCommands with a primary command buffer"
9303 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009304
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009305 ASSERT_NO_FATAL_FAILURE(InitState());
9306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009307
Chris Forbesf29a84f2016-10-06 18:39:28 +13009308 // An empty primary command buffer
9309 VkCommandBufferObj cb(m_device, m_commandPool);
9310 cb.BeginCommandBuffer();
9311 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009312
Chris Forbesf29a84f2016-10-06 18:39:28 +13009313 m_commandBuffer->BeginCommandBuffer();
9314 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9315 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009316
Chris Forbesf29a84f2016-10-06 18:39:28 +13009317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9318 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009319 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009320
9321 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009322}
9323
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009324TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009325 TEST_DESCRIPTION(
9326 "Attempt to update descriptor sets for images and buffers "
9327 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009328 VkResult err;
9329
9330 ASSERT_NO_FATAL_FAILURE(InitState());
9331 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9332 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9333 ds_type_count[i].type = VkDescriptorType(i);
9334 ds_type_count[i].descriptorCount = 1;
9335 }
9336 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9337 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9338 ds_pool_ci.pNext = NULL;
9339 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9340 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9341 ds_pool_ci.pPoolSizes = ds_type_count;
9342
9343 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009344 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009345 ASSERT_VK_SUCCESS(err);
9346
9347 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009348 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009349 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9350 dsl_binding[i].binding = 0;
9351 dsl_binding[i].descriptorType = VkDescriptorType(i);
9352 dsl_binding[i].descriptorCount = 1;
9353 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9354 dsl_binding[i].pImmutableSamplers = NULL;
9355 }
9356
9357 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9358 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9359 ds_layout_ci.pNext = NULL;
9360 ds_layout_ci.bindingCount = 1;
9361 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9362 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9363 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009364 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009365 ASSERT_VK_SUCCESS(err);
9366 }
9367 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9368 VkDescriptorSetAllocateInfo alloc_info = {};
9369 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9370 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9371 alloc_info.descriptorPool = ds_pool;
9372 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009373 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009374 ASSERT_VK_SUCCESS(err);
9375
9376 // Create a buffer & bufferView to be used for invalid updates
9377 VkBufferCreateInfo buff_ci = {};
9378 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009379 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009380 buff_ci.size = 256;
9381 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009382 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009383 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9384 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009385
9386 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9387 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9388 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9389 ASSERT_VK_SUCCESS(err);
9390
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009391 VkMemoryRequirements mem_reqs;
9392 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9393 VkMemoryAllocateInfo mem_alloc_info = {};
9394 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9395 mem_alloc_info.pNext = NULL;
9396 mem_alloc_info.memoryTypeIndex = 0;
9397 mem_alloc_info.allocationSize = mem_reqs.size;
9398 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9399 if (!pass) {
9400 vkDestroyBuffer(m_device->device(), buffer, NULL);
9401 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9402 return;
9403 }
9404 VkDeviceMemory mem;
9405 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9406 ASSERT_VK_SUCCESS(err);
9407 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9408 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009409
9410 VkBufferViewCreateInfo buff_view_ci = {};
9411 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9412 buff_view_ci.buffer = buffer;
9413 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9414 buff_view_ci.range = VK_WHOLE_SIZE;
9415 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009416 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009417 ASSERT_VK_SUCCESS(err);
9418
Tony Barbour415497c2017-01-24 10:06:09 -07009419 // Now get resources / view for storage_texel_buffer
9420 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9421 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9422 if (!pass) {
9423 vkDestroyBuffer(m_device->device(), buffer, NULL);
9424 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9425 vkFreeMemory(m_device->device(), mem, NULL);
9426 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9427 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9428 return;
9429 }
9430 VkDeviceMemory storage_texel_buffer_mem;
9431 VkBufferView storage_texel_buffer_view;
9432 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9433 ASSERT_VK_SUCCESS(err);
9434 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9435 ASSERT_VK_SUCCESS(err);
9436 buff_view_ci.buffer = storage_texel_buffer;
9437 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9438 ASSERT_VK_SUCCESS(err);
9439
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009440 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009441 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009442 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009443 image_ci.format = VK_FORMAT_UNDEFINED;
9444 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9445 VkFormat format = static_cast<VkFormat>(f);
9446 VkFormatProperties fProps = m_device->format_properties(format);
9447 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9448 image_ci.format = format;
9449 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9450 break;
9451 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9452 image_ci.format = format;
9453 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9454 break;
9455 }
9456 }
9457 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9458 return;
9459 }
9460
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009461 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9462 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009463 image_ci.extent.width = 64;
9464 image_ci.extent.height = 64;
9465 image_ci.extent.depth = 1;
9466 image_ci.mipLevels = 1;
9467 image_ci.arrayLayers = 1;
9468 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009469 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009470 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009471 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9472 VkImage image;
9473 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9474 ASSERT_VK_SUCCESS(err);
9475 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009476 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009477
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009478 VkMemoryAllocateInfo mem_alloc = {};
9479 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9480 mem_alloc.pNext = NULL;
9481 mem_alloc.allocationSize = 0;
9482 mem_alloc.memoryTypeIndex = 0;
9483 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9484 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009485 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009486 ASSERT_TRUE(pass);
9487 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9488 ASSERT_VK_SUCCESS(err);
9489 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9490 ASSERT_VK_SUCCESS(err);
9491 // Now create view for image
9492 VkImageViewCreateInfo image_view_ci = {};
9493 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9494 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009495 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009496 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9497 image_view_ci.subresourceRange.layerCount = 1;
9498 image_view_ci.subresourceRange.baseArrayLayer = 0;
9499 image_view_ci.subresourceRange.levelCount = 1;
9500 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9501 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009502 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009503 ASSERT_VK_SUCCESS(err);
9504
9505 VkDescriptorBufferInfo buff_info = {};
9506 buff_info.buffer = buffer;
9507 VkDescriptorImageInfo img_info = {};
9508 img_info.imageView = image_view;
9509 VkWriteDescriptorSet descriptor_write = {};
9510 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9511 descriptor_write.dstBinding = 0;
9512 descriptor_write.descriptorCount = 1;
9513 descriptor_write.pTexelBufferView = &buff_view;
9514 descriptor_write.pBufferInfo = &buff_info;
9515 descriptor_write.pImageInfo = &img_info;
9516
9517 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009518 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009519 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9520 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9521 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9522 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9523 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9524 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9525 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9526 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9527 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9528 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9529 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009530 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009531 // Start loop at 1 as SAMPLER desc type has no usage bit error
9532 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009533 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9534 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9535 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9536 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009537 descriptor_write.descriptorType = VkDescriptorType(i);
9538 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009540
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009541 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009542
9543 m_errorMonitor->VerifyFound();
9544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009545 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9546 descriptor_write.pTexelBufferView = &buff_view;
9547 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009548 }
Tony Barbour415497c2017-01-24 10:06:09 -07009549
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009550 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9551 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009552 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009553 vkDestroyImageView(m_device->device(), image_view, NULL);
9554 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009555 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009556 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009557 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009558 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009559 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009560 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9561}
9562
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009563TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009564 TEST_DESCRIPTION(
9565 "Attempt to update buffer descriptor set that has incorrect "
9566 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9567 "1. offset value greater than buffer size\n"
9568 "2. range value of 0\n"
9569 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009570 VkResult err;
9571
9572 ASSERT_NO_FATAL_FAILURE(InitState());
9573 VkDescriptorPoolSize ds_type_count = {};
9574 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9575 ds_type_count.descriptorCount = 1;
9576
9577 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9578 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9579 ds_pool_ci.pNext = NULL;
9580 ds_pool_ci.maxSets = 1;
9581 ds_pool_ci.poolSizeCount = 1;
9582 ds_pool_ci.pPoolSizes = &ds_type_count;
9583
9584 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009585 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009586 ASSERT_VK_SUCCESS(err);
9587
9588 // Create layout with single uniform buffer descriptor
9589 VkDescriptorSetLayoutBinding dsl_binding = {};
9590 dsl_binding.binding = 0;
9591 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9592 dsl_binding.descriptorCount = 1;
9593 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9594 dsl_binding.pImmutableSamplers = NULL;
9595
9596 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9597 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9598 ds_layout_ci.pNext = NULL;
9599 ds_layout_ci.bindingCount = 1;
9600 ds_layout_ci.pBindings = &dsl_binding;
9601 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009603 ASSERT_VK_SUCCESS(err);
9604
9605 VkDescriptorSet descriptor_set = {};
9606 VkDescriptorSetAllocateInfo alloc_info = {};
9607 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9608 alloc_info.descriptorSetCount = 1;
9609 alloc_info.descriptorPool = ds_pool;
9610 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009611 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009612 ASSERT_VK_SUCCESS(err);
9613
9614 // Create a buffer to be used for invalid updates
9615 VkBufferCreateInfo buff_ci = {};
9616 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9617 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9618 buff_ci.size = 256;
9619 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9620 VkBuffer buffer;
9621 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9622 ASSERT_VK_SUCCESS(err);
9623 // Have to bind memory to buffer before descriptor update
9624 VkMemoryAllocateInfo mem_alloc = {};
9625 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9626 mem_alloc.pNext = NULL;
9627 mem_alloc.allocationSize = 256;
9628 mem_alloc.memoryTypeIndex = 0;
9629
9630 VkMemoryRequirements mem_reqs;
9631 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009633 if (!pass) {
9634 vkDestroyBuffer(m_device->device(), buffer, NULL);
9635 return;
9636 }
9637
9638 VkDeviceMemory mem;
9639 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9640 ASSERT_VK_SUCCESS(err);
9641 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9642 ASSERT_VK_SUCCESS(err);
9643
9644 VkDescriptorBufferInfo buff_info = {};
9645 buff_info.buffer = buffer;
9646 // First make offset 1 larger than buffer size
9647 buff_info.offset = 257;
9648 buff_info.range = VK_WHOLE_SIZE;
9649 VkWriteDescriptorSet descriptor_write = {};
9650 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9651 descriptor_write.dstBinding = 0;
9652 descriptor_write.descriptorCount = 1;
9653 descriptor_write.pTexelBufferView = nullptr;
9654 descriptor_write.pBufferInfo = &buff_info;
9655 descriptor_write.pImageInfo = nullptr;
9656
9657 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9658 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009660
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009661 m_errorMonitor->SetUnexpectedError(
9662 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9663 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009664 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9665
9666 m_errorMonitor->VerifyFound();
9667 // Now cause error due to range of 0
9668 buff_info.offset = 0;
9669 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009671
9672 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9673
9674 m_errorMonitor->VerifyFound();
9675 // Now cause error due to range exceeding buffer size - offset
9676 buff_info.offset = 128;
9677 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009678 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009679
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009680 m_errorMonitor->SetUnexpectedError(
9681 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9682 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009683 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9684
9685 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009686 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009687 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9688 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009689 m_errorMonitor->SetUnexpectedError(
9690 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009691 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9692 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9693}
9694
Tobin Ehlis845887e2017-02-02 19:01:44 -07009695TEST_F(VkLayerTest, DSBufferLimitErrors) {
9696 TEST_DESCRIPTION(
9697 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9698 "Test cases include:\n"
9699 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9700 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9701 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9702 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9703 VkResult err;
9704
9705 ASSERT_NO_FATAL_FAILURE(InitState());
9706 VkDescriptorPoolSize ds_type_count[2] = {};
9707 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9708 ds_type_count[0].descriptorCount = 1;
9709 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9710 ds_type_count[1].descriptorCount = 1;
9711
9712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9714 ds_pool_ci.pNext = NULL;
9715 ds_pool_ci.maxSets = 1;
9716 ds_pool_ci.poolSizeCount = 2;
9717 ds_pool_ci.pPoolSizes = ds_type_count;
9718
9719 VkDescriptorPool ds_pool;
9720 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9721 ASSERT_VK_SUCCESS(err);
9722
9723 // Create layout with single uniform buffer & single storage buffer descriptor
9724 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9725 dsl_binding[0].binding = 0;
9726 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9727 dsl_binding[0].descriptorCount = 1;
9728 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9729 dsl_binding[0].pImmutableSamplers = NULL;
9730 dsl_binding[1].binding = 1;
9731 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9732 dsl_binding[1].descriptorCount = 1;
9733 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9734 dsl_binding[1].pImmutableSamplers = NULL;
9735
9736 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9737 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9738 ds_layout_ci.pNext = NULL;
9739 ds_layout_ci.bindingCount = 2;
9740 ds_layout_ci.pBindings = dsl_binding;
9741 VkDescriptorSetLayout ds_layout;
9742 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9743 ASSERT_VK_SUCCESS(err);
9744
9745 VkDescriptorSet descriptor_set = {};
9746 VkDescriptorSetAllocateInfo alloc_info = {};
9747 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9748 alloc_info.descriptorSetCount = 1;
9749 alloc_info.descriptorPool = ds_pool;
9750 alloc_info.pSetLayouts = &ds_layout;
9751 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9752 ASSERT_VK_SUCCESS(err);
9753
9754 // Create a buffer to be used for invalid updates
9755 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9756 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9757 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9758 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9759 VkBufferCreateInfo ub_ci = {};
9760 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9761 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9762 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9763 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9764 VkBuffer uniform_buffer;
9765 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9766 ASSERT_VK_SUCCESS(err);
9767 VkBufferCreateInfo sb_ci = {};
9768 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9769 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9770 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9771 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9772 VkBuffer storage_buffer;
9773 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9774 ASSERT_VK_SUCCESS(err);
9775 // Have to bind memory to buffer before descriptor update
9776 VkMemoryAllocateInfo mem_alloc = {};
9777 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9778 mem_alloc.pNext = NULL;
9779 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9780 mem_alloc.memoryTypeIndex = 0;
9781
9782 VkMemoryRequirements mem_reqs;
9783 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9784 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9785 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9786 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9787 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009788 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009789 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009790 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9791 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009792 return;
9793 }
9794
9795 VkDeviceMemory mem;
9796 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009797 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009798 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9800 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9801 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9802 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9803 return;
9804 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009805 ASSERT_VK_SUCCESS(err);
9806 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9807 ASSERT_VK_SUCCESS(err);
9808 auto sb_offset = ub_ci.size + 1024;
9809 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9810 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9811 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9812 ASSERT_VK_SUCCESS(err);
9813
9814 VkDescriptorBufferInfo buff_info = {};
9815 buff_info.buffer = uniform_buffer;
9816 buff_info.range = ub_ci.size; // This will exceed limit
9817 VkWriteDescriptorSet descriptor_write = {};
9818 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9819 descriptor_write.dstBinding = 0;
9820 descriptor_write.descriptorCount = 1;
9821 descriptor_write.pTexelBufferView = nullptr;
9822 descriptor_write.pBufferInfo = &buff_info;
9823 descriptor_write.pImageInfo = nullptr;
9824
9825 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9826 descriptor_write.dstSet = descriptor_set;
9827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9828 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9829 m_errorMonitor->VerifyFound();
9830
9831 // Reduce size of range to acceptable limit & cause offset error
9832 buff_info.range = max_ub_range;
9833 buff_info.offset = min_ub_align - 1;
9834 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9835 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9836 m_errorMonitor->VerifyFound();
9837
9838 // Now break storage updates
9839 buff_info.buffer = storage_buffer;
9840 buff_info.range = sb_ci.size; // This will exceed limit
9841 buff_info.offset = 0; // Reset offset for this update
9842
9843 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9844 descriptor_write.dstBinding = 1;
9845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9847 m_errorMonitor->VerifyFound();
9848
9849 // Reduce size of range to acceptable limit & cause offset error
9850 buff_info.range = max_sb_range;
9851 buff_info.offset = min_sb_align - 1;
9852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9854 m_errorMonitor->VerifyFound();
9855
9856 vkFreeMemory(m_device->device(), mem, NULL);
9857 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9858 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9859 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9860 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9861}
9862
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009863TEST_F(VkLayerTest, DSAspectBitsErrors) {
9864 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9865 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009866 TEST_DESCRIPTION(
9867 "Attempt to update descriptor sets for images "
9868 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009869 VkResult err;
9870
9871 ASSERT_NO_FATAL_FAILURE(InitState());
9872 VkDescriptorPoolSize ds_type_count = {};
9873 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9874 ds_type_count.descriptorCount = 1;
9875
9876 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9877 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9878 ds_pool_ci.pNext = NULL;
9879 ds_pool_ci.maxSets = 5;
9880 ds_pool_ci.poolSizeCount = 1;
9881 ds_pool_ci.pPoolSizes = &ds_type_count;
9882
9883 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009884 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009885 ASSERT_VK_SUCCESS(err);
9886
9887 VkDescriptorSetLayoutBinding dsl_binding = {};
9888 dsl_binding.binding = 0;
9889 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9890 dsl_binding.descriptorCount = 1;
9891 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9892 dsl_binding.pImmutableSamplers = NULL;
9893
9894 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9895 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9896 ds_layout_ci.pNext = NULL;
9897 ds_layout_ci.bindingCount = 1;
9898 ds_layout_ci.pBindings = &dsl_binding;
9899 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009900 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009901 ASSERT_VK_SUCCESS(err);
9902
9903 VkDescriptorSet descriptor_set = {};
9904 VkDescriptorSetAllocateInfo alloc_info = {};
9905 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9906 alloc_info.descriptorSetCount = 1;
9907 alloc_info.descriptorPool = ds_pool;
9908 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009909 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009910 ASSERT_VK_SUCCESS(err);
9911
9912 // Create an image to be used for invalid updates
9913 VkImageCreateInfo image_ci = {};
9914 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9915 image_ci.imageType = VK_IMAGE_TYPE_2D;
9916 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9917 image_ci.extent.width = 64;
9918 image_ci.extent.height = 64;
9919 image_ci.extent.depth = 1;
9920 image_ci.mipLevels = 1;
9921 image_ci.arrayLayers = 1;
9922 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9923 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9924 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9925 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9926 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9927 VkImage image;
9928 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9929 ASSERT_VK_SUCCESS(err);
9930 // Bind memory to image
9931 VkMemoryRequirements mem_reqs;
9932 VkDeviceMemory image_mem;
9933 bool pass;
9934 VkMemoryAllocateInfo mem_alloc = {};
9935 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9936 mem_alloc.pNext = NULL;
9937 mem_alloc.allocationSize = 0;
9938 mem_alloc.memoryTypeIndex = 0;
9939 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9940 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009941 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009942 ASSERT_TRUE(pass);
9943 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9944 ASSERT_VK_SUCCESS(err);
9945 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9946 ASSERT_VK_SUCCESS(err);
9947 // Now create view for image
9948 VkImageViewCreateInfo image_view_ci = {};
9949 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9950 image_view_ci.image = image;
9951 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9952 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9953 image_view_ci.subresourceRange.layerCount = 1;
9954 image_view_ci.subresourceRange.baseArrayLayer = 0;
9955 image_view_ci.subresourceRange.levelCount = 1;
9956 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009957 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009958
9959 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009960 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009961 ASSERT_VK_SUCCESS(err);
9962
9963 VkDescriptorImageInfo img_info = {};
9964 img_info.imageView = image_view;
9965 VkWriteDescriptorSet descriptor_write = {};
9966 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9967 descriptor_write.dstBinding = 0;
9968 descriptor_write.descriptorCount = 1;
9969 descriptor_write.pTexelBufferView = NULL;
9970 descriptor_write.pBufferInfo = NULL;
9971 descriptor_write.pImageInfo = &img_info;
9972 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9973 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009974 const char *error_msg =
9975 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9976 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009978
9979 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9980
9981 m_errorMonitor->VerifyFound();
9982 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9983 vkDestroyImage(m_device->device(), image, NULL);
9984 vkFreeMemory(m_device->device(), image_mem, NULL);
9985 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009986 m_errorMonitor->SetUnexpectedError(
9987 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009988 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9989 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9990}
9991
Karl Schultz6addd812016-02-02 17:17:23 -07009992TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06009993 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -07009994 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -06009995
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009996 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9997 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
9998 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009999
Tobin Ehlis3b780662015-05-28 12:11:26 -060010000 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010001 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010002 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010003 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10004 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010005
10006 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010007 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10008 ds_pool_ci.pNext = NULL;
10009 ds_pool_ci.maxSets = 1;
10010 ds_pool_ci.poolSizeCount = 1;
10011 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010012
Tobin Ehlis3b780662015-05-28 12:11:26 -060010013 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010014 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010015 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010016 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010017 dsl_binding.binding = 0;
10018 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10019 dsl_binding.descriptorCount = 1;
10020 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10021 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010022
Tony Barboureb254902015-07-15 12:50:33 -060010023 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010024 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10025 ds_layout_ci.pNext = NULL;
10026 ds_layout_ci.bindingCount = 1;
10027 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010028
Tobin Ehlis3b780662015-05-28 12:11:26 -060010029 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010030 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010031 ASSERT_VK_SUCCESS(err);
10032
10033 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010034 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010035 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010036 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010037 alloc_info.descriptorPool = ds_pool;
10038 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010039 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010040 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010041
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010042 VkSamplerCreateInfo sampler_ci = {};
10043 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10044 sampler_ci.pNext = NULL;
10045 sampler_ci.magFilter = VK_FILTER_NEAREST;
10046 sampler_ci.minFilter = VK_FILTER_NEAREST;
10047 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10048 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10049 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10050 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10051 sampler_ci.mipLodBias = 1.0;
10052 sampler_ci.anisotropyEnable = VK_FALSE;
10053 sampler_ci.maxAnisotropy = 1;
10054 sampler_ci.compareEnable = VK_FALSE;
10055 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10056 sampler_ci.minLod = 1.0;
10057 sampler_ci.maxLod = 1.0;
10058 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10059 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10060 VkSampler sampler;
10061 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10062 ASSERT_VK_SUCCESS(err);
10063
10064 VkDescriptorImageInfo info = {};
10065 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010066
10067 VkWriteDescriptorSet descriptor_write;
10068 memset(&descriptor_write, 0, sizeof(descriptor_write));
10069 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010070 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010071 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010072 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010073 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010074 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010075
10076 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10077
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010078 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010079
Chia-I Wuf7458c52015-10-26 21:10:41 +080010080 vkDestroySampler(m_device->device(), sampler, NULL);
10081 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10082 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010083}
10084
Karl Schultz6addd812016-02-02 17:17:23 -070010085TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010086 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010087 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010088
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010090
Tobin Ehlis3b780662015-05-28 12:11:26 -060010091 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010092 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010093 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010094 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10095 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010096
10097 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010098 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10099 ds_pool_ci.pNext = NULL;
10100 ds_pool_ci.maxSets = 1;
10101 ds_pool_ci.poolSizeCount = 1;
10102 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010103
Tobin Ehlis3b780662015-05-28 12:11:26 -060010104 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010106 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010107
Tony Barboureb254902015-07-15 12:50:33 -060010108 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010109 dsl_binding.binding = 0;
10110 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10111 dsl_binding.descriptorCount = 1;
10112 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10113 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010114
10115 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010116 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10117 ds_layout_ci.pNext = NULL;
10118 ds_layout_ci.bindingCount = 1;
10119 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010120
Tobin Ehlis3b780662015-05-28 12:11:26 -060010121 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010123 ASSERT_VK_SUCCESS(err);
10124
10125 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010126 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010127 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010128 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010129 alloc_info.descriptorPool = ds_pool;
10130 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010131 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010132 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010133
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010134 // Correctly update descriptor to avoid "NOT_UPDATED" error
10135 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010136 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010137 buff_info.offset = 0;
10138 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010139
10140 VkWriteDescriptorSet descriptor_write;
10141 memset(&descriptor_write, 0, sizeof(descriptor_write));
10142 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010143 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010144 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010145 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010146 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10147 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010148
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010149 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010150 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10151
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010152 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010153
Chia-I Wuf7458c52015-10-26 21:10:41 +080010154 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10155 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010156}
10157
Karl Schultz6addd812016-02-02 17:17:23 -070010158TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010159 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010160 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010161
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010163
Tobin Ehlis3b780662015-05-28 12:11:26 -060010164 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010165 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010166 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010167 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10168 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010169
10170 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010171 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10172 ds_pool_ci.pNext = NULL;
10173 ds_pool_ci.maxSets = 1;
10174 ds_pool_ci.poolSizeCount = 1;
10175 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010176
Tobin Ehlis3b780662015-05-28 12:11:26 -060010177 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010178 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010179 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010180
Tony Barboureb254902015-07-15 12:50:33 -060010181 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010182 dsl_binding.binding = 0;
10183 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10184 dsl_binding.descriptorCount = 1;
10185 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10186 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010187
10188 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010189 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10190 ds_layout_ci.pNext = NULL;
10191 ds_layout_ci.bindingCount = 1;
10192 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010193 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010194 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010195 ASSERT_VK_SUCCESS(err);
10196
10197 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010198 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010199 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010200 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010201 alloc_info.descriptorPool = ds_pool;
10202 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010203 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010204 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010205
Tony Barboureb254902015-07-15 12:50:33 -060010206 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010207 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10208 sampler_ci.pNext = NULL;
10209 sampler_ci.magFilter = VK_FILTER_NEAREST;
10210 sampler_ci.minFilter = VK_FILTER_NEAREST;
10211 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10212 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10213 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10214 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10215 sampler_ci.mipLodBias = 1.0;
10216 sampler_ci.anisotropyEnable = VK_FALSE;
10217 sampler_ci.maxAnisotropy = 1;
10218 sampler_ci.compareEnable = VK_FALSE;
10219 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10220 sampler_ci.minLod = 1.0;
10221 sampler_ci.maxLod = 1.0;
10222 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10223 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010224
Tobin Ehlis3b780662015-05-28 12:11:26 -060010225 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010226 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010227 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010228
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010229 VkDescriptorImageInfo info = {};
10230 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010231
10232 VkWriteDescriptorSet descriptor_write;
10233 memset(&descriptor_write, 0, sizeof(descriptor_write));
10234 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010235 descriptor_write.dstSet = descriptorSet;
10236 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010237 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010238 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010239 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010240 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010241
10242 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10243
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010244 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010245
Chia-I Wuf7458c52015-10-26 21:10:41 +080010246 vkDestroySampler(m_device->device(), sampler, NULL);
10247 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10248 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010249}
10250
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010251TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10252 // Create layout w/ empty binding and attempt to update it
10253 VkResult err;
10254
10255 ASSERT_NO_FATAL_FAILURE(InitState());
10256
10257 VkDescriptorPoolSize ds_type_count = {};
10258 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10259 ds_type_count.descriptorCount = 1;
10260
10261 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10262 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10263 ds_pool_ci.pNext = NULL;
10264 ds_pool_ci.maxSets = 1;
10265 ds_pool_ci.poolSizeCount = 1;
10266 ds_pool_ci.pPoolSizes = &ds_type_count;
10267
10268 VkDescriptorPool ds_pool;
10269 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10270 ASSERT_VK_SUCCESS(err);
10271
10272 VkDescriptorSetLayoutBinding dsl_binding = {};
10273 dsl_binding.binding = 0;
10274 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10275 dsl_binding.descriptorCount = 0;
10276 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10277 dsl_binding.pImmutableSamplers = NULL;
10278
10279 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10280 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10281 ds_layout_ci.pNext = NULL;
10282 ds_layout_ci.bindingCount = 1;
10283 ds_layout_ci.pBindings = &dsl_binding;
10284 VkDescriptorSetLayout ds_layout;
10285 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10286 ASSERT_VK_SUCCESS(err);
10287
10288 VkDescriptorSet descriptor_set;
10289 VkDescriptorSetAllocateInfo alloc_info = {};
10290 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10291 alloc_info.descriptorSetCount = 1;
10292 alloc_info.descriptorPool = ds_pool;
10293 alloc_info.pSetLayouts = &ds_layout;
10294 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10295 ASSERT_VK_SUCCESS(err);
10296
10297 VkSamplerCreateInfo sampler_ci = {};
10298 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10299 sampler_ci.magFilter = VK_FILTER_NEAREST;
10300 sampler_ci.minFilter = VK_FILTER_NEAREST;
10301 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10302 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10303 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10304 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10305 sampler_ci.mipLodBias = 1.0;
10306 sampler_ci.maxAnisotropy = 1;
10307 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10308 sampler_ci.minLod = 1.0;
10309 sampler_ci.maxLod = 1.0;
10310 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10311
10312 VkSampler sampler;
10313 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10314 ASSERT_VK_SUCCESS(err);
10315
10316 VkDescriptorImageInfo info = {};
10317 info.sampler = sampler;
10318
10319 VkWriteDescriptorSet descriptor_write;
10320 memset(&descriptor_write, 0, sizeof(descriptor_write));
10321 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10322 descriptor_write.dstSet = descriptor_set;
10323 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010324 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010325 // This is the wrong type, but empty binding error will be flagged first
10326 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10327 descriptor_write.pImageInfo = &info;
10328
10329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10330 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10331 m_errorMonitor->VerifyFound();
10332
10333 vkDestroySampler(m_device->device(), sampler, NULL);
10334 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10335 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10336}
10337
Karl Schultz6addd812016-02-02 17:17:23 -070010338TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10339 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10340 // types
10341 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010342
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010343 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 -060010344
Tobin Ehlis3b780662015-05-28 12:11:26 -060010345 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010346
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010347 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010348 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10349 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010350
10351 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010352 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10353 ds_pool_ci.pNext = NULL;
10354 ds_pool_ci.maxSets = 1;
10355 ds_pool_ci.poolSizeCount = 1;
10356 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010357
Tobin Ehlis3b780662015-05-28 12:11:26 -060010358 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010359 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010360 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010361 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010362 dsl_binding.binding = 0;
10363 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10364 dsl_binding.descriptorCount = 1;
10365 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10366 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010367
Tony Barboureb254902015-07-15 12:50:33 -060010368 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010369 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10370 ds_layout_ci.pNext = NULL;
10371 ds_layout_ci.bindingCount = 1;
10372 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010373
Tobin Ehlis3b780662015-05-28 12:11:26 -060010374 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010375 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010376 ASSERT_VK_SUCCESS(err);
10377
10378 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010379 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010380 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010381 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010382 alloc_info.descriptorPool = ds_pool;
10383 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010384 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010385 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010386
Tony Barboureb254902015-07-15 12:50:33 -060010387 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010388 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10389 sampler_ci.pNext = NULL;
10390 sampler_ci.magFilter = VK_FILTER_NEAREST;
10391 sampler_ci.minFilter = VK_FILTER_NEAREST;
10392 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10393 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10394 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10395 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10396 sampler_ci.mipLodBias = 1.0;
10397 sampler_ci.anisotropyEnable = VK_FALSE;
10398 sampler_ci.maxAnisotropy = 1;
10399 sampler_ci.compareEnable = VK_FALSE;
10400 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10401 sampler_ci.minLod = 1.0;
10402 sampler_ci.maxLod = 1.0;
10403 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10404 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010405 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010406 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010407 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010408
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010409 VkDescriptorImageInfo info = {};
10410 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010411
10412 VkWriteDescriptorSet descriptor_write;
10413 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010414 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010415 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010416 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010417 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010418 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010419 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010420
10421 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10422
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010423 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010424
Chia-I Wuf7458c52015-10-26 21:10:41 +080010425 vkDestroySampler(m_device->device(), sampler, NULL);
10426 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10427 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010428}
10429
Karl Schultz6addd812016-02-02 17:17:23 -070010430TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010431 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010432 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010433
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010434 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010435
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010436 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010437 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10438 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010439 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010440 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10441 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010442
10443 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010444 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10445 ds_pool_ci.pNext = NULL;
10446 ds_pool_ci.maxSets = 1;
10447 ds_pool_ci.poolSizeCount = 1;
10448 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010449
10450 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010451 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010452 ASSERT_VK_SUCCESS(err);
10453
10454 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010455 dsl_binding.binding = 0;
10456 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10457 dsl_binding.descriptorCount = 1;
10458 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10459 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010460
10461 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010462 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10463 ds_layout_ci.pNext = NULL;
10464 ds_layout_ci.bindingCount = 1;
10465 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010466 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010467 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010468 ASSERT_VK_SUCCESS(err);
10469
10470 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010471 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010472 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010473 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010474 alloc_info.descriptorPool = ds_pool;
10475 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010476 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010477 ASSERT_VK_SUCCESS(err);
10478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010479 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010480
10481 VkDescriptorImageInfo descriptor_info;
10482 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10483 descriptor_info.sampler = sampler;
10484
10485 VkWriteDescriptorSet descriptor_write;
10486 memset(&descriptor_write, 0, sizeof(descriptor_write));
10487 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010488 descriptor_write.dstSet = descriptorSet;
10489 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010490 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010491 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10492 descriptor_write.pImageInfo = &descriptor_info;
10493
10494 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10495
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010496 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010497
Chia-I Wuf7458c52015-10-26 21:10:41 +080010498 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10499 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010500}
10501
Karl Schultz6addd812016-02-02 17:17:23 -070010502TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10503 // Create a single combined Image/Sampler descriptor and send it an invalid
10504 // imageView
10505 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010506
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010508
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010509 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010510 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010511 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10512 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010513
10514 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010515 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10516 ds_pool_ci.pNext = NULL;
10517 ds_pool_ci.maxSets = 1;
10518 ds_pool_ci.poolSizeCount = 1;
10519 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010520
10521 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010522 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010523 ASSERT_VK_SUCCESS(err);
10524
10525 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010526 dsl_binding.binding = 0;
10527 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10528 dsl_binding.descriptorCount = 1;
10529 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10530 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010531
10532 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010533 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10534 ds_layout_ci.pNext = NULL;
10535 ds_layout_ci.bindingCount = 1;
10536 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010537 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010538 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010539 ASSERT_VK_SUCCESS(err);
10540
10541 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010542 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010543 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010544 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010545 alloc_info.descriptorPool = ds_pool;
10546 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010547 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010548 ASSERT_VK_SUCCESS(err);
10549
10550 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010551 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10552 sampler_ci.pNext = NULL;
10553 sampler_ci.magFilter = VK_FILTER_NEAREST;
10554 sampler_ci.minFilter = VK_FILTER_NEAREST;
10555 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10556 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10557 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10558 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10559 sampler_ci.mipLodBias = 1.0;
10560 sampler_ci.anisotropyEnable = VK_FALSE;
10561 sampler_ci.maxAnisotropy = 1;
10562 sampler_ci.compareEnable = VK_FALSE;
10563 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10564 sampler_ci.minLod = 1.0;
10565 sampler_ci.maxLod = 1.0;
10566 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10567 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010568
10569 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010570 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010571 ASSERT_VK_SUCCESS(err);
10572
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010573 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010574
10575 VkDescriptorImageInfo descriptor_info;
10576 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10577 descriptor_info.sampler = sampler;
10578 descriptor_info.imageView = view;
10579
10580 VkWriteDescriptorSet descriptor_write;
10581 memset(&descriptor_write, 0, sizeof(descriptor_write));
10582 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010583 descriptor_write.dstSet = descriptorSet;
10584 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010585 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010586 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10587 descriptor_write.pImageInfo = &descriptor_info;
10588
10589 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10590
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010591 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010592
Chia-I Wuf7458c52015-10-26 21:10:41 +080010593 vkDestroySampler(m_device->device(), sampler, NULL);
10594 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10595 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010596}
10597
Karl Schultz6addd812016-02-02 17:17:23 -070010598TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10599 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10600 // into the other
10601 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010602
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010603 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10604 " binding #1 with type "
10605 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10606 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010607
Tobin Ehlis04356f92015-10-27 16:35:27 -060010608 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010609 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010610 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010611 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10612 ds_type_count[0].descriptorCount = 1;
10613 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10614 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010615
10616 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010617 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10618 ds_pool_ci.pNext = NULL;
10619 ds_pool_ci.maxSets = 1;
10620 ds_pool_ci.poolSizeCount = 2;
10621 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010622
10623 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010624 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010625 ASSERT_VK_SUCCESS(err);
10626 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010627 dsl_binding[0].binding = 0;
10628 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10629 dsl_binding[0].descriptorCount = 1;
10630 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10631 dsl_binding[0].pImmutableSamplers = NULL;
10632 dsl_binding[1].binding = 1;
10633 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10634 dsl_binding[1].descriptorCount = 1;
10635 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10636 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010637
10638 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010639 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10640 ds_layout_ci.pNext = NULL;
10641 ds_layout_ci.bindingCount = 2;
10642 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010643
10644 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010646 ASSERT_VK_SUCCESS(err);
10647
10648 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010649 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010650 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010651 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010652 alloc_info.descriptorPool = ds_pool;
10653 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010655 ASSERT_VK_SUCCESS(err);
10656
10657 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010658 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10659 sampler_ci.pNext = NULL;
10660 sampler_ci.magFilter = VK_FILTER_NEAREST;
10661 sampler_ci.minFilter = VK_FILTER_NEAREST;
10662 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10663 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10664 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10665 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10666 sampler_ci.mipLodBias = 1.0;
10667 sampler_ci.anisotropyEnable = VK_FALSE;
10668 sampler_ci.maxAnisotropy = 1;
10669 sampler_ci.compareEnable = VK_FALSE;
10670 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10671 sampler_ci.minLod = 1.0;
10672 sampler_ci.maxLod = 1.0;
10673 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10674 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010675
10676 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010677 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010678 ASSERT_VK_SUCCESS(err);
10679
10680 VkDescriptorImageInfo info = {};
10681 info.sampler = sampler;
10682
10683 VkWriteDescriptorSet descriptor_write;
10684 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10685 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010686 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010687 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010688 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010689 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10690 descriptor_write.pImageInfo = &info;
10691 // This write update should succeed
10692 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10693 // Now perform a copy update that fails due to type mismatch
10694 VkCopyDescriptorSet copy_ds_update;
10695 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10696 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10697 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010698 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010699 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010700 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10701 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010702 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10703
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010704 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010705 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010706 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 -060010707 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10708 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10709 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010710 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010711 copy_ds_update.dstSet = descriptorSet;
10712 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010713 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010714 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10715
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010716 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010717
Tobin Ehlis04356f92015-10-27 16:35:27 -060010718 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10720 " binding#1 with offset index of 1 plus "
10721 "update array offset of 0 and update of "
10722 "5 descriptors oversteps total number "
10723 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010724
Tobin Ehlis04356f92015-10-27 16:35:27 -060010725 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10726 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10727 copy_ds_update.srcSet = descriptorSet;
10728 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010729 copy_ds_update.dstSet = descriptorSet;
10730 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010731 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010732 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10733
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010734 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010735
Chia-I Wuf7458c52015-10-26 21:10:41 +080010736 vkDestroySampler(m_device->device(), sampler, NULL);
10737 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10738 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010739}
10740
Karl Schultz6addd812016-02-02 17:17:23 -070010741TEST_F(VkLayerTest, NumSamplesMismatch) {
10742 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10743 // sampleCount
10744 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010745
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010746 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010747
Tobin Ehlis3b780662015-05-28 12:11:26 -060010748 ASSERT_NO_FATAL_FAILURE(InitState());
10749 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010750 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010751 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010752 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010753
10754 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010755 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10756 ds_pool_ci.pNext = NULL;
10757 ds_pool_ci.maxSets = 1;
10758 ds_pool_ci.poolSizeCount = 1;
10759 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010760
Tobin Ehlis3b780662015-05-28 12:11:26 -060010761 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010762 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010763 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010764
Tony Barboureb254902015-07-15 12:50:33 -060010765 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010766 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010767 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010768 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010769 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10770 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010771
Tony Barboureb254902015-07-15 12:50:33 -060010772 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10773 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10774 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010775 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010776 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010777
Tobin Ehlis3b780662015-05-28 12:11:26 -060010778 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010779 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010780 ASSERT_VK_SUCCESS(err);
10781
10782 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010783 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010784 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010785 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010786 alloc_info.descriptorPool = ds_pool;
10787 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010788 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010789 ASSERT_VK_SUCCESS(err);
10790
Tony Barboureb254902015-07-15 12:50:33 -060010791 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010792 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010793 pipe_ms_state_ci.pNext = NULL;
10794 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10795 pipe_ms_state_ci.sampleShadingEnable = 0;
10796 pipe_ms_state_ci.minSampleShading = 1.0;
10797 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010798
Tony Barboureb254902015-07-15 12:50:33 -060010799 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010800 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10801 pipeline_layout_ci.pNext = NULL;
10802 pipeline_layout_ci.setLayoutCount = 1;
10803 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010804
10805 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010806 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010807 ASSERT_VK_SUCCESS(err);
10808
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010809 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010810 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 -060010811 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010812 VkPipelineObj pipe(m_device);
10813 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010814 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010815 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010816 pipe.SetMSAA(&pipe_ms_state_ci);
10817 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010818
Tony Barbour552f6c02016-12-21 14:34:07 -070010819 m_commandBuffer->BeginCommandBuffer();
10820 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010821 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010822
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010823 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10824 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10825 VkRect2D scissor = {{0, 0}, {16, 16}};
10826 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10827
Mark Young29927482016-05-04 14:38:51 -060010828 // Render triangle (the error should trigger on the attempt to draw).
10829 Draw(3, 1, 0, 0);
10830
10831 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010832 m_commandBuffer->EndRenderPass();
10833 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010834
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010835 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010836
Chia-I Wuf7458c52015-10-26 21:10:41 +080010837 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10838 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10839 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010840}
Mark Young29927482016-05-04 14:38:51 -060010841
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010842TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010843 TEST_DESCRIPTION(
10844 "Hit RenderPass incompatible cases. "
10845 "Initial case is drawing with an active renderpass that's "
10846 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010847 VkResult err;
10848
10849 ASSERT_NO_FATAL_FAILURE(InitState());
10850 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10851
10852 VkDescriptorSetLayoutBinding dsl_binding = {};
10853 dsl_binding.binding = 0;
10854 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10855 dsl_binding.descriptorCount = 1;
10856 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10857 dsl_binding.pImmutableSamplers = NULL;
10858
10859 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10860 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10861 ds_layout_ci.pNext = NULL;
10862 ds_layout_ci.bindingCount = 1;
10863 ds_layout_ci.pBindings = &dsl_binding;
10864
10865 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010867 ASSERT_VK_SUCCESS(err);
10868
10869 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10870 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10871 pipeline_layout_ci.pNext = NULL;
10872 pipeline_layout_ci.setLayoutCount = 1;
10873 pipeline_layout_ci.pSetLayouts = &ds_layout;
10874
10875 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010876 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010877 ASSERT_VK_SUCCESS(err);
10878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010879 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010880 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 -060010881 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010882 // Create a renderpass that will be incompatible with default renderpass
10883 VkAttachmentReference attach = {};
10884 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10885 VkAttachmentReference color_att = {};
10886 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10887 VkSubpassDescription subpass = {};
10888 subpass.inputAttachmentCount = 1;
10889 subpass.pInputAttachments = &attach;
10890 subpass.colorAttachmentCount = 1;
10891 subpass.pColorAttachments = &color_att;
10892 VkRenderPassCreateInfo rpci = {};
10893 rpci.subpassCount = 1;
10894 rpci.pSubpasses = &subpass;
10895 rpci.attachmentCount = 1;
10896 VkAttachmentDescription attach_desc = {};
10897 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010898 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10899 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010900 rpci.pAttachments = &attach_desc;
10901 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10902 VkRenderPass rp;
10903 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10904 VkPipelineObj pipe(m_device);
10905 pipe.AddShader(&vs);
10906 pipe.AddShader(&fs);
10907 pipe.AddColorAttachment();
10908 VkViewport view_port = {};
10909 m_viewports.push_back(view_port);
10910 pipe.SetViewport(m_viewports);
10911 VkRect2D rect = {};
10912 m_scissors.push_back(rect);
10913 pipe.SetScissor(m_scissors);
10914 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10915
10916 VkCommandBufferInheritanceInfo cbii = {};
10917 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10918 cbii.renderPass = rp;
10919 cbii.subpass = 0;
10920 VkCommandBufferBeginInfo cbbi = {};
10921 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10922 cbbi.pInheritanceInfo = &cbii;
10923 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10924 VkRenderPassBeginInfo rpbi = {};
10925 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10926 rpbi.framebuffer = m_framebuffer;
10927 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010928 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10929 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010930
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010931 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010932 // Render triangle (the error should trigger on the attempt to draw).
10933 Draw(3, 1, 0, 0);
10934
10935 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010936 m_commandBuffer->EndRenderPass();
10937 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010938
10939 m_errorMonitor->VerifyFound();
10940
10941 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10942 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10943 vkDestroyRenderPass(m_device->device(), rp, NULL);
10944}
10945
Mark Youngc89c6312016-03-31 16:03:20 -060010946TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10947 // Create Pipeline where the number of blend attachments doesn't match the
10948 // number of color attachments. In this case, we don't add any color
10949 // blend attachments even though we have a color attachment.
10950 VkResult err;
10951
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010953
10954 ASSERT_NO_FATAL_FAILURE(InitState());
10955 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10956 VkDescriptorPoolSize ds_type_count = {};
10957 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10958 ds_type_count.descriptorCount = 1;
10959
10960 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10961 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10962 ds_pool_ci.pNext = NULL;
10963 ds_pool_ci.maxSets = 1;
10964 ds_pool_ci.poolSizeCount = 1;
10965 ds_pool_ci.pPoolSizes = &ds_type_count;
10966
10967 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010968 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010969 ASSERT_VK_SUCCESS(err);
10970
10971 VkDescriptorSetLayoutBinding dsl_binding = {};
10972 dsl_binding.binding = 0;
10973 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10974 dsl_binding.descriptorCount = 1;
10975 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10976 dsl_binding.pImmutableSamplers = NULL;
10977
10978 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10979 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10980 ds_layout_ci.pNext = NULL;
10981 ds_layout_ci.bindingCount = 1;
10982 ds_layout_ci.pBindings = &dsl_binding;
10983
10984 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010985 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010986 ASSERT_VK_SUCCESS(err);
10987
10988 VkDescriptorSet descriptorSet;
10989 VkDescriptorSetAllocateInfo alloc_info = {};
10990 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10991 alloc_info.descriptorSetCount = 1;
10992 alloc_info.descriptorPool = ds_pool;
10993 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010994 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060010995 ASSERT_VK_SUCCESS(err);
10996
10997 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010998 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060010999 pipe_ms_state_ci.pNext = NULL;
11000 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11001 pipe_ms_state_ci.sampleShadingEnable = 0;
11002 pipe_ms_state_ci.minSampleShading = 1.0;
11003 pipe_ms_state_ci.pSampleMask = NULL;
11004
11005 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11006 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11007 pipeline_layout_ci.pNext = NULL;
11008 pipeline_layout_ci.setLayoutCount = 1;
11009 pipeline_layout_ci.pSetLayouts = &ds_layout;
11010
11011 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011012 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011013 ASSERT_VK_SUCCESS(err);
11014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011015 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011016 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 -060011017 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011018 VkPipelineObj pipe(m_device);
11019 pipe.AddShader(&vs);
11020 pipe.AddShader(&fs);
11021 pipe.SetMSAA(&pipe_ms_state_ci);
11022 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011023 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011024
11025 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11026 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11027 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11028}
Mark Young29927482016-05-04 14:38:51 -060011029
Mark Muellerd4914412016-06-13 17:52:06 -060011030TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011031 TEST_DESCRIPTION(
11032 "Points to a wrong colorAttachment index in a VkClearAttachment "
11033 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011034 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011036
11037 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11038 m_errorMonitor->VerifyFound();
11039}
11040
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011041TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011042 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11043 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011044
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011045 ASSERT_NO_FATAL_FAILURE(InitState());
11046 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011047
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011048 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011049 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11050 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011051
11052 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011053 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11054 ds_pool_ci.pNext = NULL;
11055 ds_pool_ci.maxSets = 1;
11056 ds_pool_ci.poolSizeCount = 1;
11057 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011058
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011059 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011060 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011061 ASSERT_VK_SUCCESS(err);
11062
Tony Barboureb254902015-07-15 12:50:33 -060011063 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011064 dsl_binding.binding = 0;
11065 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11066 dsl_binding.descriptorCount = 1;
11067 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11068 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011069
Tony Barboureb254902015-07-15 12:50:33 -060011070 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011071 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11072 ds_layout_ci.pNext = NULL;
11073 ds_layout_ci.bindingCount = 1;
11074 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011075
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011076 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011077 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011078 ASSERT_VK_SUCCESS(err);
11079
11080 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011081 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011082 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011083 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011084 alloc_info.descriptorPool = ds_pool;
11085 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011086 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011087 ASSERT_VK_SUCCESS(err);
11088
Tony Barboureb254902015-07-15 12:50:33 -060011089 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011090 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011091 pipe_ms_state_ci.pNext = NULL;
11092 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11093 pipe_ms_state_ci.sampleShadingEnable = 0;
11094 pipe_ms_state_ci.minSampleShading = 1.0;
11095 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011096
Tony Barboureb254902015-07-15 12:50:33 -060011097 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011098 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11099 pipeline_layout_ci.pNext = NULL;
11100 pipeline_layout_ci.setLayoutCount = 1;
11101 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011102
11103 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011104 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011105 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011107 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011108 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011109 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011110 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011111
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011112 VkPipelineObj pipe(m_device);
11113 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011114 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011115 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011116 m_errorMonitor->SetUnexpectedError(
11117 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11118 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011119 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011120
Tony Barbour552f6c02016-12-21 14:34:07 -070011121 m_commandBuffer->BeginCommandBuffer();
11122 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011123
Karl Schultz6addd812016-02-02 17:17:23 -070011124 // Main thing we care about for this test is that the VkImage obj we're
11125 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011126 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011127 VkClearAttachment color_attachment;
11128 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11129 color_attachment.clearValue.color.float32[0] = 1.0;
11130 color_attachment.clearValue.color.float32[1] = 1.0;
11131 color_attachment.clearValue.color.float32[2] = 1.0;
11132 color_attachment.clearValue.color.float32[3] = 1.0;
11133 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011135
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011136 // Call for full-sized FB Color attachment prior to issuing a Draw
11137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011138 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011139 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011140 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011141
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011142 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11143 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11144 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11145 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11146 m_errorMonitor->VerifyFound();
11147
11148 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11149 clear_rect.layerCount = 2;
11150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11151 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011152 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011153
Chia-I Wuf7458c52015-10-26 21:10:41 +080011154 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11155 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11156 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011157}
11158
Karl Schultz6addd812016-02-02 17:17:23 -070011159TEST_F(VkLayerTest, VtxBufferBadIndex) {
11160 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11163 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011164
Tobin Ehlis502480b2015-06-24 15:53:07 -060011165 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011166 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011168
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011169 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011170 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11171 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011172
11173 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011174 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11175 ds_pool_ci.pNext = NULL;
11176 ds_pool_ci.maxSets = 1;
11177 ds_pool_ci.poolSizeCount = 1;
11178 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011179
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011180 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011181 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011182 ASSERT_VK_SUCCESS(err);
11183
Tony Barboureb254902015-07-15 12:50:33 -060011184 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011185 dsl_binding.binding = 0;
11186 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11187 dsl_binding.descriptorCount = 1;
11188 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11189 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011190
Tony Barboureb254902015-07-15 12:50:33 -060011191 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011192 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11193 ds_layout_ci.pNext = NULL;
11194 ds_layout_ci.bindingCount = 1;
11195 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011196
Tobin Ehlis502480b2015-06-24 15:53:07 -060011197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011199 ASSERT_VK_SUCCESS(err);
11200
11201 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011202 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011204 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011205 alloc_info.descriptorPool = ds_pool;
11206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011208 ASSERT_VK_SUCCESS(err);
11209
Tony Barboureb254902015-07-15 12:50:33 -060011210 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011212 pipe_ms_state_ci.pNext = NULL;
11213 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11214 pipe_ms_state_ci.sampleShadingEnable = 0;
11215 pipe_ms_state_ci.minSampleShading = 1.0;
11216 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011217
Tony Barboureb254902015-07-15 12:50:33 -060011218 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011219 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11220 pipeline_layout_ci.pNext = NULL;
11221 pipeline_layout_ci.setLayoutCount = 1;
11222 pipeline_layout_ci.pSetLayouts = &ds_layout;
11223 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011224
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011225 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011226 ASSERT_VK_SUCCESS(err);
11227
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011228 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011229 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 -060011230 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011231 VkPipelineObj pipe(m_device);
11232 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011233 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011234 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011235 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011236 pipe.SetViewport(m_viewports);
11237 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011238 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011239
Tony Barbour552f6c02016-12-21 14:34:07 -070011240 m_commandBuffer->BeginCommandBuffer();
11241 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011242 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011243 // Don't care about actual data, just need to get to draw to flag error
11244 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011245 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011246 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011247 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011248
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011249 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011250
Chia-I Wuf7458c52015-10-26 21:10:41 +080011251 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11252 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11253 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011254}
Mark Muellerdfe37552016-07-07 14:47:42 -060011255
Mark Mueller2ee294f2016-08-04 12:59:48 -060011256TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011257 TEST_DESCRIPTION(
11258 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11259 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011260 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011261
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011262 const char *invalid_queueFamilyIndex_message =
11263 "Invalid queue create request in vkCreateDevice(). Invalid "
11264 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011266 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011267
Mark Mueller880fce52016-08-17 15:23:23 -060011268 // The following test fails with recent NVidia drivers.
11269 // By the time core_validation is reached, the NVidia
11270 // driver has sanitized the invalid condition and core_validation
11271 // is not introduced to the failure condition. This is not the case
11272 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011273 // uint32_t count = static_cast<uint32_t>(~0);
11274 // VkPhysicalDevice physical_device;
11275 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11276 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011277
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011279 float queue_priority = 0.0;
11280
11281 VkDeviceQueueCreateInfo queue_create_info = {};
11282 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11283 queue_create_info.queueCount = 1;
11284 queue_create_info.pQueuePriorities = &queue_priority;
11285 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11286
11287 VkPhysicalDeviceFeatures features = m_device->phy().features();
11288 VkDevice testDevice;
11289 VkDeviceCreateInfo device_create_info = {};
11290 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11291 device_create_info.queueCreateInfoCount = 1;
11292 device_create_info.pQueueCreateInfos = &queue_create_info;
11293 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011294 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011295 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11296 m_errorMonitor->VerifyFound();
11297
11298 queue_create_info.queueFamilyIndex = 1;
11299
11300 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11301 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11302 for (unsigned i = 0; i < feature_count; i++) {
11303 if (VK_FALSE == feature_array[i]) {
11304 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011306 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011307 m_errorMonitor->SetUnexpectedError(
11308 "You requested features that are unavailable on this device. You should first query feature availability by "
11309 "calling vkGetPhysicalDeviceFeatures().");
11310 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011311 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11312 m_errorMonitor->VerifyFound();
11313 break;
11314 }
11315 }
11316}
11317
Tobin Ehlis16edf082016-11-21 12:33:49 -070011318TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11319 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11320
11321 ASSERT_NO_FATAL_FAILURE(InitState());
11322
11323 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11324 std::vector<VkDeviceQueueCreateInfo> queue_info;
11325 queue_info.reserve(queue_props.size());
11326 std::vector<std::vector<float>> queue_priorities;
11327 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11328 VkDeviceQueueCreateInfo qi{};
11329 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11330 qi.queueFamilyIndex = i;
11331 qi.queueCount = queue_props[i].queueCount;
11332 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11333 qi.pQueuePriorities = queue_priorities[i].data();
11334 queue_info.push_back(qi);
11335 }
11336
11337 std::vector<const char *> device_extension_names;
11338
11339 VkDevice local_device;
11340 VkDeviceCreateInfo device_create_info = {};
11341 auto features = m_device->phy().features();
11342 // Intentionally disable pipeline stats
11343 features.pipelineStatisticsQuery = VK_FALSE;
11344 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11345 device_create_info.pNext = NULL;
11346 device_create_info.queueCreateInfoCount = queue_info.size();
11347 device_create_info.pQueueCreateInfos = queue_info.data();
11348 device_create_info.enabledLayerCount = 0;
11349 device_create_info.ppEnabledLayerNames = NULL;
11350 device_create_info.pEnabledFeatures = &features;
11351 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11352 ASSERT_VK_SUCCESS(err);
11353
11354 VkQueryPoolCreateInfo qpci{};
11355 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11356 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11357 qpci.queryCount = 1;
11358 VkQueryPool query_pool;
11359
11360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11361 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11362 m_errorMonitor->VerifyFound();
11363
11364 vkDestroyDevice(local_device, nullptr);
11365}
11366
Mark Mueller2ee294f2016-08-04 12:59:48 -060011367TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011368 TEST_DESCRIPTION(
11369 "Use an invalid queue index in a vkCmdWaitEvents call."
11370 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011371
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011372 const char *invalid_queue_index =
11373 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11374 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11375 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011376
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011377 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011378
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011380
11381 ASSERT_NO_FATAL_FAILURE(InitState());
11382
11383 VkEvent event;
11384 VkEventCreateInfo event_create_info{};
11385 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11386 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11387
Mark Mueller2ee294f2016-08-04 12:59:48 -060011388 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011389 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011390
Tony Barbour552f6c02016-12-21 14:34:07 -070011391 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011392
11393 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011394 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 -060011395 ASSERT_TRUE(image.initialized());
11396 VkImageMemoryBarrier img_barrier = {};
11397 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11398 img_barrier.pNext = NULL;
11399 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11400 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11401 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11402 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11403 img_barrier.image = image.handle();
11404 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011405
11406 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11407 // that layer validation catches the case when it is not.
11408 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011409 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11410 img_barrier.subresourceRange.baseArrayLayer = 0;
11411 img_barrier.subresourceRange.baseMipLevel = 0;
11412 img_barrier.subresourceRange.layerCount = 1;
11413 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011414 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11415 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011416 m_errorMonitor->VerifyFound();
11417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011419
11420 VkQueryPool query_pool;
11421 VkQueryPoolCreateInfo query_pool_create_info = {};
11422 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11423 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11424 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011425 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011426
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011427 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011428 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11429
11430 vkEndCommandBuffer(m_commandBuffer->handle());
11431 m_errorMonitor->VerifyFound();
11432
11433 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11434 vkDestroyEvent(m_device->device(), event, nullptr);
11435}
11436
Mark Muellerdfe37552016-07-07 14:47:42 -060011437TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011438 TEST_DESCRIPTION(
11439 "Submit a command buffer using deleted vertex buffer, "
11440 "delete a buffer twice, use an invalid offset for each "
11441 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011442
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011443 const char *deleted_buffer_in_command_buffer =
11444 "Cannot submit cmd buffer "
11445 "using deleted buffer ";
11446 const char *invalid_offset_message =
11447 "vkBindBufferMemory(): "
11448 "memoryOffset is 0x";
11449 const char *invalid_storage_buffer_offset_message =
11450 "vkBindBufferMemory(): "
11451 "storage memoryOffset "
11452 "is 0x";
11453 const char *invalid_texel_buffer_offset_message =
11454 "vkBindBufferMemory(): "
11455 "texel memoryOffset "
11456 "is 0x";
11457 const char *invalid_uniform_buffer_offset_message =
11458 "vkBindBufferMemory(): "
11459 "uniform memoryOffset "
11460 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011461
11462 ASSERT_NO_FATAL_FAILURE(InitState());
11463 ASSERT_NO_FATAL_FAILURE(InitViewport());
11464 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11465
11466 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011467 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011468 pipe_ms_state_ci.pNext = NULL;
11469 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11470 pipe_ms_state_ci.sampleShadingEnable = 0;
11471 pipe_ms_state_ci.minSampleShading = 1.0;
11472 pipe_ms_state_ci.pSampleMask = nullptr;
11473
11474 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11475 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11476 VkPipelineLayout pipeline_layout;
11477
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011478 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011479 ASSERT_VK_SUCCESS(err);
11480
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011481 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11482 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011483 VkPipelineObj pipe(m_device);
11484 pipe.AddShader(&vs);
11485 pipe.AddShader(&fs);
11486 pipe.AddColorAttachment();
11487 pipe.SetMSAA(&pipe_ms_state_ci);
11488 pipe.SetViewport(m_viewports);
11489 pipe.SetScissor(m_scissors);
11490 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11491
Tony Barbour552f6c02016-12-21 14:34:07 -070011492 m_commandBuffer->BeginCommandBuffer();
11493 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011494 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011495
11496 {
11497 // Create and bind a vertex buffer in a reduced scope, which will cause
11498 // it to be deleted upon leaving this scope
11499 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011500 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011501 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11502 draw_verticies.AddVertexInputToPipe(pipe);
11503 }
11504
11505 Draw(1, 0, 0, 0);
11506
Tony Barbour552f6c02016-12-21 14:34:07 -070011507 m_commandBuffer->EndRenderPass();
11508 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011509
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011510 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011511 QueueCommandBuffer(false);
11512 m_errorMonitor->VerifyFound();
11513
11514 {
11515 // Create and bind a vertex buffer in a reduced scope, and delete it
11516 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011517 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011519 buffer_test.TestDoubleDestroy();
11520 }
11521 m_errorMonitor->VerifyFound();
11522
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011523 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011524 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011525 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011527 m_errorMonitor->SetUnexpectedError(
11528 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11529 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11531 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011532 m_errorMonitor->VerifyFound();
11533 }
11534
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11536 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011537 // Create and bind a memory buffer with an invalid offset again,
11538 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011540 m_errorMonitor->SetUnexpectedError(
11541 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11542 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11544 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011545 m_errorMonitor->VerifyFound();
11546 }
11547
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011548 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011549 // Create and bind a memory buffer with an invalid offset again, but
11550 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011552 m_errorMonitor->SetUnexpectedError(
11553 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11554 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011555 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11556 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011557 m_errorMonitor->VerifyFound();
11558 }
11559
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011560 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011561 // Create and bind a memory buffer with an invalid offset again, but
11562 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011563 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011564 m_errorMonitor->SetUnexpectedError(
11565 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11566 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011567 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11568 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011569 m_errorMonitor->VerifyFound();
11570 }
11571
11572 {
11573 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011575 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11576 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011577 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11578 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011579 m_errorMonitor->VerifyFound();
11580 }
11581
11582 {
11583 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011585 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11586 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011587 }
11588 m_errorMonitor->VerifyFound();
11589
11590 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11591}
11592
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011593// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11594TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011595 TEST_DESCRIPTION(
11596 "Hit all possible validation checks associated with the "
11597 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11598 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011599 // 3 in ValidateCmdBufImageLayouts
11600 // * -1 Attempt to submit cmd buf w/ deleted image
11601 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11602 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011603
11604 ASSERT_NO_FATAL_FAILURE(InitState());
11605 // Create src & dst images to use for copy operations
11606 VkImage src_image;
11607 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011608 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011609
11610 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11611 const int32_t tex_width = 32;
11612 const int32_t tex_height = 32;
11613
11614 VkImageCreateInfo image_create_info = {};
11615 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11616 image_create_info.pNext = NULL;
11617 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11618 image_create_info.format = tex_format;
11619 image_create_info.extent.width = tex_width;
11620 image_create_info.extent.height = tex_height;
11621 image_create_info.extent.depth = 1;
11622 image_create_info.mipLevels = 1;
11623 image_create_info.arrayLayers = 4;
11624 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11625 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11626 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011627 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011628 image_create_info.flags = 0;
11629
11630 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11631 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011632 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011633 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11634 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011635 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11636 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11637 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11638 ASSERT_VK_SUCCESS(err);
11639
11640 // Allocate memory
11641 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011642 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011643 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011644 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11645 mem_alloc.pNext = NULL;
11646 mem_alloc.allocationSize = 0;
11647 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011648
11649 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011650 mem_alloc.allocationSize = img_mem_reqs.size;
11651 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011652 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011653 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011654 ASSERT_VK_SUCCESS(err);
11655
11656 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011657 mem_alloc.allocationSize = img_mem_reqs.size;
11658 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011659 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011660 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011661 ASSERT_VK_SUCCESS(err);
11662
11663 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011664 mem_alloc.allocationSize = img_mem_reqs.size;
11665 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011666 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011667 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011668 ASSERT_VK_SUCCESS(err);
11669
11670 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11671 ASSERT_VK_SUCCESS(err);
11672 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11673 ASSERT_VK_SUCCESS(err);
11674 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11675 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011676
Tony Barbour552f6c02016-12-21 14:34:07 -070011677 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011678 VkImageCopy copy_region;
11679 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11680 copy_region.srcSubresource.mipLevel = 0;
11681 copy_region.srcSubresource.baseArrayLayer = 0;
11682 copy_region.srcSubresource.layerCount = 1;
11683 copy_region.srcOffset.x = 0;
11684 copy_region.srcOffset.y = 0;
11685 copy_region.srcOffset.z = 0;
11686 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11687 copy_region.dstSubresource.mipLevel = 0;
11688 copy_region.dstSubresource.baseArrayLayer = 0;
11689 copy_region.dstSubresource.layerCount = 1;
11690 copy_region.dstOffset.x = 0;
11691 copy_region.dstOffset.y = 0;
11692 copy_region.dstOffset.z = 0;
11693 copy_region.extent.width = 1;
11694 copy_region.extent.height = 1;
11695 copy_region.extent.depth = 1;
11696
11697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11698 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011699 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011700 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 -060011701 m_errorMonitor->VerifyFound();
11702 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11704 "Cannot copy from an image whose source layout is "
11705 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11706 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011707 m_errorMonitor->SetUnexpectedError(
11708 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011709 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 -060011710 m_errorMonitor->VerifyFound();
11711 // Final src error is due to bad layout type
11712 m_errorMonitor->SetDesiredFailureMsg(
11713 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11714 "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 -070011715 m_errorMonitor->SetUnexpectedError(
11716 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11717 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011718 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 -060011719 m_errorMonitor->VerifyFound();
11720 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11722 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011723 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011724 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 -060011725 m_errorMonitor->VerifyFound();
11726 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011727 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11728 "Cannot copy from an image whose dest layout is "
11729 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11730 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011731 m_errorMonitor->SetUnexpectedError(
11732 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011733 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 -060011734 m_errorMonitor->VerifyFound();
11735 m_errorMonitor->SetDesiredFailureMsg(
11736 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11737 "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 -070011738 m_errorMonitor->SetUnexpectedError(
11739 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11740 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011741 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 -060011742 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011743
Cort3b021012016-12-07 12:00:57 -080011744 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11745 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11746 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11747 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11748 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11749 transfer_dst_image_barrier[0].srcAccessMask = 0;
11750 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11751 transfer_dst_image_barrier[0].image = dst_image;
11752 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11753 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11754 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11755 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11756 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11757 transfer_dst_image_barrier[0].image = depth_image;
11758 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11759 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11760 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11761
11762 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011763 VkClearColorValue color_clear_value = {};
11764 VkImageSubresourceRange clear_range;
11765 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11766 clear_range.baseMipLevel = 0;
11767 clear_range.baseArrayLayer = 0;
11768 clear_range.layerCount = 1;
11769 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011770
Cort3b021012016-12-07 12:00:57 -080011771 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11772 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11774 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011775 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011776 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011777 // Fail due to provided layout not matching actual current layout for color clear.
11778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011779 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011780 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011781
Cort530cf382016-12-08 09:59:47 -080011782 VkClearDepthStencilValue depth_clear_value = {};
11783 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011784
11785 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11786 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011789 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011790 m_errorMonitor->VerifyFound();
11791 // Fail due to provided layout not matching actual current layout for depth clear.
11792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011793 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011794 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011795
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011796 // Now cause error due to bad image layout transition in PipelineBarrier
11797 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011798 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011799 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011800 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011801 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011802 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11803 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011804 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011805 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11806 "You cannot transition the layout of aspect 1 from "
11807 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11808 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011809 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11810 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011811 m_errorMonitor->VerifyFound();
11812
11813 // Finally some layout errors at RenderPass create time
11814 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11815 VkAttachmentReference attach = {};
11816 // perf warning for GENERAL layout w/ non-DS input attachment
11817 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11818 VkSubpassDescription subpass = {};
11819 subpass.inputAttachmentCount = 1;
11820 subpass.pInputAttachments = &attach;
11821 VkRenderPassCreateInfo rpci = {};
11822 rpci.subpassCount = 1;
11823 rpci.pSubpasses = &subpass;
11824 rpci.attachmentCount = 1;
11825 VkAttachmentDescription attach_desc = {};
11826 attach_desc.format = VK_FORMAT_UNDEFINED;
11827 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011828 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011829 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11831 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011832 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11833 m_errorMonitor->VerifyFound();
11834 // error w/ non-general layout
11835 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11836
11837 m_errorMonitor->SetDesiredFailureMsg(
11838 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11839 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11840 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11841 m_errorMonitor->VerifyFound();
11842 subpass.inputAttachmentCount = 0;
11843 subpass.colorAttachmentCount = 1;
11844 subpass.pColorAttachments = &attach;
11845 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11846 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11848 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011849 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11850 m_errorMonitor->VerifyFound();
11851 // error w/ non-color opt or GENERAL layout for color attachment
11852 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11853 m_errorMonitor->SetDesiredFailureMsg(
11854 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11855 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11856 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11857 m_errorMonitor->VerifyFound();
11858 subpass.colorAttachmentCount = 0;
11859 subpass.pDepthStencilAttachment = &attach;
11860 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11861 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11863 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011864 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11865 m_errorMonitor->VerifyFound();
11866 // error w/ non-ds opt or GENERAL layout for color attachment
11867 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011868 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11869 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11870 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011871 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11872 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011873 // For this error we need a valid renderpass so create default one
11874 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11875 attach.attachment = 0;
11876 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11877 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11878 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11879 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11880 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11881 // Can't do a CLEAR load on READ_ONLY initialLayout
11882 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11883 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11884 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11886 " with invalid first layout "
11887 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11888 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011889 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11890 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011891
Cort3b021012016-12-07 12:00:57 -080011892 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11893 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11894 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011895 vkDestroyImage(m_device->device(), src_image, NULL);
11896 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011897 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011898}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011899
Tobin Ehlise0936662016-10-11 08:10:51 -060011900TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11901 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11902 VkResult err;
11903
11904 ASSERT_NO_FATAL_FAILURE(InitState());
11905
11906 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11907 VkImageTiling tiling;
11908 VkFormatProperties format_properties;
11909 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11910 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11911 tiling = VK_IMAGE_TILING_LINEAR;
11912 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11913 tiling = VK_IMAGE_TILING_OPTIMAL;
11914 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011915 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011916 return;
11917 }
11918
11919 VkDescriptorPoolSize ds_type = {};
11920 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11921 ds_type.descriptorCount = 1;
11922
11923 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11924 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11925 ds_pool_ci.maxSets = 1;
11926 ds_pool_ci.poolSizeCount = 1;
11927 ds_pool_ci.pPoolSizes = &ds_type;
11928 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11929
11930 VkDescriptorPool ds_pool;
11931 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11932 ASSERT_VK_SUCCESS(err);
11933
11934 VkDescriptorSetLayoutBinding dsl_binding = {};
11935 dsl_binding.binding = 0;
11936 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11937 dsl_binding.descriptorCount = 1;
11938 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11939 dsl_binding.pImmutableSamplers = NULL;
11940
11941 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11942 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11943 ds_layout_ci.pNext = NULL;
11944 ds_layout_ci.bindingCount = 1;
11945 ds_layout_ci.pBindings = &dsl_binding;
11946
11947 VkDescriptorSetLayout ds_layout;
11948 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11949 ASSERT_VK_SUCCESS(err);
11950
11951 VkDescriptorSetAllocateInfo alloc_info = {};
11952 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11953 alloc_info.descriptorSetCount = 1;
11954 alloc_info.descriptorPool = ds_pool;
11955 alloc_info.pSetLayouts = &ds_layout;
11956 VkDescriptorSet descriptor_set;
11957 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11958 ASSERT_VK_SUCCESS(err);
11959
11960 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11961 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11962 pipeline_layout_ci.pNext = NULL;
11963 pipeline_layout_ci.setLayoutCount = 1;
11964 pipeline_layout_ci.pSetLayouts = &ds_layout;
11965 VkPipelineLayout pipeline_layout;
11966 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11967 ASSERT_VK_SUCCESS(err);
11968
11969 VkImageObj image(m_device);
11970 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11971 ASSERT_TRUE(image.initialized());
11972 VkImageView view = image.targetView(tex_format);
11973
11974 VkDescriptorImageInfo image_info = {};
11975 image_info.imageView = view;
11976 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11977
11978 VkWriteDescriptorSet descriptor_write = {};
11979 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11980 descriptor_write.dstSet = descriptor_set;
11981 descriptor_write.dstBinding = 0;
11982 descriptor_write.descriptorCount = 1;
11983 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11984 descriptor_write.pImageInfo = &image_info;
11985
11986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11987 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11988 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
11989 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
11990 m_errorMonitor->VerifyFound();
11991
11992 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11994 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
11995 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11996}
11997
Mark Mueller93b938f2016-08-18 10:27:40 -060011998TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011999 TEST_DESCRIPTION(
12000 "Use vkCmdExecuteCommands with invalid state "
12001 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012002
12003 ASSERT_NO_FATAL_FAILURE(InitState());
12004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12005
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012006 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012007 const char *simultaneous_use_message2 =
12008 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12009 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012010
12011 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012012 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012013 command_buffer_allocate_info.commandPool = m_commandPool;
12014 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12015 command_buffer_allocate_info.commandBufferCount = 1;
12016
12017 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012018 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012019 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12020 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012021 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012022 command_buffer_inheritance_info.renderPass = m_renderPass;
12023 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012024
Mark Mueller93b938f2016-08-18 10:27:40 -060012025 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012026 command_buffer_begin_info.flags =
12027 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012028 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12029
12030 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12031 vkEndCommandBuffer(secondary_command_buffer);
12032
Mark Mueller93b938f2016-08-18 10:27:40 -060012033 VkSubmitInfo submit_info = {};
12034 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12035 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012036 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012037
Mark Mueller4042b652016-09-05 22:52:21 -060012038 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012039 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12041 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012042 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012043 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012044 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12045 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012046
Dave Houltonfbf52152017-01-06 12:55:29 -070012047 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012048 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012049 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012050
Mark Mueller4042b652016-09-05 22:52:21 -060012051 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012052 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12053 m_errorMonitor->SetUnexpectedError(
12054 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12055 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012056 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012057 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012058
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12060 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012061 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012062 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12063 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012064
12065 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012066
12067 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012068}
12069
Tony Barbour626994c2017-02-08 15:29:37 -070012070TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12071 TEST_DESCRIPTION(
12072 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12073 "errors");
12074 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12075 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12076 ASSERT_NO_FATAL_FAILURE(InitState());
12077
12078 VkCommandBuffer cmd_bufs[2];
12079 VkCommandBufferAllocateInfo alloc_info;
12080 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12081 alloc_info.pNext = NULL;
12082 alloc_info.commandBufferCount = 2;
12083 alloc_info.commandPool = m_commandPool;
12084 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12085 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12086
12087 VkCommandBufferBeginInfo cb_binfo;
12088 cb_binfo.pNext = NULL;
12089 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12090 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12091 cb_binfo.flags = 0;
12092 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12093 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12094 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12095 vkEndCommandBuffer(cmd_bufs[0]);
12096 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12097
12098 VkSubmitInfo submit_info = {};
12099 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12100 submit_info.commandBufferCount = 2;
12101 submit_info.pCommandBuffers = duplicates;
12102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12103 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12104 m_errorMonitor->VerifyFound();
12105 vkQueueWaitIdle(m_device->m_queue);
12106
12107 // Set one time use and now look for one time submit
12108 duplicates[0] = duplicates[1] = cmd_bufs[1];
12109 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12110 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12111 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12112 vkEndCommandBuffer(cmd_bufs[1]);
12113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12114 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12115 m_errorMonitor->VerifyFound();
12116 vkQueueWaitIdle(m_device->m_queue);
12117}
12118
Tobin Ehlisb093da82017-01-19 12:05:27 -070012119TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012120 TEST_DESCRIPTION(
12121 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12122 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012123
12124 ASSERT_NO_FATAL_FAILURE(InitState());
12125 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12126
12127 std::vector<const char *> device_extension_names;
12128 auto features = m_device->phy().features();
12129 // Make sure gs & ts are disabled
12130 features.geometryShader = false;
12131 features.tessellationShader = false;
12132 // The sacrificial device object
12133 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12134
12135 VkCommandPoolCreateInfo pool_create_info{};
12136 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12137 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12138
12139 VkCommandPool command_pool;
12140 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12141
12142 VkCommandBufferAllocateInfo cmd = {};
12143 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12144 cmd.pNext = NULL;
12145 cmd.commandPool = command_pool;
12146 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12147 cmd.commandBufferCount = 1;
12148
12149 VkCommandBuffer cmd_buffer;
12150 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12151 ASSERT_VK_SUCCESS(err);
12152
12153 VkEvent event;
12154 VkEventCreateInfo evci = {};
12155 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12156 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12157 ASSERT_VK_SUCCESS(result);
12158
12159 VkCommandBufferBeginInfo cbbi = {};
12160 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12161 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12163 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12164 m_errorMonitor->VerifyFound();
12165
12166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12167 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12168 m_errorMonitor->VerifyFound();
12169
12170 vkDestroyEvent(test_device.handle(), event, NULL);
12171 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12172}
12173
Mark Mueller917f6bc2016-08-30 10:57:19 -060012174TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012175 TEST_DESCRIPTION(
12176 "Use vkCmdExecuteCommands with invalid state "
12177 "in primary and secondary command buffers. "
12178 "Delete objects that are inuse. Call VkQueueSubmit "
12179 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012180
12181 ASSERT_NO_FATAL_FAILURE(InitState());
12182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12183
Tony Barbour552f6c02016-12-21 14:34:07 -070012184 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012185
12186 VkEvent event;
12187 VkEventCreateInfo event_create_info = {};
12188 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12189 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012190 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012191
Tony Barbour552f6c02016-12-21 14:34:07 -070012192 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012193 vkDestroyEvent(m_device->device(), event, nullptr);
12194
12195 VkSubmitInfo submit_info = {};
12196 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12197 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012198 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012200 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12201 m_errorMonitor->VerifyFound();
12202
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012203 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012204 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12205
12206 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12207
Mark Mueller917f6bc2016-08-30 10:57:19 -060012208 VkSemaphoreCreateInfo semaphore_create_info = {};
12209 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12210 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012211 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012212 VkFenceCreateInfo fence_create_info = {};
12213 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12214 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012215 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012216
12217 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012218 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012219 descriptor_pool_type_count.descriptorCount = 1;
12220
12221 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12222 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12223 descriptor_pool_create_info.maxSets = 1;
12224 descriptor_pool_create_info.poolSizeCount = 1;
12225 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012226 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012227
12228 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012229 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012230
12231 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012232 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012233 descriptorset_layout_binding.descriptorCount = 1;
12234 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12235
12236 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012237 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012238 descriptorset_layout_create_info.bindingCount = 1;
12239 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12240
12241 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012242 ASSERT_VK_SUCCESS(
12243 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012244
12245 VkDescriptorSet descriptorset;
12246 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012247 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012248 descriptorset_allocate_info.descriptorSetCount = 1;
12249 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12250 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012251 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012252
Mark Mueller4042b652016-09-05 22:52:21 -060012253 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12254
12255 VkDescriptorBufferInfo buffer_info = {};
12256 buffer_info.buffer = buffer_test.GetBuffer();
12257 buffer_info.offset = 0;
12258 buffer_info.range = 1024;
12259
12260 VkWriteDescriptorSet write_descriptor_set = {};
12261 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12262 write_descriptor_set.dstSet = descriptorset;
12263 write_descriptor_set.descriptorCount = 1;
12264 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12265 write_descriptor_set.pBufferInfo = &buffer_info;
12266
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012267 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012268
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012269 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12270 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012271
12272 VkPipelineObj pipe(m_device);
12273 pipe.AddColorAttachment();
12274 pipe.AddShader(&vs);
12275 pipe.AddShader(&fs);
12276
12277 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012278 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012279 pipeline_layout_create_info.setLayoutCount = 1;
12280 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12281
12282 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012283 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012284
12285 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12286
Tony Barbour552f6c02016-12-21 14:34:07 -070012287 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012288 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012289
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012290 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12292 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012293
Tony Barbour552f6c02016-12-21 14:34:07 -070012294 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012295
Mark Mueller917f6bc2016-08-30 10:57:19 -060012296 submit_info.signalSemaphoreCount = 1;
12297 submit_info.pSignalSemaphores = &semaphore;
12298 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012299 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012300
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012301 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012302 vkDestroyEvent(m_device->device(), event, nullptr);
12303 m_errorMonitor->VerifyFound();
12304
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012306 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12307 m_errorMonitor->VerifyFound();
12308
Jeremy Hayes08369882017-02-02 10:31:06 -070012309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012310 vkDestroyFence(m_device->device(), fence, nullptr);
12311 m_errorMonitor->VerifyFound();
12312
Tobin Ehlis122207b2016-09-01 08:50:06 -070012313 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012314 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12315 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012316 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012317 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12318 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012319 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012320 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12321 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012322 vkDestroyEvent(m_device->device(), event, nullptr);
12323 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012324 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012325 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12326}
12327
Tobin Ehlis2adda372016-09-01 08:51:06 -070012328TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12329 TEST_DESCRIPTION("Delete in-use query pool.");
12330
12331 ASSERT_NO_FATAL_FAILURE(InitState());
12332 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12333
12334 VkQueryPool query_pool;
12335 VkQueryPoolCreateInfo query_pool_ci{};
12336 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12337 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12338 query_pool_ci.queryCount = 1;
12339 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012340 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012341 // Reset query pool to create binding with cmd buffer
12342 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12343
Tony Barbour552f6c02016-12-21 14:34:07 -070012344 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012345
12346 VkSubmitInfo submit_info = {};
12347 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12348 submit_info.commandBufferCount = 1;
12349 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12350 // Submit cmd buffer and then destroy query pool while in-flight
12351 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12352
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012354 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12355 m_errorMonitor->VerifyFound();
12356
12357 vkQueueWaitIdle(m_device->m_queue);
12358 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012359 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12360 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012361 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12362}
12363
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012364TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12365 TEST_DESCRIPTION("Delete in-use pipeline.");
12366
12367 ASSERT_NO_FATAL_FAILURE(InitState());
12368 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12369
12370 // Empty pipeline layout used for binding PSO
12371 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12372 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12373 pipeline_layout_ci.setLayoutCount = 0;
12374 pipeline_layout_ci.pSetLayouts = NULL;
12375
12376 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012377 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012378 ASSERT_VK_SUCCESS(err);
12379
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012381 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012382 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12383 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012384 // Store pipeline handle so we can actually delete it before test finishes
12385 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012386 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012387 VkPipelineObj pipe(m_device);
12388 pipe.AddShader(&vs);
12389 pipe.AddShader(&fs);
12390 pipe.AddColorAttachment();
12391 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12392 delete_this_pipeline = pipe.handle();
12393
Tony Barbour552f6c02016-12-21 14:34:07 -070012394 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012395 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012396 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012397
Tony Barbour552f6c02016-12-21 14:34:07 -070012398 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012399
12400 VkSubmitInfo submit_info = {};
12401 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12402 submit_info.commandBufferCount = 1;
12403 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12404 // Submit cmd buffer and then pipeline destroyed while in-flight
12405 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012406 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012407 m_errorMonitor->VerifyFound();
12408 // Make sure queue finished and then actually delete pipeline
12409 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012410 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12411 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012412 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12413 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12414}
12415
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012416TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12417 TEST_DESCRIPTION("Delete in-use imageView.");
12418
12419 ASSERT_NO_FATAL_FAILURE(InitState());
12420 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12421
12422 VkDescriptorPoolSize ds_type_count;
12423 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12424 ds_type_count.descriptorCount = 1;
12425
12426 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12427 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12428 ds_pool_ci.maxSets = 1;
12429 ds_pool_ci.poolSizeCount = 1;
12430 ds_pool_ci.pPoolSizes = &ds_type_count;
12431
12432 VkDescriptorPool ds_pool;
12433 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12434 ASSERT_VK_SUCCESS(err);
12435
12436 VkSamplerCreateInfo sampler_ci = {};
12437 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12438 sampler_ci.pNext = NULL;
12439 sampler_ci.magFilter = VK_FILTER_NEAREST;
12440 sampler_ci.minFilter = VK_FILTER_NEAREST;
12441 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12442 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12443 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12444 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12445 sampler_ci.mipLodBias = 1.0;
12446 sampler_ci.anisotropyEnable = VK_FALSE;
12447 sampler_ci.maxAnisotropy = 1;
12448 sampler_ci.compareEnable = VK_FALSE;
12449 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12450 sampler_ci.minLod = 1.0;
12451 sampler_ci.maxLod = 1.0;
12452 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12453 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12454 VkSampler sampler;
12455
12456 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12457 ASSERT_VK_SUCCESS(err);
12458
12459 VkDescriptorSetLayoutBinding layout_binding;
12460 layout_binding.binding = 0;
12461 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12462 layout_binding.descriptorCount = 1;
12463 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12464 layout_binding.pImmutableSamplers = NULL;
12465
12466 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12467 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12468 ds_layout_ci.bindingCount = 1;
12469 ds_layout_ci.pBindings = &layout_binding;
12470 VkDescriptorSetLayout ds_layout;
12471 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12472 ASSERT_VK_SUCCESS(err);
12473
12474 VkDescriptorSetAllocateInfo alloc_info = {};
12475 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12476 alloc_info.descriptorSetCount = 1;
12477 alloc_info.descriptorPool = ds_pool;
12478 alloc_info.pSetLayouts = &ds_layout;
12479 VkDescriptorSet descriptor_set;
12480 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12481 ASSERT_VK_SUCCESS(err);
12482
12483 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12484 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12485 pipeline_layout_ci.pNext = NULL;
12486 pipeline_layout_ci.setLayoutCount = 1;
12487 pipeline_layout_ci.pSetLayouts = &ds_layout;
12488
12489 VkPipelineLayout pipeline_layout;
12490 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12491 ASSERT_VK_SUCCESS(err);
12492
12493 VkImageObj image(m_device);
12494 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12495 ASSERT_TRUE(image.initialized());
12496
12497 VkImageView view;
12498 VkImageViewCreateInfo ivci = {};
12499 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12500 ivci.image = image.handle();
12501 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12502 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12503 ivci.subresourceRange.layerCount = 1;
12504 ivci.subresourceRange.baseMipLevel = 0;
12505 ivci.subresourceRange.levelCount = 1;
12506 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12507
12508 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12509 ASSERT_VK_SUCCESS(err);
12510
12511 VkDescriptorImageInfo image_info{};
12512 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12513 image_info.imageView = view;
12514 image_info.sampler = sampler;
12515
12516 VkWriteDescriptorSet descriptor_write = {};
12517 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12518 descriptor_write.dstSet = descriptor_set;
12519 descriptor_write.dstBinding = 0;
12520 descriptor_write.descriptorCount = 1;
12521 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12522 descriptor_write.pImageInfo = &image_info;
12523
12524 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12525
12526 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012527 char const *vsSource =
12528 "#version 450\n"
12529 "\n"
12530 "out gl_PerVertex { \n"
12531 " vec4 gl_Position;\n"
12532 "};\n"
12533 "void main(){\n"
12534 " gl_Position = vec4(1);\n"
12535 "}\n";
12536 char const *fsSource =
12537 "#version 450\n"
12538 "\n"
12539 "layout(set=0, binding=0) uniform sampler2D s;\n"
12540 "layout(location=0) out vec4 x;\n"
12541 "void main(){\n"
12542 " x = texture(s, vec2(1));\n"
12543 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012544 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12545 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12546 VkPipelineObj pipe(m_device);
12547 pipe.AddShader(&vs);
12548 pipe.AddShader(&fs);
12549 pipe.AddColorAttachment();
12550 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12551
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012553
Tony Barbour552f6c02016-12-21 14:34:07 -070012554 m_commandBuffer->BeginCommandBuffer();
12555 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012556 // Bind pipeline to cmd buffer
12557 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12558 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12559 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012560
12561 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12562 VkRect2D scissor = {{0, 0}, {16, 16}};
12563 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12564 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12565
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012566 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012567 m_commandBuffer->EndRenderPass();
12568 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012569 // Submit cmd buffer then destroy sampler
12570 VkSubmitInfo submit_info = {};
12571 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12572 submit_info.commandBufferCount = 1;
12573 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12574 // Submit cmd buffer and then destroy imageView while in-flight
12575 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12576
12577 vkDestroyImageView(m_device->device(), view, nullptr);
12578 m_errorMonitor->VerifyFound();
12579 vkQueueWaitIdle(m_device->m_queue);
12580 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012581 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12582 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012583 vkDestroyImageView(m_device->device(), view, NULL);
12584 vkDestroySampler(m_device->device(), sampler, nullptr);
12585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12586 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12588}
12589
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012590TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12591 TEST_DESCRIPTION("Delete in-use bufferView.");
12592
12593 ASSERT_NO_FATAL_FAILURE(InitState());
12594 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12595
12596 VkDescriptorPoolSize ds_type_count;
12597 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12598 ds_type_count.descriptorCount = 1;
12599
12600 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12601 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12602 ds_pool_ci.maxSets = 1;
12603 ds_pool_ci.poolSizeCount = 1;
12604 ds_pool_ci.pPoolSizes = &ds_type_count;
12605
12606 VkDescriptorPool ds_pool;
12607 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12608 ASSERT_VK_SUCCESS(err);
12609
12610 VkDescriptorSetLayoutBinding layout_binding;
12611 layout_binding.binding = 0;
12612 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12613 layout_binding.descriptorCount = 1;
12614 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12615 layout_binding.pImmutableSamplers = NULL;
12616
12617 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12618 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12619 ds_layout_ci.bindingCount = 1;
12620 ds_layout_ci.pBindings = &layout_binding;
12621 VkDescriptorSetLayout ds_layout;
12622 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12623 ASSERT_VK_SUCCESS(err);
12624
12625 VkDescriptorSetAllocateInfo alloc_info = {};
12626 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12627 alloc_info.descriptorSetCount = 1;
12628 alloc_info.descriptorPool = ds_pool;
12629 alloc_info.pSetLayouts = &ds_layout;
12630 VkDescriptorSet descriptor_set;
12631 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12632 ASSERT_VK_SUCCESS(err);
12633
12634 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12635 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12636 pipeline_layout_ci.pNext = NULL;
12637 pipeline_layout_ci.setLayoutCount = 1;
12638 pipeline_layout_ci.pSetLayouts = &ds_layout;
12639
12640 VkPipelineLayout pipeline_layout;
12641 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12642 ASSERT_VK_SUCCESS(err);
12643
12644 VkBuffer buffer;
12645 uint32_t queue_family_index = 0;
12646 VkBufferCreateInfo buffer_create_info = {};
12647 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12648 buffer_create_info.size = 1024;
12649 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12650 buffer_create_info.queueFamilyIndexCount = 1;
12651 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12652
12653 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12654 ASSERT_VK_SUCCESS(err);
12655
12656 VkMemoryRequirements memory_reqs;
12657 VkDeviceMemory buffer_memory;
12658
12659 VkMemoryAllocateInfo memory_info = {};
12660 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12661 memory_info.allocationSize = 0;
12662 memory_info.memoryTypeIndex = 0;
12663
12664 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12665 memory_info.allocationSize = memory_reqs.size;
12666 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12667 ASSERT_TRUE(pass);
12668
12669 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12670 ASSERT_VK_SUCCESS(err);
12671 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12672 ASSERT_VK_SUCCESS(err);
12673
12674 VkBufferView view;
12675 VkBufferViewCreateInfo bvci = {};
12676 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12677 bvci.buffer = buffer;
12678 bvci.format = VK_FORMAT_R8_UNORM;
12679 bvci.range = VK_WHOLE_SIZE;
12680
12681 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12682 ASSERT_VK_SUCCESS(err);
12683
12684 VkWriteDescriptorSet descriptor_write = {};
12685 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12686 descriptor_write.dstSet = descriptor_set;
12687 descriptor_write.dstBinding = 0;
12688 descriptor_write.descriptorCount = 1;
12689 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12690 descriptor_write.pTexelBufferView = &view;
12691
12692 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12693
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012694 char const *vsSource =
12695 "#version 450\n"
12696 "\n"
12697 "out gl_PerVertex { \n"
12698 " vec4 gl_Position;\n"
12699 "};\n"
12700 "void main(){\n"
12701 " gl_Position = vec4(1);\n"
12702 "}\n";
12703 char const *fsSource =
12704 "#version 450\n"
12705 "\n"
12706 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12707 "layout(location=0) out vec4 x;\n"
12708 "void main(){\n"
12709 " x = imageLoad(s, 0);\n"
12710 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012711 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12712 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12713 VkPipelineObj pipe(m_device);
12714 pipe.AddShader(&vs);
12715 pipe.AddShader(&fs);
12716 pipe.AddColorAttachment();
12717 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12718
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012720
Tony Barbour552f6c02016-12-21 14:34:07 -070012721 m_commandBuffer->BeginCommandBuffer();
12722 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012723 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12724 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12725 VkRect2D scissor = {{0, 0}, {16, 16}};
12726 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12727 // Bind pipeline to cmd buffer
12728 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12729 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12730 &descriptor_set, 0, nullptr);
12731 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012732 m_commandBuffer->EndRenderPass();
12733 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012734
12735 VkSubmitInfo submit_info = {};
12736 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12737 submit_info.commandBufferCount = 1;
12738 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12739 // Submit cmd buffer and then destroy bufferView while in-flight
12740 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12741
12742 vkDestroyBufferView(m_device->device(), view, nullptr);
12743 m_errorMonitor->VerifyFound();
12744 vkQueueWaitIdle(m_device->m_queue);
12745 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012746 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12747 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012748 vkDestroyBufferView(m_device->device(), view, NULL);
12749 vkDestroyBuffer(m_device->device(), buffer, NULL);
12750 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12751 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12752 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12753 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12754}
12755
Tobin Ehlis209532e2016-09-07 13:52:18 -060012756TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12757 TEST_DESCRIPTION("Delete in-use sampler.");
12758
12759 ASSERT_NO_FATAL_FAILURE(InitState());
12760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12761
12762 VkDescriptorPoolSize ds_type_count;
12763 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12764 ds_type_count.descriptorCount = 1;
12765
12766 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12767 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12768 ds_pool_ci.maxSets = 1;
12769 ds_pool_ci.poolSizeCount = 1;
12770 ds_pool_ci.pPoolSizes = &ds_type_count;
12771
12772 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012773 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012774 ASSERT_VK_SUCCESS(err);
12775
12776 VkSamplerCreateInfo sampler_ci = {};
12777 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12778 sampler_ci.pNext = NULL;
12779 sampler_ci.magFilter = VK_FILTER_NEAREST;
12780 sampler_ci.minFilter = VK_FILTER_NEAREST;
12781 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12782 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12783 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12784 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12785 sampler_ci.mipLodBias = 1.0;
12786 sampler_ci.anisotropyEnable = VK_FALSE;
12787 sampler_ci.maxAnisotropy = 1;
12788 sampler_ci.compareEnable = VK_FALSE;
12789 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12790 sampler_ci.minLod = 1.0;
12791 sampler_ci.maxLod = 1.0;
12792 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12793 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12794 VkSampler sampler;
12795
12796 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12797 ASSERT_VK_SUCCESS(err);
12798
12799 VkDescriptorSetLayoutBinding layout_binding;
12800 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012801 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012802 layout_binding.descriptorCount = 1;
12803 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12804 layout_binding.pImmutableSamplers = NULL;
12805
12806 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12807 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12808 ds_layout_ci.bindingCount = 1;
12809 ds_layout_ci.pBindings = &layout_binding;
12810 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012811 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012812 ASSERT_VK_SUCCESS(err);
12813
12814 VkDescriptorSetAllocateInfo alloc_info = {};
12815 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12816 alloc_info.descriptorSetCount = 1;
12817 alloc_info.descriptorPool = ds_pool;
12818 alloc_info.pSetLayouts = &ds_layout;
12819 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012820 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012821 ASSERT_VK_SUCCESS(err);
12822
12823 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12824 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12825 pipeline_layout_ci.pNext = NULL;
12826 pipeline_layout_ci.setLayoutCount = 1;
12827 pipeline_layout_ci.pSetLayouts = &ds_layout;
12828
12829 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012830 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012831 ASSERT_VK_SUCCESS(err);
12832
12833 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012834 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 -060012835 ASSERT_TRUE(image.initialized());
12836
12837 VkImageView view;
12838 VkImageViewCreateInfo ivci = {};
12839 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12840 ivci.image = image.handle();
12841 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12842 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12843 ivci.subresourceRange.layerCount = 1;
12844 ivci.subresourceRange.baseMipLevel = 0;
12845 ivci.subresourceRange.levelCount = 1;
12846 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12847
12848 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12849 ASSERT_VK_SUCCESS(err);
12850
12851 VkDescriptorImageInfo image_info{};
12852 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12853 image_info.imageView = view;
12854 image_info.sampler = sampler;
12855
12856 VkWriteDescriptorSet descriptor_write = {};
12857 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12858 descriptor_write.dstSet = descriptor_set;
12859 descriptor_write.dstBinding = 0;
12860 descriptor_write.descriptorCount = 1;
12861 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12862 descriptor_write.pImageInfo = &image_info;
12863
12864 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12865
12866 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012867 char const *vsSource =
12868 "#version 450\n"
12869 "\n"
12870 "out gl_PerVertex { \n"
12871 " vec4 gl_Position;\n"
12872 "};\n"
12873 "void main(){\n"
12874 " gl_Position = vec4(1);\n"
12875 "}\n";
12876 char const *fsSource =
12877 "#version 450\n"
12878 "\n"
12879 "layout(set=0, binding=0) uniform sampler2D s;\n"
12880 "layout(location=0) out vec4 x;\n"
12881 "void main(){\n"
12882 " x = texture(s, vec2(1));\n"
12883 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012884 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12885 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12886 VkPipelineObj pipe(m_device);
12887 pipe.AddShader(&vs);
12888 pipe.AddShader(&fs);
12889 pipe.AddColorAttachment();
12890 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12891
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012893
Tony Barbour552f6c02016-12-21 14:34:07 -070012894 m_commandBuffer->BeginCommandBuffer();
12895 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012896 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012897 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12898 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12899 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012900
12901 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12902 VkRect2D scissor = {{0, 0}, {16, 16}};
12903 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12904 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12905
Tobin Ehlis209532e2016-09-07 13:52:18 -060012906 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012907 m_commandBuffer->EndRenderPass();
12908 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012909 // Submit cmd buffer then destroy sampler
12910 VkSubmitInfo submit_info = {};
12911 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12912 submit_info.commandBufferCount = 1;
12913 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12914 // Submit cmd buffer and then destroy sampler while in-flight
12915 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12916
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012917 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012918 m_errorMonitor->VerifyFound();
12919 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012920
Tobin Ehlis209532e2016-09-07 13:52:18 -060012921 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012922 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12923 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012924 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012925 vkDestroyImageView(m_device->device(), view, NULL);
12926 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12927 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12928 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12929}
12930
Mark Mueller1cd9f412016-08-25 13:23:52 -060012931TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012932 TEST_DESCRIPTION(
12933 "Call VkQueueSubmit with a semaphore that is already "
12934 "signaled but not waited on by the queue. Wait on a "
12935 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012936
12937 ASSERT_NO_FATAL_FAILURE(InitState());
12938 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12939
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012940 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 -070012941 const char *invalid_fence_wait_message =
12942 " which has not been submitted on a Queue or during "
12943 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012944
Tony Barbour552f6c02016-12-21 14:34:07 -070012945 m_commandBuffer->BeginCommandBuffer();
12946 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012947
12948 VkSemaphoreCreateInfo semaphore_create_info = {};
12949 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12950 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012952 VkSubmitInfo submit_info = {};
12953 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12954 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012955 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012956 submit_info.signalSemaphoreCount = 1;
12957 submit_info.pSignalSemaphores = &semaphore;
12958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012959 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012960 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012961 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012962 m_commandBuffer->BeginCommandBuffer();
12963 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012965 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12966 m_errorMonitor->VerifyFound();
12967
Mark Mueller1cd9f412016-08-25 13:23:52 -060012968 VkFenceCreateInfo fence_create_info = {};
12969 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12970 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012971 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012972
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012974 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12975 m_errorMonitor->VerifyFound();
12976
Mark Mueller4042b652016-09-05 22:52:21 -060012977 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012978 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012979 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12980}
12981
Tobin Ehlis4af23302016-07-19 10:50:30 -060012982TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012983 TEST_DESCRIPTION(
12984 "Bind a secondary command buffer with with a framebuffer "
12985 "that does not match the framebuffer for the active "
12986 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012987 ASSERT_NO_FATAL_FAILURE(InitState());
12988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12989
12990 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012991 VkAttachmentDescription attachment = {0,
12992 VK_FORMAT_B8G8R8A8_UNORM,
12993 VK_SAMPLE_COUNT_1_BIT,
12994 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12995 VK_ATTACHMENT_STORE_OP_STORE,
12996 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
12997 VK_ATTACHMENT_STORE_OP_DONT_CARE,
12998 VK_IMAGE_LAYOUT_UNDEFINED,
12999 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013000
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013001 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013002
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013003 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013004
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013005 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013006
13007 VkRenderPass rp;
13008 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13009 ASSERT_VK_SUCCESS(err);
13010
13011 // A compatible framebuffer.
13012 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013013 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 -060013014 ASSERT_TRUE(image.initialized());
13015
13016 VkImageViewCreateInfo ivci = {
13017 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13018 nullptr,
13019 0,
13020 image.handle(),
13021 VK_IMAGE_VIEW_TYPE_2D,
13022 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013023 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13024 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013025 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13026 };
13027 VkImageView view;
13028 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13029 ASSERT_VK_SUCCESS(err);
13030
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013031 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013032 VkFramebuffer fb;
13033 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13034 ASSERT_VK_SUCCESS(err);
13035
13036 VkCommandBufferAllocateInfo cbai = {};
13037 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13038 cbai.commandPool = m_commandPool;
13039 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13040 cbai.commandBufferCount = 1;
13041
13042 VkCommandBuffer sec_cb;
13043 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13044 ASSERT_VK_SUCCESS(err);
13045 VkCommandBufferBeginInfo cbbi = {};
13046 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013047 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013048 cbii.renderPass = renderPass();
13049 cbii.framebuffer = fb;
13050 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13051 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013052 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 -060013053 cbbi.pInheritanceInfo = &cbii;
13054 vkBeginCommandBuffer(sec_cb, &cbbi);
13055 vkEndCommandBuffer(sec_cb);
13056
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013057 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013058 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13059 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013060
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013061 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013062 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013063 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13064 m_errorMonitor->VerifyFound();
13065 // Cleanup
13066 vkDestroyImageView(m_device->device(), view, NULL);
13067 vkDestroyRenderPass(m_device->device(), rp, NULL);
13068 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13069}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013070
13071TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013072 TEST_DESCRIPTION(
13073 "If logicOp is available on the device, set it to an "
13074 "invalid value. If logicOp is not available, attempt to "
13075 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013076 ASSERT_NO_FATAL_FAILURE(InitState());
13077 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13078
13079 auto features = m_device->phy().features();
13080 // Set the expected error depending on whether or not logicOp available
13081 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13083 "If logic operations feature not "
13084 "enabled, logicOpEnable must be "
13085 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013086 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013087 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013088 }
13089 // Create a pipeline using logicOp
13090 VkResult err;
13091
13092 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13093 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13094
13095 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013096 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013097 ASSERT_VK_SUCCESS(err);
13098
13099 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13100 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13101 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013102 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013103 vp_state_ci.pViewports = &vp;
13104 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013105 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013106 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013107
13108 VkPipelineShaderStageCreateInfo shaderStages[2];
13109 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13110
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013111 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13112 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013113 shaderStages[0] = vs.GetStageCreateInfo();
13114 shaderStages[1] = fs.GetStageCreateInfo();
13115
13116 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13117 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13118
13119 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13120 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13121 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13122
13123 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13124 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013125 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013126
13127 VkPipelineColorBlendAttachmentState att = {};
13128 att.blendEnable = VK_FALSE;
13129 att.colorWriteMask = 0xf;
13130
13131 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13132 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13133 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13134 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013135 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013136 cb_ci.attachmentCount = 1;
13137 cb_ci.pAttachments = &att;
13138
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013139 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13140 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13141 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13142
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013143 VkGraphicsPipelineCreateInfo gp_ci = {};
13144 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13145 gp_ci.stageCount = 2;
13146 gp_ci.pStages = shaderStages;
13147 gp_ci.pVertexInputState = &vi_ci;
13148 gp_ci.pInputAssemblyState = &ia_ci;
13149 gp_ci.pViewportState = &vp_state_ci;
13150 gp_ci.pRasterizationState = &rs_ci;
13151 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013152 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013153 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13154 gp_ci.layout = pipeline_layout;
13155 gp_ci.renderPass = renderPass();
13156
13157 VkPipelineCacheCreateInfo pc_ci = {};
13158 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13159
13160 VkPipeline pipeline;
13161 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013162 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013163 ASSERT_VK_SUCCESS(err);
13164
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013165 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013166 m_errorMonitor->VerifyFound();
13167 if (VK_SUCCESS == err) {
13168 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13169 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013170 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13171 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13172}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013173
Mike Stroyanaccf7692015-05-12 16:00:45 -060013174#if GTEST_IS_THREADSAFE
13175struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013176 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013177 VkEvent event;
13178 bool bailout;
13179};
13180
Karl Schultz6addd812016-02-02 17:17:23 -070013181extern "C" void *AddToCommandBuffer(void *arg) {
13182 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013183
Mike Stroyana6d14942016-07-13 15:10:05 -060013184 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013185 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013186 if (data->bailout) {
13187 break;
13188 }
13189 }
13190 return NULL;
13191}
13192
Karl Schultz6addd812016-02-02 17:17:23 -070013193TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013194 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013195
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013197
Mike Stroyanaccf7692015-05-12 16:00:45 -060013198 ASSERT_NO_FATAL_FAILURE(InitState());
13199 ASSERT_NO_FATAL_FAILURE(InitViewport());
13200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13201
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013202 // Calls AllocateCommandBuffers
13203 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013204
13205 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013206 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013207
13208 VkEventCreateInfo event_info;
13209 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013210 VkResult err;
13211
13212 memset(&event_info, 0, sizeof(event_info));
13213 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13214
Chia-I Wuf7458c52015-10-26 21:10:41 +080013215 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013216 ASSERT_VK_SUCCESS(err);
13217
Mike Stroyanaccf7692015-05-12 16:00:45 -060013218 err = vkResetEvent(device(), event);
13219 ASSERT_VK_SUCCESS(err);
13220
13221 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013222 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013223 data.event = event;
13224 data.bailout = false;
13225 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013226
13227 // First do some correct operations using multiple threads.
13228 // Add many entries to command buffer from another thread.
13229 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13230 // Make non-conflicting calls from this thread at the same time.
13231 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013232 uint32_t count;
13233 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013234 }
13235 test_platform_thread_join(thread, NULL);
13236
13237 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013238 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013239 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013240 // Add many entries to command buffer from this thread at the same time.
13241 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013242
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013243 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013244 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013245
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013246 m_errorMonitor->SetBailout(NULL);
13247
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013248 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013249
Chia-I Wuf7458c52015-10-26 21:10:41 +080013250 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013251}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013252#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013253
Karl Schultz6addd812016-02-02 17:17:23 -070013254TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013255 TEST_DESCRIPTION(
13256 "Test that an error is produced for a spirv module "
13257 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013258
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013260
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013261 ASSERT_NO_FATAL_FAILURE(InitState());
13262 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13263
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013264 VkShaderModule module;
13265 VkShaderModuleCreateInfo moduleCreateInfo;
13266 struct icd_spv_header spv;
13267
13268 spv.magic = ICD_SPV_MAGIC;
13269 spv.version = ICD_SPV_VERSION;
13270 spv.gen_magic = 0;
13271
13272 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13273 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013274 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013275 moduleCreateInfo.codeSize = 4;
13276 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013277 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013279 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013280}
13281
Karl Schultz6addd812016-02-02 17:17:23 -070013282TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013283 TEST_DESCRIPTION(
13284 "Test that an error is produced for a spirv module "
13285 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013288
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013289 ASSERT_NO_FATAL_FAILURE(InitState());
13290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13291
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013292 VkShaderModule module;
13293 VkShaderModuleCreateInfo moduleCreateInfo;
13294 struct icd_spv_header spv;
13295
13296 spv.magic = ~ICD_SPV_MAGIC;
13297 spv.version = ICD_SPV_VERSION;
13298 spv.gen_magic = 0;
13299
13300 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13301 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013302 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013303 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13304 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013305 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013306
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013307 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013308}
13309
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013310#if 0
13311// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013312TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013314 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013315
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013316 ASSERT_NO_FATAL_FAILURE(InitState());
13317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13318
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013319 VkShaderModule module;
13320 VkShaderModuleCreateInfo moduleCreateInfo;
13321 struct icd_spv_header spv;
13322
13323 spv.magic = ICD_SPV_MAGIC;
13324 spv.version = ~ICD_SPV_VERSION;
13325 spv.gen_magic = 0;
13326
13327 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13328 moduleCreateInfo.pNext = NULL;
13329
Karl Schultz6addd812016-02-02 17:17:23 -070013330 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013331 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13332 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013333 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013334
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013335 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013336}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013337#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013338
Karl Schultz6addd812016-02-02 17:17:23 -070013339TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013340 TEST_DESCRIPTION(
13341 "Test that a warning is produced for a vertex output that "
13342 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013344
Chris Forbes9f7ff632015-05-25 11:13:08 +120013345 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013346 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013347
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013348 char const *vsSource =
13349 "#version 450\n"
13350 "\n"
13351 "layout(location=0) out float x;\n"
13352 "out gl_PerVertex {\n"
13353 " vec4 gl_Position;\n"
13354 "};\n"
13355 "void main(){\n"
13356 " gl_Position = vec4(1);\n"
13357 " x = 0;\n"
13358 "}\n";
13359 char const *fsSource =
13360 "#version 450\n"
13361 "\n"
13362 "layout(location=0) out vec4 color;\n"
13363 "void main(){\n"
13364 " color = vec4(1);\n"
13365 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013366
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013367 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13368 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013369
13370 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013371 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013372 pipe.AddShader(&vs);
13373 pipe.AddShader(&fs);
13374
Chris Forbes9f7ff632015-05-25 11:13:08 +120013375 VkDescriptorSetObj descriptorSet(m_device);
13376 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013377 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013378
Tony Barbour5781e8f2015-08-04 16:23:11 -060013379 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013380
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013381 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013382}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013383
Mark Mueller098c9cb2016-09-08 09:01:57 -060013384TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13385 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13386
13387 ASSERT_NO_FATAL_FAILURE(InitState());
13388 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13389
13390 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013391 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013392
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013393 char const *vsSource =
13394 "#version 450\n"
13395 "\n"
13396 "out gl_PerVertex {\n"
13397 " vec4 gl_Position;\n"
13398 "};\n"
13399 "void main(){\n"
13400 " gl_Position = vec4(1);\n"
13401 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013402
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013403 char const *fsSource =
13404 "#version 450\n"
13405 "\n"
13406 "layout (constant_id = 0) const float r = 0.0f;\n"
13407 "layout(location = 0) out vec4 uFragColor;\n"
13408 "void main(){\n"
13409 " uFragColor = vec4(r,1,0,1);\n"
13410 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013411
13412 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13413 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13414
13415 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13416 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13417
13418 VkPipelineLayout pipeline_layout;
13419 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13420
13421 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13422 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13423 vp_state_create_info.viewportCount = 1;
13424 VkViewport viewport = {};
13425 vp_state_create_info.pViewports = &viewport;
13426 vp_state_create_info.scissorCount = 1;
13427 VkRect2D scissors = {};
13428 vp_state_create_info.pScissors = &scissors;
13429
13430 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13431
13432 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13433 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13434 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13435 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13436
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013437 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013438
13439 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13440 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13441
13442 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13443 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13444 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13445
13446 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13447 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13448 rasterization_state_create_info.pNext = nullptr;
13449 rasterization_state_create_info.lineWidth = 1.0f;
13450 rasterization_state_create_info.rasterizerDiscardEnable = true;
13451
13452 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13453 color_blend_attachment_state.blendEnable = VK_FALSE;
13454 color_blend_attachment_state.colorWriteMask = 0xf;
13455
13456 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13457 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13458 color_blend_state_create_info.attachmentCount = 1;
13459 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13460
13461 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13462 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13463 graphicspipe_create_info.stageCount = 2;
13464 graphicspipe_create_info.pStages = shader_stage_create_info;
13465 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13466 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13467 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13468 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13469 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13470 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13471 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13472 graphicspipe_create_info.layout = pipeline_layout;
13473 graphicspipe_create_info.renderPass = renderPass();
13474
13475 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13476 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13477
13478 VkPipelineCache pipelineCache;
13479 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13480
13481 // This structure maps constant ids to data locations.
13482 const VkSpecializationMapEntry entry =
13483 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013484 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013485
13486 uint32_t data = 1;
13487
13488 // Set up the info describing spec map and data
13489 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013490 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013491 };
13492 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13493
13494 VkPipeline pipeline;
13495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13496 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13497 m_errorMonitor->VerifyFound();
13498
13499 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13500 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13501}
13502
13503TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13504 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13505
13506 ASSERT_NO_FATAL_FAILURE(InitState());
13507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13508
13509 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13510
13511 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13512 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13513 descriptor_pool_type_count[0].descriptorCount = 1;
13514 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13515 descriptor_pool_type_count[1].descriptorCount = 1;
13516
13517 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13518 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13519 descriptor_pool_create_info.maxSets = 1;
13520 descriptor_pool_create_info.poolSizeCount = 2;
13521 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13522 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13523
13524 VkDescriptorPool descriptorset_pool;
13525 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13526
13527 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13528 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13529 descriptorset_layout_binding.descriptorCount = 1;
13530 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13531
13532 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13533 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13534 descriptorset_layout_create_info.bindingCount = 1;
13535 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13536
13537 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013538 ASSERT_VK_SUCCESS(
13539 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013540
13541 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13542 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13543 descriptorset_allocate_info.descriptorSetCount = 1;
13544 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13545 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13546 VkDescriptorSet descriptorset;
13547 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13548
13549 // Challenge core_validation with a non uniform buffer type.
13550 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13551
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013552 char const *vsSource =
13553 "#version 450\n"
13554 "\n"
13555 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13556 " mat4 mvp;\n"
13557 "} ubuf;\n"
13558 "out gl_PerVertex {\n"
13559 " vec4 gl_Position;\n"
13560 "};\n"
13561 "void main(){\n"
13562 " gl_Position = ubuf.mvp * vec4(1);\n"
13563 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013565 char const *fsSource =
13566 "#version 450\n"
13567 "\n"
13568 "layout(location = 0) out vec4 uFragColor;\n"
13569 "void main(){\n"
13570 " uFragColor = vec4(0,1,0,1);\n"
13571 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013572
13573 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13574 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13575
13576 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13577 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13578 pipeline_layout_create_info.setLayoutCount = 1;
13579 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13580
13581 VkPipelineLayout pipeline_layout;
13582 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13583
13584 VkPipelineObj pipe(m_device);
13585 pipe.AddColorAttachment();
13586 pipe.AddShader(&vs);
13587 pipe.AddShader(&fs);
13588
13589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13590 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13591 m_errorMonitor->VerifyFound();
13592
13593 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13594 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13595 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13596}
13597
13598TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13599 TEST_DESCRIPTION(
13600 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13601
13602 ASSERT_NO_FATAL_FAILURE(InitState());
13603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13604
13605 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13606
13607 VkDescriptorPoolSize descriptor_pool_type_count = {};
13608 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13609 descriptor_pool_type_count.descriptorCount = 1;
13610
13611 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13612 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13613 descriptor_pool_create_info.maxSets = 1;
13614 descriptor_pool_create_info.poolSizeCount = 1;
13615 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13616 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13617
13618 VkDescriptorPool descriptorset_pool;
13619 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13620
13621 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13622 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13623 descriptorset_layout_binding.descriptorCount = 1;
13624 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13625 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13626
13627 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13628 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13629 descriptorset_layout_create_info.bindingCount = 1;
13630 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13631
13632 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013633 ASSERT_VK_SUCCESS(
13634 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013635
13636 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13637 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13638 descriptorset_allocate_info.descriptorSetCount = 1;
13639 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13640 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13641 VkDescriptorSet descriptorset;
13642 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13643
13644 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13645
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013646 char const *vsSource =
13647 "#version 450\n"
13648 "\n"
13649 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13650 " mat4 mvp;\n"
13651 "} ubuf;\n"
13652 "out gl_PerVertex {\n"
13653 " vec4 gl_Position;\n"
13654 "};\n"
13655 "void main(){\n"
13656 " gl_Position = ubuf.mvp * vec4(1);\n"
13657 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013658
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013659 char const *fsSource =
13660 "#version 450\n"
13661 "\n"
13662 "layout(location = 0) out vec4 uFragColor;\n"
13663 "void main(){\n"
13664 " uFragColor = vec4(0,1,0,1);\n"
13665 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013666
13667 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13668 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13669
13670 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13671 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13672 pipeline_layout_create_info.setLayoutCount = 1;
13673 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13674
13675 VkPipelineLayout pipeline_layout;
13676 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13677
13678 VkPipelineObj pipe(m_device);
13679 pipe.AddColorAttachment();
13680 pipe.AddShader(&vs);
13681 pipe.AddShader(&fs);
13682
13683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13684 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13685 m_errorMonitor->VerifyFound();
13686
13687 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13688 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13689 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13690}
13691
13692TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013693 TEST_DESCRIPTION(
13694 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13695 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013696
13697 ASSERT_NO_FATAL_FAILURE(InitState());
13698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13699
13700 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013701 "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 -060013702
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013703 char const *vsSource =
13704 "#version 450\n"
13705 "\n"
13706 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13707 "out gl_PerVertex {\n"
13708 " vec4 gl_Position;\n"
13709 "};\n"
13710 "void main(){\n"
13711 " gl_Position = vec4(consts.x);\n"
13712 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013713
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013714 char const *fsSource =
13715 "#version 450\n"
13716 "\n"
13717 "layout(location = 0) out vec4 uFragColor;\n"
13718 "void main(){\n"
13719 " uFragColor = vec4(0,1,0,1);\n"
13720 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013721
13722 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13723 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13724
13725 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13726 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13727
13728 // Set up a push constant range
13729 VkPushConstantRange push_constant_ranges = {};
13730 // Set to the wrong stage to challenge core_validation
13731 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13732 push_constant_ranges.size = 4;
13733
13734 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13735 pipeline_layout_create_info.pushConstantRangeCount = 1;
13736
13737 VkPipelineLayout pipeline_layout;
13738 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13739
13740 VkPipelineObj pipe(m_device);
13741 pipe.AddColorAttachment();
13742 pipe.AddShader(&vs);
13743 pipe.AddShader(&fs);
13744
13745 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13746 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13747 m_errorMonitor->VerifyFound();
13748
13749 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13750}
13751
13752TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13753 TEST_DESCRIPTION(
13754 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13755
13756 ASSERT_NO_FATAL_FAILURE(InitState());
13757 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13758
13759 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013760 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013761
13762 // Some awkward steps are required to test with custom device features.
13763 std::vector<const char *> device_extension_names;
13764 auto features = m_device->phy().features();
13765 // Disable support for 64 bit floats
13766 features.shaderFloat64 = false;
13767 // The sacrificial device object
13768 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13769
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013770 char const *vsSource =
13771 "#version 450\n"
13772 "\n"
13773 "out gl_PerVertex {\n"
13774 " vec4 gl_Position;\n"
13775 "};\n"
13776 "void main(){\n"
13777 " gl_Position = vec4(1);\n"
13778 "}\n";
13779 char const *fsSource =
13780 "#version 450\n"
13781 "\n"
13782 "layout(location=0) out vec4 color;\n"
13783 "void main(){\n"
13784 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13785 " color = vec4(green);\n"
13786 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013787
13788 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13789 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13790
13791 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013792
13793 VkPipelineObj pipe(&test_device);
13794 pipe.AddColorAttachment();
13795 pipe.AddShader(&vs);
13796 pipe.AddShader(&fs);
13797
13798 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13799 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13800 VkPipelineLayout pipeline_layout;
13801 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13802
13803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13804 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13805 m_errorMonitor->VerifyFound();
13806
13807 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13808}
13809
13810TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13811 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13812
13813 ASSERT_NO_FATAL_FAILURE(InitState());
13814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13815
13816 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13817
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013818 char const *vsSource =
13819 "#version 450\n"
13820 "\n"
13821 "out gl_PerVertex {\n"
13822 " vec4 gl_Position;\n"
13823 "};\n"
13824 "layout(xfb_buffer = 1) out;"
13825 "void main(){\n"
13826 " gl_Position = vec4(1);\n"
13827 "}\n";
13828 char const *fsSource =
13829 "#version 450\n"
13830 "\n"
13831 "layout(location=0) out vec4 color;\n"
13832 "void main(){\n"
13833 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13834 " color = vec4(green);\n"
13835 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013836
13837 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13838 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13839
13840 VkPipelineObj pipe(m_device);
13841 pipe.AddColorAttachment();
13842 pipe.AddShader(&vs);
13843 pipe.AddShader(&fs);
13844
13845 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13846 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13847 VkPipelineLayout pipeline_layout;
13848 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13849
13850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13851 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13852 m_errorMonitor->VerifyFound();
13853
13854 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13855}
13856
Karl Schultz6addd812016-02-02 17:17:23 -070013857TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013858 TEST_DESCRIPTION(
13859 "Test that an error is produced for a fragment shader input "
13860 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013861
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013863
Chris Forbes59cb88d2015-05-25 11:13:13 +120013864 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013865 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013866
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013867 char const *vsSource =
13868 "#version 450\n"
13869 "\n"
13870 "out gl_PerVertex {\n"
13871 " vec4 gl_Position;\n"
13872 "};\n"
13873 "void main(){\n"
13874 " gl_Position = vec4(1);\n"
13875 "}\n";
13876 char const *fsSource =
13877 "#version 450\n"
13878 "\n"
13879 "layout(location=0) in float x;\n"
13880 "layout(location=0) out vec4 color;\n"
13881 "void main(){\n"
13882 " color = vec4(x);\n"
13883 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013884
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013885 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13886 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013887
13888 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013889 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013890 pipe.AddShader(&vs);
13891 pipe.AddShader(&fs);
13892
Chris Forbes59cb88d2015-05-25 11:13:13 +120013893 VkDescriptorSetObj descriptorSet(m_device);
13894 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013895 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013896
Tony Barbour5781e8f2015-08-04 16:23:11 -060013897 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013898
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013899 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013900}
13901
Karl Schultz6addd812016-02-02 17:17:23 -070013902TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013903 TEST_DESCRIPTION(
13904 "Test that an error is produced for a fragment shader input "
13905 "within an interace block, which is not present in the outputs "
13906 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013907 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013908
13909 ASSERT_NO_FATAL_FAILURE(InitState());
13910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13911
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013912 char const *vsSource =
13913 "#version 450\n"
13914 "\n"
13915 "out gl_PerVertex {\n"
13916 " vec4 gl_Position;\n"
13917 "};\n"
13918 "void main(){\n"
13919 " gl_Position = vec4(1);\n"
13920 "}\n";
13921 char const *fsSource =
13922 "#version 450\n"
13923 "\n"
13924 "in block { layout(location=0) float x; } ins;\n"
13925 "layout(location=0) out vec4 color;\n"
13926 "void main(){\n"
13927 " color = vec4(ins.x);\n"
13928 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013929
13930 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13931 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13932
13933 VkPipelineObj pipe(m_device);
13934 pipe.AddColorAttachment();
13935 pipe.AddShader(&vs);
13936 pipe.AddShader(&fs);
13937
13938 VkDescriptorSetObj descriptorSet(m_device);
13939 descriptorSet.AppendDummy();
13940 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13941
13942 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13943
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013944 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013945}
13946
Karl Schultz6addd812016-02-02 17:17:23 -070013947TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013948 TEST_DESCRIPTION(
13949 "Test that an error is produced for mismatched array sizes "
13950 "across the vertex->fragment shader interface");
13951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13952 "Type mismatch on location 0.0: 'ptr to "
13953 "output arr[2] of float32' vs 'ptr to "
13954 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013955
13956 ASSERT_NO_FATAL_FAILURE(InitState());
13957 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13958
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013959 char const *vsSource =
13960 "#version 450\n"
13961 "\n"
13962 "layout(location=0) out float x[2];\n"
13963 "out gl_PerVertex {\n"
13964 " vec4 gl_Position;\n"
13965 "};\n"
13966 "void main(){\n"
13967 " x[0] = 0; x[1] = 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[1];\n"
13974 "layout(location=0) out vec4 color;\n"
13975 "void main(){\n"
13976 " color = vec4(x[0]);\n"
13977 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013978
13979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13981
13982 VkPipelineObj pipe(m_device);
13983 pipe.AddColorAttachment();
13984 pipe.AddShader(&vs);
13985 pipe.AddShader(&fs);
13986
13987 VkDescriptorSetObj descriptorSet(m_device);
13988 descriptorSet.AppendDummy();
13989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13990
13991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13992
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013993 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130013994}
13995
Karl Schultz6addd812016-02-02 17:17:23 -070013996TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
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");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014001
Chris Forbesb56af562015-05-25 11:13:17 +120014002 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014003 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014004
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014005 char const *vsSource =
14006 "#version 450\n"
14007 "\n"
14008 "layout(location=0) out int x;\n"
14009 "out gl_PerVertex {\n"
14010 " vec4 gl_Position;\n"
14011 "};\n"
14012 "void main(){\n"
14013 " x = 0;\n"
14014 " gl_Position = vec4(1);\n"
14015 "}\n";
14016 char const *fsSource =
14017 "#version 450\n"
14018 "\n"
14019 "layout(location=0) in float x;\n" /* VS writes int */
14020 "layout(location=0) out vec4 color;\n"
14021 "void main(){\n"
14022 " color = vec4(x);\n"
14023 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014024
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014025 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14026 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014027
14028 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014029 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014030 pipe.AddShader(&vs);
14031 pipe.AddShader(&fs);
14032
Chris Forbesb56af562015-05-25 11:13:17 +120014033 VkDescriptorSetObj descriptorSet(m_device);
14034 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014035 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014036
Tony Barbour5781e8f2015-08-04 16:23:11 -060014037 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014038
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014039 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014040}
14041
Karl Schultz6addd812016-02-02 17:17:23 -070014042TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014043 TEST_DESCRIPTION(
14044 "Test that an error is produced for mismatched types across "
14045 "the vertex->fragment shader interface, when the variable is contained within "
14046 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014048
14049 ASSERT_NO_FATAL_FAILURE(InitState());
14050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14051
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014052 char const *vsSource =
14053 "#version 450\n"
14054 "\n"
14055 "out block { layout(location=0) int x; } outs;\n"
14056 "out gl_PerVertex {\n"
14057 " vec4 gl_Position;\n"
14058 "};\n"
14059 "void main(){\n"
14060 " outs.x = 0;\n"
14061 " gl_Position = vec4(1);\n"
14062 "}\n";
14063 char const *fsSource =
14064 "#version 450\n"
14065 "\n"
14066 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14067 "layout(location=0) out vec4 color;\n"
14068 "void main(){\n"
14069 " color = vec4(ins.x);\n"
14070 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014071
14072 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14073 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14074
14075 VkPipelineObj pipe(m_device);
14076 pipe.AddColorAttachment();
14077 pipe.AddShader(&vs);
14078 pipe.AddShader(&fs);
14079
14080 VkDescriptorSetObj descriptorSet(m_device);
14081 descriptorSet.AppendDummy();
14082 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14083
14084 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14085
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014086 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014087}
14088
14089TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014090 TEST_DESCRIPTION(
14091 "Test that an error is produced for location mismatches across "
14092 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14093 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014094 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 +130014095
14096 ASSERT_NO_FATAL_FAILURE(InitState());
14097 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14098
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014099 char const *vsSource =
14100 "#version 450\n"
14101 "\n"
14102 "out block { layout(location=1) float x; } outs;\n"
14103 "out gl_PerVertex {\n"
14104 " vec4 gl_Position;\n"
14105 "};\n"
14106 "void main(){\n"
14107 " outs.x = 0;\n"
14108 " gl_Position = vec4(1);\n"
14109 "}\n";
14110 char const *fsSource =
14111 "#version 450\n"
14112 "\n"
14113 "in block { layout(location=0) float x; } ins;\n"
14114 "layout(location=0) out vec4 color;\n"
14115 "void main(){\n"
14116 " color = vec4(ins.x);\n"
14117 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014118
14119 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14120 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14121
14122 VkPipelineObj pipe(m_device);
14123 pipe.AddColorAttachment();
14124 pipe.AddShader(&vs);
14125 pipe.AddShader(&fs);
14126
14127 VkDescriptorSetObj descriptorSet(m_device);
14128 descriptorSet.AppendDummy();
14129 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14130
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014131 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014132 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14133
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014134 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014135}
14136
14137TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014138 TEST_DESCRIPTION(
14139 "Test that an error is produced for component mismatches across the "
14140 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14141 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014142 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 +130014143
14144 ASSERT_NO_FATAL_FAILURE(InitState());
14145 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14146
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014147 char const *vsSource =
14148 "#version 450\n"
14149 "\n"
14150 "out block { layout(location=0, component=0) float x; } outs;\n"
14151 "out gl_PerVertex {\n"
14152 " vec4 gl_Position;\n"
14153 "};\n"
14154 "void main(){\n"
14155 " outs.x = 0;\n"
14156 " gl_Position = vec4(1);\n"
14157 "}\n";
14158 char const *fsSource =
14159 "#version 450\n"
14160 "\n"
14161 "in block { layout(location=0, component=1) float x; } ins;\n"
14162 "layout(location=0) out vec4 color;\n"
14163 "void main(){\n"
14164 " color = vec4(ins.x);\n"
14165 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014166
14167 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14168 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14169
14170 VkPipelineObj pipe(m_device);
14171 pipe.AddColorAttachment();
14172 pipe.AddShader(&vs);
14173 pipe.AddShader(&fs);
14174
14175 VkDescriptorSetObj descriptorSet(m_device);
14176 descriptorSet.AppendDummy();
14177 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14178
14179 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14180
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014181 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014182}
14183
Chris Forbes1f3b0152016-11-30 12:48:40 +130014184TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14185 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14186
14187 ASSERT_NO_FATAL_FAILURE(InitState());
14188 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14189
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014190 char const *vsSource =
14191 "#version 450\n"
14192 "layout(location=0) out mediump float x;\n"
14193 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14194 char const *fsSource =
14195 "#version 450\n"
14196 "layout(location=0) in highp float x;\n"
14197 "layout(location=0) out vec4 color;\n"
14198 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014199
14200 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14201 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14202
14203 VkPipelineObj pipe(m_device);
14204 pipe.AddColorAttachment();
14205 pipe.AddShader(&vs);
14206 pipe.AddShader(&fs);
14207
14208 VkDescriptorSetObj descriptorSet(m_device);
14209 descriptorSet.AppendDummy();
14210 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14211
14212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14213
14214 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14215
14216 m_errorMonitor->VerifyFound();
14217}
14218
Chris Forbes870a39e2016-11-30 12:55:56 +130014219TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14220 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14221
14222 ASSERT_NO_FATAL_FAILURE(InitState());
14223 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14224
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014225 char const *vsSource =
14226 "#version 450\n"
14227 "out block { layout(location=0) mediump float x; };\n"
14228 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14229 char const *fsSource =
14230 "#version 450\n"
14231 "in block { layout(location=0) highp float x; };\n"
14232 "layout(location=0) out vec4 color;\n"
14233 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014234
14235 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14236 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14237
14238 VkPipelineObj pipe(m_device);
14239 pipe.AddColorAttachment();
14240 pipe.AddShader(&vs);
14241 pipe.AddShader(&fs);
14242
14243 VkDescriptorSetObj descriptorSet(m_device);
14244 descriptorSet.AppendDummy();
14245 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14246
14247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14248
14249 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14250
14251 m_errorMonitor->VerifyFound();
14252}
14253
Karl Schultz6addd812016-02-02 17:17:23 -070014254TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014255 TEST_DESCRIPTION(
14256 "Test that a warning is produced for a vertex attribute which is "
14257 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014259
Chris Forbesde136e02015-05-25 11:13:28 +120014260 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014261 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014262
14263 VkVertexInputBindingDescription input_binding;
14264 memset(&input_binding, 0, sizeof(input_binding));
14265
14266 VkVertexInputAttributeDescription input_attrib;
14267 memset(&input_attrib, 0, sizeof(input_attrib));
14268 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14269
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014270 char const *vsSource =
14271 "#version 450\n"
14272 "\n"
14273 "out gl_PerVertex {\n"
14274 " vec4 gl_Position;\n"
14275 "};\n"
14276 "void main(){\n"
14277 " gl_Position = vec4(1);\n"
14278 "}\n";
14279 char const *fsSource =
14280 "#version 450\n"
14281 "\n"
14282 "layout(location=0) out vec4 color;\n"
14283 "void main(){\n"
14284 " color = vec4(1);\n"
14285 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014286
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014287 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14288 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014289
14290 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014291 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014292 pipe.AddShader(&vs);
14293 pipe.AddShader(&fs);
14294
14295 pipe.AddVertexInputBindings(&input_binding, 1);
14296 pipe.AddVertexInputAttribs(&input_attrib, 1);
14297
Chris Forbesde136e02015-05-25 11:13:28 +120014298 VkDescriptorSetObj descriptorSet(m_device);
14299 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014300 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014301
Tony Barbour5781e8f2015-08-04 16:23:11 -060014302 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014303
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014304 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014305}
14306
Karl Schultz6addd812016-02-02 17:17:23 -070014307TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014308 TEST_DESCRIPTION(
14309 "Test that a warning is produced for a location mismatch on "
14310 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014312
14313 ASSERT_NO_FATAL_FAILURE(InitState());
14314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14315
14316 VkVertexInputBindingDescription input_binding;
14317 memset(&input_binding, 0, sizeof(input_binding));
14318
14319 VkVertexInputAttributeDescription input_attrib;
14320 memset(&input_attrib, 0, sizeof(input_attrib));
14321 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014323 char const *vsSource =
14324 "#version 450\n"
14325 "\n"
14326 "layout(location=1) in float x;\n"
14327 "out gl_PerVertex {\n"
14328 " vec4 gl_Position;\n"
14329 "};\n"
14330 "void main(){\n"
14331 " gl_Position = vec4(x);\n"
14332 "}\n";
14333 char const *fsSource =
14334 "#version 450\n"
14335 "\n"
14336 "layout(location=0) out vec4 color;\n"
14337 "void main(){\n"
14338 " color = vec4(1);\n"
14339 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014340
14341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14343
14344 VkPipelineObj pipe(m_device);
14345 pipe.AddColorAttachment();
14346 pipe.AddShader(&vs);
14347 pipe.AddShader(&fs);
14348
14349 pipe.AddVertexInputBindings(&input_binding, 1);
14350 pipe.AddVertexInputAttribs(&input_attrib, 1);
14351
14352 VkDescriptorSetObj descriptorSet(m_device);
14353 descriptorSet.AppendDummy();
14354 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14355
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014356 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014357 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14358
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014359 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014360}
14361
Karl Schultz6addd812016-02-02 17:17:23 -070014362TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014363 TEST_DESCRIPTION(
14364 "Test that an error is produced for a vertex shader input which is not "
14365 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14367 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014368
Chris Forbes62e8e502015-05-25 11:13:29 +120014369 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014370 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014371
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014372 char const *vsSource =
14373 "#version 450\n"
14374 "\n"
14375 "layout(location=0) in vec4 x;\n" /* not provided */
14376 "out gl_PerVertex {\n"
14377 " vec4 gl_Position;\n"
14378 "};\n"
14379 "void main(){\n"
14380 " gl_Position = x;\n"
14381 "}\n";
14382 char const *fsSource =
14383 "#version 450\n"
14384 "\n"
14385 "layout(location=0) out vec4 color;\n"
14386 "void main(){\n"
14387 " color = vec4(1);\n"
14388 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014389
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014390 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14391 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014392
14393 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014394 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014395 pipe.AddShader(&vs);
14396 pipe.AddShader(&fs);
14397
Chris Forbes62e8e502015-05-25 11:13:29 +120014398 VkDescriptorSetObj descriptorSet(m_device);
14399 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014400 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014401
Tony Barbour5781e8f2015-08-04 16:23:11 -060014402 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014403
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014404 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014405}
14406
Karl Schultz6addd812016-02-02 17:17:23 -070014407TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014408 TEST_DESCRIPTION(
14409 "Test that an error is produced for a mismatch between the "
14410 "fundamental type (float/int/uint) of an attribute and the "
14411 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014412 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 -060014413
Chris Forbesc97d98e2015-05-25 11:13:31 +120014414 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014415 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014416
14417 VkVertexInputBindingDescription input_binding;
14418 memset(&input_binding, 0, sizeof(input_binding));
14419
14420 VkVertexInputAttributeDescription input_attrib;
14421 memset(&input_attrib, 0, sizeof(input_attrib));
14422 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14423
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014424 char const *vsSource =
14425 "#version 450\n"
14426 "\n"
14427 "layout(location=0) in int x;\n" /* attrib provided float */
14428 "out gl_PerVertex {\n"
14429 " vec4 gl_Position;\n"
14430 "};\n"
14431 "void main(){\n"
14432 " gl_Position = vec4(x);\n"
14433 "}\n";
14434 char const *fsSource =
14435 "#version 450\n"
14436 "\n"
14437 "layout(location=0) out vec4 color;\n"
14438 "void main(){\n"
14439 " color = vec4(1);\n"
14440 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014441
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014442 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14443 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014444
14445 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014446 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014447 pipe.AddShader(&vs);
14448 pipe.AddShader(&fs);
14449
14450 pipe.AddVertexInputBindings(&input_binding, 1);
14451 pipe.AddVertexInputAttribs(&input_attrib, 1);
14452
Chris Forbesc97d98e2015-05-25 11:13:31 +120014453 VkDescriptorSetObj descriptorSet(m_device);
14454 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014455 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014456
Tony Barbour5781e8f2015-08-04 16:23:11 -060014457 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014458
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014459 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014460}
14461
Chris Forbesc68b43c2016-04-06 11:18:47 +120014462TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014463 TEST_DESCRIPTION(
14464 "Test that an error is produced for a pipeline containing multiple "
14465 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014466 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14467 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014468
14469 ASSERT_NO_FATAL_FAILURE(InitState());
14470 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14471
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014472 char const *vsSource =
14473 "#version 450\n"
14474 "\n"
14475 "out gl_PerVertex {\n"
14476 " vec4 gl_Position;\n"
14477 "};\n"
14478 "void main(){\n"
14479 " gl_Position = vec4(1);\n"
14480 "}\n";
14481 char const *fsSource =
14482 "#version 450\n"
14483 "\n"
14484 "layout(location=0) out vec4 color;\n"
14485 "void main(){\n"
14486 " color = vec4(1);\n"
14487 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014488
14489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14491
14492 VkPipelineObj pipe(m_device);
14493 pipe.AddColorAttachment();
14494 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014495 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014496 pipe.AddShader(&fs);
14497
14498 VkDescriptorSetObj descriptorSet(m_device);
14499 descriptorSet.AppendDummy();
14500 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14501
14502 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14503
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014504 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014505}
14506
Chris Forbes82ff92a2016-09-09 10:50:24 +120014507TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014508 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014509
14510 ASSERT_NO_FATAL_FAILURE(InitState());
14511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14512
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014513 char const *vsSource =
14514 "#version 450\n"
14515 "out gl_PerVertex {\n"
14516 " vec4 gl_Position;\n"
14517 "};\n"
14518 "void main(){\n"
14519 " gl_Position = vec4(0);\n"
14520 "}\n";
14521 char const *fsSource =
14522 "#version 450\n"
14523 "\n"
14524 "layout(location=0) out vec4 color;\n"
14525 "void main(){\n"
14526 " color = vec4(1);\n"
14527 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014528
14529 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14530 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14531
14532 VkPipelineObj pipe(m_device);
14533 pipe.AddColorAttachment();
14534 pipe.AddShader(&vs);
14535 pipe.AddShader(&fs);
14536
14537 VkDescriptorSetObj descriptorSet(m_device);
14538 descriptorSet.AppendDummy();
14539 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14540
14541 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14542
14543 m_errorMonitor->VerifyFound();
14544}
14545
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014546TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014547 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14548 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14549 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014550
14551 ASSERT_NO_FATAL_FAILURE(InitState());
14552 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14553
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014554 char const *vsSource =
14555 "#version 450\n"
14556 "void main(){ gl_Position = vec4(0); }\n";
14557 char const *fsSource =
14558 "#version 450\n"
14559 "\n"
14560 "layout(location=0) out vec4 color;\n"
14561 "void main(){\n"
14562 " color = vec4(1);\n"
14563 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014564
14565 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14566 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14567
14568 VkPipelineObj pipe(m_device);
14569 pipe.AddColorAttachment();
14570 pipe.AddShader(&vs);
14571 pipe.AddShader(&fs);
14572
14573 VkDescriptorSetObj descriptorSet(m_device);
14574 descriptorSet.AppendDummy();
14575 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14576
14577 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014578 {
14579 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14580 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14581 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014582 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014583 {
14584 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14585 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14586 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014587 },
14588 };
14589 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014590 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014591 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014592 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14593 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014594 VkRenderPass rp;
14595 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14596 ASSERT_VK_SUCCESS(err);
14597
14598 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14599
14600 m_errorMonitor->VerifyFound();
14601
14602 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14603}
14604
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014605TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014606 TEST_DESCRIPTION(
14607 "Test that an error is produced for a variable output from "
14608 "the TCS without the patch decoration, but consumed in the TES "
14609 "with the decoration.");
14610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14611 "is per-vertex in tessellation control shader stage "
14612 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014613
14614 ASSERT_NO_FATAL_FAILURE(InitState());
14615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14616
Chris Forbesc1e852d2016-04-04 19:26:42 +120014617 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014618 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014619 return;
14620 }
14621
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014622 char const *vsSource =
14623 "#version 450\n"
14624 "void main(){}\n";
14625 char const *tcsSource =
14626 "#version 450\n"
14627 "layout(location=0) out int x[];\n"
14628 "layout(vertices=3) out;\n"
14629 "void main(){\n"
14630 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14631 " gl_TessLevelInner[0] = 1;\n"
14632 " x[gl_InvocationID] = gl_InvocationID;\n"
14633 "}\n";
14634 char const *tesSource =
14635 "#version 450\n"
14636 "layout(triangles, equal_spacing, cw) in;\n"
14637 "layout(location=0) patch in int x;\n"
14638 "out gl_PerVertex { vec4 gl_Position; };\n"
14639 "void main(){\n"
14640 " gl_Position.xyz = gl_TessCoord;\n"
14641 " gl_Position.w = x;\n"
14642 "}\n";
14643 char const *fsSource =
14644 "#version 450\n"
14645 "layout(location=0) out vec4 color;\n"
14646 "void main(){\n"
14647 " color = vec4(1);\n"
14648 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014649
14650 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14651 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14652 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14653 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014655 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14656 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014657
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014658 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014659
14660 VkPipelineObj pipe(m_device);
14661 pipe.SetInputAssembly(&iasci);
14662 pipe.SetTessellation(&tsci);
14663 pipe.AddColorAttachment();
14664 pipe.AddShader(&vs);
14665 pipe.AddShader(&tcs);
14666 pipe.AddShader(&tes);
14667 pipe.AddShader(&fs);
14668
14669 VkDescriptorSetObj descriptorSet(m_device);
14670 descriptorSet.AppendDummy();
14671 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14672
14673 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14674
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014675 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014676}
14677
Karl Schultz6addd812016-02-02 17:17:23 -070014678TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014679 TEST_DESCRIPTION(
14680 "Test that an error is produced for a vertex attribute setup where multiple "
14681 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14683 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014684
Chris Forbes280ba2c2015-06-12 11:16:41 +120014685 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014686 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014687
14688 /* Two binding descriptions for binding 0 */
14689 VkVertexInputBindingDescription input_bindings[2];
14690 memset(input_bindings, 0, sizeof(input_bindings));
14691
14692 VkVertexInputAttributeDescription input_attrib;
14693 memset(&input_attrib, 0, sizeof(input_attrib));
14694 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14695
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014696 char const *vsSource =
14697 "#version 450\n"
14698 "\n"
14699 "layout(location=0) in float x;\n" /* attrib provided float */
14700 "out gl_PerVertex {\n"
14701 " vec4 gl_Position;\n"
14702 "};\n"
14703 "void main(){\n"
14704 " gl_Position = vec4(x);\n"
14705 "}\n";
14706 char const *fsSource =
14707 "#version 450\n"
14708 "\n"
14709 "layout(location=0) out vec4 color;\n"
14710 "void main(){\n"
14711 " color = vec4(1);\n"
14712 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014713
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014714 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14715 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014716
14717 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014718 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014719 pipe.AddShader(&vs);
14720 pipe.AddShader(&fs);
14721
14722 pipe.AddVertexInputBindings(input_bindings, 2);
14723 pipe.AddVertexInputAttribs(&input_attrib, 1);
14724
Chris Forbes280ba2c2015-06-12 11:16:41 +120014725 VkDescriptorSetObj descriptorSet(m_device);
14726 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014727 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014728
Tony Barbour5781e8f2015-08-04 16:23:11 -060014729 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014730
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014731 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014732}
Chris Forbes8f68b562015-05-25 11:13:32 +120014733
Karl Schultz6addd812016-02-02 17:17:23 -070014734TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014735 TEST_DESCRIPTION(
14736 "Test that an error is produced for a fragment shader which does not "
14737 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014739
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014740 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014741
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014742 char const *vsSource =
14743 "#version 450\n"
14744 "\n"
14745 "out gl_PerVertex {\n"
14746 " vec4 gl_Position;\n"
14747 "};\n"
14748 "void main(){\n"
14749 " gl_Position = vec4(1);\n"
14750 "}\n";
14751 char const *fsSource =
14752 "#version 450\n"
14753 "\n"
14754 "void main(){\n"
14755 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014756
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014757 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14758 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014759
14760 VkPipelineObj pipe(m_device);
14761 pipe.AddShader(&vs);
14762 pipe.AddShader(&fs);
14763
Chia-I Wu08accc62015-07-07 11:50:03 +080014764 /* set up CB 0, not written */
14765 pipe.AddColorAttachment();
14766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014767
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014768 VkDescriptorSetObj descriptorSet(m_device);
14769 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014770 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014771
Tony Barbour5781e8f2015-08-04 16:23:11 -060014772 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014773
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014774 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014775}
14776
Karl Schultz6addd812016-02-02 17:17:23 -070014777TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014778 TEST_DESCRIPTION(
14779 "Test that a warning is produced for a fragment shader which provides a spurious "
14780 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014782 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014783
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014784 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014785
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014786 char const *vsSource =
14787 "#version 450\n"
14788 "\n"
14789 "out gl_PerVertex {\n"
14790 " vec4 gl_Position;\n"
14791 "};\n"
14792 "void main(){\n"
14793 " gl_Position = vec4(1);\n"
14794 "}\n";
14795 char const *fsSource =
14796 "#version 450\n"
14797 "\n"
14798 "layout(location=0) out vec4 x;\n"
14799 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14800 "void main(){\n"
14801 " x = vec4(1);\n"
14802 " y = vec4(1);\n"
14803 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +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 Forbesf3fffaa2015-05-25 11:13:43 +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, not written */
14813 pipe.AddColorAttachment();
14814 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014815 /* FS writes CB 1, but we don't configure it */
14816
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014817 VkDescriptorSetObj descriptorSet(m_device);
14818 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014819 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014820
Tony Barbour5781e8f2015-08-04 16:23:11 -060014821 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014822
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014823 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014824}
14825
Karl Schultz6addd812016-02-02 17:17:23 -070014826TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014827 TEST_DESCRIPTION(
14828 "Test that an error is produced for a mismatch between the fundamental "
14829 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014831
Chris Forbesa36d69e2015-05-25 11:13:44 +120014832 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014833
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014834 char const *vsSource =
14835 "#version 450\n"
14836 "\n"
14837 "out gl_PerVertex {\n"
14838 " vec4 gl_Position;\n"
14839 "};\n"
14840 "void main(){\n"
14841 " gl_Position = vec4(1);\n"
14842 "}\n";
14843 char const *fsSource =
14844 "#version 450\n"
14845 "\n"
14846 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14847 "void main(){\n"
14848 " x = ivec4(1);\n"
14849 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +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 Forbesa36d69e2015-05-25 11:13:44 +120014853
14854 VkPipelineObj pipe(m_device);
14855 pipe.AddShader(&vs);
14856 pipe.AddShader(&fs);
14857
Chia-I Wu08accc62015-07-07 11:50:03 +080014858 /* set up CB 0; type is UNORM by default */
14859 pipe.AddColorAttachment();
14860 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014861
Chris Forbesa36d69e2015-05-25 11:13:44 +120014862 VkDescriptorSetObj descriptorSet(m_device);
14863 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014864 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014865
Tony Barbour5781e8f2015-08-04 16:23:11 -060014866 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014867
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014868 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014869}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014870
Karl Schultz6addd812016-02-02 17:17:23 -070014871TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014872 TEST_DESCRIPTION(
14873 "Test that an error is produced for a shader consuming a uniform "
14874 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014876
Chris Forbes556c76c2015-08-14 12:04:59 +120014877 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014878
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014879 char const *vsSource =
14880 "#version 450\n"
14881 "\n"
14882 "out gl_PerVertex {\n"
14883 " vec4 gl_Position;\n"
14884 "};\n"
14885 "void main(){\n"
14886 " gl_Position = vec4(1);\n"
14887 "}\n";
14888 char const *fsSource =
14889 "#version 450\n"
14890 "\n"
14891 "layout(location=0) out vec4 x;\n"
14892 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14893 "void main(){\n"
14894 " x = vec4(bar.y);\n"
14895 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014896
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014897 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14898 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014899
Chris Forbes556c76c2015-08-14 12:04:59 +120014900 VkPipelineObj pipe(m_device);
14901 pipe.AddShader(&vs);
14902 pipe.AddShader(&fs);
14903
14904 /* set up CB 0; type is UNORM by default */
14905 pipe.AddColorAttachment();
14906 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14907
14908 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014909 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014910
14911 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14912
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014913 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014914}
14915
Chris Forbes5c59e902016-02-26 16:56:09 +130014916TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014917 TEST_DESCRIPTION(
14918 "Test that an error is produced for a shader consuming push constants "
14919 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014921
14922 ASSERT_NO_FATAL_FAILURE(InitState());
14923
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014924 char const *vsSource =
14925 "#version 450\n"
14926 "\n"
14927 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14928 "out gl_PerVertex {\n"
14929 " vec4 gl_Position;\n"
14930 "};\n"
14931 "void main(){\n"
14932 " gl_Position = vec4(consts.x);\n"
14933 "}\n";
14934 char const *fsSource =
14935 "#version 450\n"
14936 "\n"
14937 "layout(location=0) out vec4 x;\n"
14938 "void main(){\n"
14939 " x = vec4(1);\n"
14940 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014941
14942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14944
14945 VkPipelineObj pipe(m_device);
14946 pipe.AddShader(&vs);
14947 pipe.AddShader(&fs);
14948
14949 /* set up CB 0; type is UNORM by default */
14950 pipe.AddColorAttachment();
14951 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14952
14953 VkDescriptorSetObj descriptorSet(m_device);
14954 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14955
14956 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14957
14958 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014959 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014960}
14961
Chris Forbes3fb17902016-08-22 14:57:55 +120014962TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014963 TEST_DESCRIPTION(
14964 "Test that an error is produced for a shader consuming an input attachment "
14965 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14967 "consumes input attachment index 0 but not provided in subpass");
14968
14969 ASSERT_NO_FATAL_FAILURE(InitState());
14970
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014971 char const *vsSource =
14972 "#version 450\n"
14973 "\n"
14974 "out gl_PerVertex {\n"
14975 " vec4 gl_Position;\n"
14976 "};\n"
14977 "void main(){\n"
14978 " gl_Position = vec4(1);\n"
14979 "}\n";
14980 char const *fsSource =
14981 "#version 450\n"
14982 "\n"
14983 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14984 "layout(location=0) out vec4 color;\n"
14985 "void main() {\n"
14986 " color = subpassLoad(x);\n"
14987 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120014988
14989 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14990 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14991
14992 VkPipelineObj pipe(m_device);
14993 pipe.AddShader(&vs);
14994 pipe.AddShader(&fs);
14995 pipe.AddColorAttachment();
14996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14997
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014998 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
14999 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015000 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015001 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015002 ASSERT_VK_SUCCESS(err);
15003
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015004 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015005 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015006 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015007 ASSERT_VK_SUCCESS(err);
15008
15009 // error here.
15010 pipe.CreateVKPipeline(pl, renderPass());
15011
15012 m_errorMonitor->VerifyFound();
15013
15014 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15015 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15016}
15017
Chris Forbes5a9a0472016-08-22 16:02:09 +120015018TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015019 TEST_DESCRIPTION(
15020 "Test that an error is produced for a shader consuming an input attachment "
15021 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015022 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15023 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15024
15025 ASSERT_NO_FATAL_FAILURE(InitState());
15026
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015027 char const *vsSource =
15028 "#version 450\n"
15029 "\n"
15030 "out gl_PerVertex {\n"
15031 " vec4 gl_Position;\n"
15032 "};\n"
15033 "void main(){\n"
15034 " gl_Position = vec4(1);\n"
15035 "}\n";
15036 char const *fsSource =
15037 "#version 450\n"
15038 "\n"
15039 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15040 "layout(location=0) out vec4 color;\n"
15041 "void main() {\n"
15042 " color = subpassLoad(x);\n"
15043 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015044
15045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15047
15048 VkPipelineObj pipe(m_device);
15049 pipe.AddShader(&vs);
15050 pipe.AddShader(&fs);
15051 pipe.AddColorAttachment();
15052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15053
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015054 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15055 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015056 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015057 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015058 ASSERT_VK_SUCCESS(err);
15059
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015060 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015061 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015062 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015063 ASSERT_VK_SUCCESS(err);
15064
15065 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15067 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15068 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15069 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15070 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 +120015071 };
15072 VkAttachmentReference color = {
15073 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15074 };
15075 VkAttachmentReference input = {
15076 1, VK_IMAGE_LAYOUT_GENERAL,
15077 };
15078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015079 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015080
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015081 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015082 VkRenderPass rp;
15083 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15084 ASSERT_VK_SUCCESS(err);
15085
15086 // error here.
15087 pipe.CreateVKPipeline(pl, rp);
15088
15089 m_errorMonitor->VerifyFound();
15090
15091 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15092 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15093 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15094}
15095
Chris Forbes541f7b02016-08-22 15:30:27 +120015096TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015097 TEST_DESCRIPTION(
15098 "Test that an error is produced for a shader consuming an input attachment "
15099 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015101 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015102
15103 ASSERT_NO_FATAL_FAILURE(InitState());
15104
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015105 char const *vsSource =
15106 "#version 450\n"
15107 "\n"
15108 "out gl_PerVertex {\n"
15109 " vec4 gl_Position;\n"
15110 "};\n"
15111 "void main(){\n"
15112 " gl_Position = vec4(1);\n"
15113 "}\n";
15114 char const *fsSource =
15115 "#version 450\n"
15116 "\n"
15117 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15118 "layout(location=0) out vec4 color;\n"
15119 "void main() {\n"
15120 " color = subpassLoad(xs[0]);\n"
15121 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015122
15123 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15124 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15125
15126 VkPipelineObj pipe(m_device);
15127 pipe.AddShader(&vs);
15128 pipe.AddShader(&fs);
15129 pipe.AddColorAttachment();
15130 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015132 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15133 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015134 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015135 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015136 ASSERT_VK_SUCCESS(err);
15137
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015138 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015139 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015140 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015141 ASSERT_VK_SUCCESS(err);
15142
15143 // error here.
15144 pipe.CreateVKPipeline(pl, renderPass());
15145
15146 m_errorMonitor->VerifyFound();
15147
15148 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15149 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15150}
15151
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015152TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015153 TEST_DESCRIPTION(
15154 "Test that an error is produced for a compute pipeline consuming a "
15155 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015156 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015157
15158 ASSERT_NO_FATAL_FAILURE(InitState());
15159
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015160 char const *csSource =
15161 "#version 450\n"
15162 "\n"
15163 "layout(local_size_x=1) in;\n"
15164 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15165 "void main(){\n"
15166 " x = vec4(1);\n"
15167 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015168
15169 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15170
15171 VkDescriptorSetObj descriptorSet(m_device);
15172 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015174 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15175 nullptr,
15176 0,
15177 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15178 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15179 descriptorSet.GetPipelineLayout(),
15180 VK_NULL_HANDLE,
15181 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015182
15183 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015184 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015185
15186 m_errorMonitor->VerifyFound();
15187
15188 if (err == VK_SUCCESS) {
15189 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15190 }
15191}
15192
Chris Forbes22a9b092016-07-19 14:34:05 +120015193TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015194 TEST_DESCRIPTION(
15195 "Test that an error is produced for a pipeline consuming a "
15196 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15198 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015199
15200 ASSERT_NO_FATAL_FAILURE(InitState());
15201
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015202 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15203 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015204 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015205 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015206 ASSERT_VK_SUCCESS(err);
15207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015208 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015209 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015210 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015211 ASSERT_VK_SUCCESS(err);
15212
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015213 char const *csSource =
15214 "#version 450\n"
15215 "\n"
15216 "layout(local_size_x=1) in;\n"
15217 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15218 "void main() {\n"
15219 " x.x = 1.0f;\n"
15220 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015221 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15222
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015223 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15224 nullptr,
15225 0,
15226 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15227 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15228 pl,
15229 VK_NULL_HANDLE,
15230 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015231
15232 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015233 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015234
15235 m_errorMonitor->VerifyFound();
15236
15237 if (err == VK_SUCCESS) {
15238 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15239 }
15240
15241 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15242 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15243}
15244
Chris Forbes50020592016-07-27 13:52:41 +120015245TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015246 TEST_DESCRIPTION(
15247 "Test that an error is produced when an image view type "
15248 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015249
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015250 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 +120015251
15252 ASSERT_NO_FATAL_FAILURE(InitState());
15253 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15254
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015255 char const *vsSource =
15256 "#version 450\n"
15257 "\n"
15258 "out gl_PerVertex { vec4 gl_Position; };\n"
15259 "void main() { gl_Position = vec4(0); }\n";
15260 char const *fsSource =
15261 "#version 450\n"
15262 "\n"
15263 "layout(set=0, binding=0) uniform sampler3D s;\n"
15264 "layout(location=0) out vec4 color;\n"
15265 "void main() {\n"
15266 " color = texture(s, vec3(0));\n"
15267 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015268 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15269 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15270
15271 VkPipelineObj pipe(m_device);
15272 pipe.AddShader(&vs);
15273 pipe.AddShader(&fs);
15274 pipe.AddColorAttachment();
15275
15276 VkTextureObj texture(m_device, nullptr);
15277 VkSamplerObj sampler(m_device);
15278
15279 VkDescriptorSetObj descriptorSet(m_device);
15280 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15281 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15282
15283 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15284 ASSERT_VK_SUCCESS(err);
15285
Tony Barbour552f6c02016-12-21 14:34:07 -070015286 m_commandBuffer->BeginCommandBuffer();
15287 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015288
15289 m_commandBuffer->BindPipeline(pipe);
15290 m_commandBuffer->BindDescriptorSet(descriptorSet);
15291
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015292 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015293 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015294 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015295 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15296
15297 // error produced here.
15298 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15299
15300 m_errorMonitor->VerifyFound();
15301
Tony Barbour552f6c02016-12-21 14:34:07 -070015302 m_commandBuffer->EndRenderPass();
15303 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015304}
15305
Chris Forbes5533bfc2016-07-27 14:12:34 +120015306TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015307 TEST_DESCRIPTION(
15308 "Test that an error is produced when a multisampled images "
15309 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015310
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015311 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015312
15313 ASSERT_NO_FATAL_FAILURE(InitState());
15314 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15315
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015316 char const *vsSource =
15317 "#version 450\n"
15318 "\n"
15319 "out gl_PerVertex { vec4 gl_Position; };\n"
15320 "void main() { gl_Position = vec4(0); }\n";
15321 char const *fsSource =
15322 "#version 450\n"
15323 "\n"
15324 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15325 "layout(location=0) out vec4 color;\n"
15326 "void main() {\n"
15327 " color = texelFetch(s, ivec2(0), 0);\n"
15328 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015329 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15330 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15331
15332 VkPipelineObj pipe(m_device);
15333 pipe.AddShader(&vs);
15334 pipe.AddShader(&fs);
15335 pipe.AddColorAttachment();
15336
15337 VkTextureObj texture(m_device, nullptr);
15338 VkSamplerObj sampler(m_device);
15339
15340 VkDescriptorSetObj descriptorSet(m_device);
15341 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15342 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15343
15344 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15345 ASSERT_VK_SUCCESS(err);
15346
Tony Barbour552f6c02016-12-21 14:34:07 -070015347 m_commandBuffer->BeginCommandBuffer();
15348 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015349
15350 m_commandBuffer->BindPipeline(pipe);
15351 m_commandBuffer->BindDescriptorSet(descriptorSet);
15352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015353 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015354 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015355 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015356 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15357
15358 // error produced here.
15359 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15360
15361 m_errorMonitor->VerifyFound();
15362
Tony Barbour552f6c02016-12-21 14:34:07 -070015363 m_commandBuffer->EndRenderPass();
15364 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015365}
15366
Mark Youngc48c4c12016-04-11 14:26:49 -060015367TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015368 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015369
15370 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015371
15372 // Create an image
15373 VkImage image;
15374
Karl Schultz6addd812016-02-02 17:17:23 -070015375 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15376 const int32_t tex_width = 32;
15377 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015378
15379 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015380 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15381 image_create_info.pNext = NULL;
15382 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15383 image_create_info.format = tex_format;
15384 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015385 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015386 image_create_info.extent.depth = 1;
15387 image_create_info.mipLevels = 1;
15388 image_create_info.arrayLayers = 1;
15389 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15390 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15391 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15392 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015393
15394 // Introduce error by sending down a bogus width extent
15395 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015396 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015397
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015398 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015399}
15400
Mark Youngc48c4c12016-04-11 14:26:49 -060015401TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015402 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015403
15404 ASSERT_NO_FATAL_FAILURE(InitState());
15405
15406 // Create an image
15407 VkImage image;
15408
15409 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15410 const int32_t tex_width = 32;
15411 const int32_t tex_height = 32;
15412
15413 VkImageCreateInfo image_create_info = {};
15414 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15415 image_create_info.pNext = NULL;
15416 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15417 image_create_info.format = tex_format;
15418 image_create_info.extent.width = tex_width;
15419 image_create_info.extent.height = tex_height;
15420 image_create_info.extent.depth = 1;
15421 image_create_info.mipLevels = 1;
15422 image_create_info.arrayLayers = 1;
15423 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15424 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15425 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15426 image_create_info.flags = 0;
15427
15428 // Introduce error by sending down a bogus width extent
15429 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015430 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015431 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15432
15433 m_errorMonitor->VerifyFound();
15434}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015435
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015436TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015437 TEST_DESCRIPTION(
15438 "Create a render pass with an attachment description "
15439 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015440
15441 ASSERT_NO_FATAL_FAILURE(InitState());
15442 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15443
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015445
15446 VkAttachmentReference color_attach = {};
15447 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15448 color_attach.attachment = 0;
15449 VkSubpassDescription subpass = {};
15450 subpass.colorAttachmentCount = 1;
15451 subpass.pColorAttachments = &color_attach;
15452
15453 VkRenderPassCreateInfo rpci = {};
15454 rpci.subpassCount = 1;
15455 rpci.pSubpasses = &subpass;
15456 rpci.attachmentCount = 1;
15457 VkAttachmentDescription attach_desc = {};
15458 attach_desc.format = VK_FORMAT_UNDEFINED;
15459 rpci.pAttachments = &attach_desc;
15460 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15461 VkRenderPass rp;
15462 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15463
15464 m_errorMonitor->VerifyFound();
15465
15466 if (result == VK_SUCCESS) {
15467 vkDestroyRenderPass(m_device->device(), rp, NULL);
15468 }
15469}
15470
Karl Schultz6addd812016-02-02 17:17:23 -070015471TEST_F(VkLayerTest, InvalidImageView) {
15472 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015473
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015475
Tobin Ehliscde08892015-09-22 10:11:37 -060015476 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015477
Mike Stroyana3082432015-09-25 13:39:21 -060015478 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015479 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015480
Karl Schultz6addd812016-02-02 17:17:23 -070015481 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15482 const int32_t tex_width = 32;
15483 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015484
15485 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015486 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15487 image_create_info.pNext = NULL;
15488 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15489 image_create_info.format = tex_format;
15490 image_create_info.extent.width = tex_width;
15491 image_create_info.extent.height = tex_height;
15492 image_create_info.extent.depth = 1;
15493 image_create_info.mipLevels = 1;
15494 image_create_info.arrayLayers = 1;
15495 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15496 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15497 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15498 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015499
Chia-I Wuf7458c52015-10-26 21:10:41 +080015500 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015501 ASSERT_VK_SUCCESS(err);
15502
15503 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015504 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015505 image_view_create_info.image = image;
15506 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15507 image_view_create_info.format = tex_format;
15508 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015509 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015510 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015511 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015512
15513 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015514 m_errorMonitor->SetUnexpectedError(
15515 "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 -060015516 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015517
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015518 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015519 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015520}
Mike Stroyana3082432015-09-25 13:39:21 -060015521
Mark Youngd339ba32016-05-30 13:28:35 -060015522TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15523 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015524 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015525 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015526
15527 ASSERT_NO_FATAL_FAILURE(InitState());
15528
15529 // Create an image and try to create a view with no memory backing the image
15530 VkImage image;
15531
15532 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15533 const int32_t tex_width = 32;
15534 const int32_t tex_height = 32;
15535
15536 VkImageCreateInfo image_create_info = {};
15537 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15538 image_create_info.pNext = NULL;
15539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15540 image_create_info.format = tex_format;
15541 image_create_info.extent.width = tex_width;
15542 image_create_info.extent.height = tex_height;
15543 image_create_info.extent.depth = 1;
15544 image_create_info.mipLevels = 1;
15545 image_create_info.arrayLayers = 1;
15546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15547 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15548 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15549 image_create_info.flags = 0;
15550
15551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15552 ASSERT_VK_SUCCESS(err);
15553
15554 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015555 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015556 image_view_create_info.image = image;
15557 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15558 image_view_create_info.format = tex_format;
15559 image_view_create_info.subresourceRange.layerCount = 1;
15560 image_view_create_info.subresourceRange.baseMipLevel = 0;
15561 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015562 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015563
15564 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015565 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015566
15567 m_errorMonitor->VerifyFound();
15568 vkDestroyImage(m_device->device(), image, NULL);
15569 // If last error is success, it still created the view, so delete it.
15570 if (err == VK_SUCCESS) {
15571 vkDestroyImageView(m_device->device(), view, NULL);
15572 }
Mark Youngd339ba32016-05-30 13:28:35 -060015573}
15574
Karl Schultz6addd812016-02-02 17:17:23 -070015575TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015576 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015578
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015579 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015580
Karl Schultz6addd812016-02-02 17:17:23 -070015581 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015582 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015583 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015584 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015585
15586 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015587 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015588 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015589 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15590 image_view_create_info.format = tex_format;
15591 image_view_create_info.subresourceRange.baseMipLevel = 0;
15592 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015593 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015594 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015595 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015596
15597 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015598 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015599
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015600 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015601}
15602
Mike Weiblena1e13f42017-02-09 21:25:59 -070015603TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15604 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15605
15606 ASSERT_NO_FATAL_FAILURE(InitState());
15607 VkSubresourceLayout subres_layout = {};
15608
15609 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15610 {
15611 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15612 VkImageObj img(m_device);
15613 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15614 ASSERT_TRUE(img.initialized());
15615
15616 VkImageSubresource subres = {};
15617 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15618 subres.mipLevel = 0;
15619 subres.arrayLayer = 0;
15620
15621 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15622 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15623 m_errorMonitor->VerifyFound();
15624 }
15625
15626 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15627 {
15628 VkImageObj img(m_device);
15629 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15630 ASSERT_TRUE(img.initialized());
15631
15632 VkImageSubresource subres = {};
15633 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15634 subres.mipLevel = 0;
15635 subres.arrayLayer = 0;
15636
15637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15639 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15640 m_errorMonitor->VerifyFound();
15641 }
15642
15643 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15644 {
15645 VkImageObj img(m_device);
15646 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15647 ASSERT_TRUE(img.initialized());
15648
15649 VkImageSubresource subres = {};
15650 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15651 subres.mipLevel = 1; // ERROR: triggers VU 00739
15652 subres.arrayLayer = 0;
15653
15654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15655 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15656 m_errorMonitor->VerifyFound();
15657 }
15658
15659 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15660 {
15661 VkImageObj img(m_device);
15662 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15663 ASSERT_TRUE(img.initialized());
15664
15665 VkImageSubresource subres = {};
15666 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15667 subres.mipLevel = 0;
15668 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15669
15670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15671 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15672 m_errorMonitor->VerifyFound();
15673 }
15674}
15675
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015676TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015677 VkResult err;
15678 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015679
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015681
Mike Stroyana3082432015-09-25 13:39:21 -060015682 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015683
15684 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015685 VkImage srcImage;
15686 VkImage dstImage;
15687 VkDeviceMemory srcMem;
15688 VkDeviceMemory destMem;
15689 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015690
15691 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015692 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15693 image_create_info.pNext = NULL;
15694 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15695 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15696 image_create_info.extent.width = 32;
15697 image_create_info.extent.height = 32;
15698 image_create_info.extent.depth = 1;
15699 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015700 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015701 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15702 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15703 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15704 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015705
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015706 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015707 ASSERT_VK_SUCCESS(err);
15708
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015709 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015710 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015711 ASSERT_VK_SUCCESS(err);
15712
15713 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015714 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015715 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15716 memAlloc.pNext = NULL;
15717 memAlloc.allocationSize = 0;
15718 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015719
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015720 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015721 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015722 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015723 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015724 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015725 ASSERT_VK_SUCCESS(err);
15726
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015727 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015728 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015729 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015730 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015731 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015732 ASSERT_VK_SUCCESS(err);
15733
15734 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15735 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015736 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015737 ASSERT_VK_SUCCESS(err);
15738
Tony Barbour552f6c02016-12-21 14:34:07 -070015739 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015740 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015741 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015742 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015743 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015744 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015745 copyRegion.srcOffset.x = 0;
15746 copyRegion.srcOffset.y = 0;
15747 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015748 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015749 copyRegion.dstSubresource.mipLevel = 0;
15750 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015751 // Introduce failure by forcing the dst layerCount to differ from src
15752 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015753 copyRegion.dstOffset.x = 0;
15754 copyRegion.dstOffset.y = 0;
15755 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015756 copyRegion.extent.width = 1;
15757 copyRegion.extent.height = 1;
15758 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015759 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015760 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015761
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015762 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015763
Chia-I Wuf7458c52015-10-26 21:10:41 +080015764 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015765 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015766 vkFreeMemory(m_device->device(), srcMem, NULL);
15767 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015768}
15769
Tony Barbourd6673642016-05-05 14:46:39 -060015770TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015771 TEST_DESCRIPTION("Creating images with unsuported formats ");
15772
15773 ASSERT_NO_FATAL_FAILURE(InitState());
15774 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15775 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015776 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 -060015777 VK_IMAGE_TILING_OPTIMAL, 0);
15778 ASSERT_TRUE(image.initialized());
15779
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015780 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015781 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015782 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015783 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15784 image_create_info.format = VK_FORMAT_UNDEFINED;
15785 image_create_info.extent.width = 32;
15786 image_create_info.extent.height = 32;
15787 image_create_info.extent.depth = 1;
15788 image_create_info.mipLevels = 1;
15789 image_create_info.arrayLayers = 1;
15790 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15791 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15792 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015793
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15795 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015796
15797 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015798 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15799 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15800 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15801 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015802 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15803 m_errorMonitor->VerifyFound();
15804
Tony Barbourd6673642016-05-05 14:46:39 -060015805 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015806 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015807 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15808 VkFormat format = static_cast<VkFormat>(f);
15809 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015810 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015811 unsupported = format;
15812 break;
15813 }
15814 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015815
Tony Barbourd6673642016-05-05 14:46:39 -060015816 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015817 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015819
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015820 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15821 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15822 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15823 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15824 m_errorMonitor->SetUnexpectedError(
15825 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15826 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15827 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015828 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015829 m_errorMonitor->VerifyFound();
15830 }
15831}
15832
15833TEST_F(VkLayerTest, ImageLayerViewTests) {
15834 VkResult ret;
15835 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15836
15837 ASSERT_NO_FATAL_FAILURE(InitState());
15838
15839 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015840 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 -060015841 VK_IMAGE_TILING_OPTIMAL, 0);
15842 ASSERT_TRUE(image.initialized());
15843
15844 VkImageView imgView;
15845 VkImageViewCreateInfo imgViewInfo = {};
15846 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15847 imgViewInfo.image = image.handle();
15848 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15849 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15850 imgViewInfo.subresourceRange.layerCount = 1;
15851 imgViewInfo.subresourceRange.baseMipLevel = 0;
15852 imgViewInfo.subresourceRange.levelCount = 1;
15853 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15854
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015856 // View can't have baseMipLevel >= image's mipLevels - Expect
15857 // VIEW_CREATE_ERROR
15858 imgViewInfo.subresourceRange.baseMipLevel = 1;
15859 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15860 m_errorMonitor->VerifyFound();
15861 imgViewInfo.subresourceRange.baseMipLevel = 0;
15862
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015864 // View can't have baseArrayLayer >= image's arraySize - Expect
15865 // VIEW_CREATE_ERROR
15866 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15867 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15868 m_errorMonitor->VerifyFound();
15869 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15870
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015872 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15873 imgViewInfo.subresourceRange.levelCount = 0;
15874 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15875 m_errorMonitor->VerifyFound();
15876 imgViewInfo.subresourceRange.levelCount = 1;
15877
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015878 m_errorMonitor->SetDesiredFailureMsg(
15879 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15880 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015881 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15882 imgViewInfo.subresourceRange.layerCount = 0;
15883 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15884 m_errorMonitor->VerifyFound();
15885 imgViewInfo.subresourceRange.layerCount = 1;
15886
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15888 "Formats MUST be IDENTICAL unless "
15889 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15890 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015891 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15892 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15893 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15894 m_errorMonitor->VerifyFound();
15895 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15896
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015898 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15899 // VIEW_CREATE_ERROR
15900 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15901 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15902 m_errorMonitor->VerifyFound();
15903 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15904
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015906 // TODO: Update framework to easily passing mutable flag into ImageObj init
15907 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015908 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15909 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15910 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015911 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15912 // VIEW_CREATE_ERROR
15913 VkImageCreateInfo mutImgInfo = image.create_info();
15914 VkImage mutImage;
15915 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015916 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015917 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15918 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15919 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15920 ASSERT_VK_SUCCESS(ret);
15921 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015922 m_errorMonitor->SetUnexpectedError(
15923 "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 -060015924 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15925 m_errorMonitor->VerifyFound();
15926 imgViewInfo.image = image.handle();
15927 vkDestroyImage(m_device->handle(), mutImage, NULL);
15928}
15929
Dave Houlton59a20702017-02-02 17:26:23 -070015930TEST_F(VkLayerTest, ImageBufferCopyTests) {
15931 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15932
15933 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070015934
15935 // Bail if any dimension of transfer granularity is 0.
15936 auto index = m_device->graphics_queue_node_index_;
15937 auto queue_family_properties = m_device->phy().queue_properties();
15938 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
15939 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
15940 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
15941 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
15942 return;
15943 }
15944
Dave Houlton59a20702017-02-02 17:26:23 -070015945 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15946 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15947 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070015948 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
15949 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
15950 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
15951 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
15952
Dave Houlton59a20702017-02-02 17:26:23 -070015953 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15954 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15955 VK_IMAGE_TILING_OPTIMAL, 0);
15956 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15957 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15958 VK_IMAGE_TILING_OPTIMAL, 0);
15959 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15960 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070015961 ASSERT_TRUE(image_64k.initialized());
15962 ASSERT_TRUE(image_16k.initialized());
15963 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070015964
Dave Houltonf3229d52017-02-21 15:59:08 -070015965 // Verify all needed Depth/Stencil formats are supported
15966 bool missing_ds_support = false;
15967 VkFormatProperties props = {0, 0, 0};
15968 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
15969 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15970 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
15971 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15972 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
15973 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15974 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
15975 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15976
15977 if (!missing_ds_support) {
15978 ds_image_4D_1S.init(
15979 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
15980 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15981 VK_IMAGE_TILING_OPTIMAL, 0);
15982 ASSERT_TRUE(ds_image_4D_1S.initialized());
15983
15984 ds_image_3D_1S.init(
15985 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
15986 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15987 VK_IMAGE_TILING_OPTIMAL, 0);
15988 ASSERT_TRUE(ds_image_3D_1S.initialized());
15989
15990 ds_image_2D.init(
15991 256, 256, VK_FORMAT_D16_UNORM,
15992 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15993 VK_IMAGE_TILING_OPTIMAL, 0);
15994 ASSERT_TRUE(ds_image_2D.initialized());
15995
15996 ds_image_1S.init(
15997 256, 256, VK_FORMAT_S8_UINT,
15998 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
15999 VK_IMAGE_TILING_OPTIMAL, 0);
16000 ASSERT_TRUE(ds_image_1S.initialized());
16001 }
16002
16003 // Allocate buffers
16004 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016005 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016006 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16007 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16008 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16009 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016010
16011 VkBufferImageCopy region = {};
16012 region.bufferRowLength = 0;
16013 region.bufferImageHeight = 0;
16014 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16015 region.imageSubresource.layerCount = 1;
16016 region.imageOffset = {0, 0, 0};
16017 region.imageExtent = {64, 64, 1};
16018 region.bufferOffset = 0;
16019
16020 // attempt copies before putting command buffer in recording state
16021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16022 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16023 &region);
16024 m_errorMonitor->VerifyFound();
16025
16026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16027 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16028 &region);
16029 m_errorMonitor->VerifyFound();
16030
16031 // start recording
16032 m_commandBuffer->BeginCommandBuffer();
16033
16034 // successful copies
16035 m_errorMonitor->ExpectSuccess();
16036 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16037 &region);
16038 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16039 &region);
16040 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16041 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16042 &region);
16043 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16044 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16045 &region);
16046 region.imageOffset.x = 0;
16047 region.imageExtent.height = 64;
16048 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16049 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16050 &region);
16051 m_errorMonitor->VerifyNotFound();
16052
16053 // image/buffer too small (extent) on copy to image
16054 region.imageExtent = {65, 64, 1};
16055 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16056 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16057 &region);
16058 m_errorMonitor->VerifyFound();
16059
16060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16061 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16062 &region);
16063 m_errorMonitor->VerifyFound();
16064
16065 // image/buffer too small (offset) on copy to image
16066 region.imageExtent = {64, 64, 1};
16067 region.imageOffset = {0, 4, 0};
16068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16069 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16070 &region);
16071 m_errorMonitor->VerifyFound();
16072
16073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16074 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16075 &region);
16076 m_errorMonitor->VerifyFound();
16077
16078 // image/buffer too small on copy to buffer
16079 region.imageExtent = {64, 64, 1};
16080 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016081 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16083 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16084 &region);
16085 m_errorMonitor->VerifyFound();
16086
16087 region.imageExtent = {64, 65, 1};
16088 region.bufferOffset = 0;
16089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16090 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16091 &region);
16092 m_errorMonitor->VerifyFound();
16093
16094 // buffer size ok but rowlength causes loose packing
16095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16096 region.imageExtent = {64, 64, 1};
16097 region.bufferRowLength = 68;
16098 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16099 &region);
16100 m_errorMonitor->VerifyFound();
16101
Dave Houlton59a20702017-02-02 17:26:23 -070016102 // aspect bits
16103 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16104 region.imageExtent = {64, 64, 1};
16105 region.bufferRowLength = 0;
16106 region.bufferImageHeight = 0;
16107 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16108 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16109 buffer_16k.handle(), 1, &region);
16110 m_errorMonitor->VerifyFound();
16111
16112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16113 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16114 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16115 &region);
16116 m_errorMonitor->VerifyFound();
16117
16118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16119 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16120 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16121 buffer_16k.handle(), 1, &region);
16122 m_errorMonitor->VerifyFound();
16123
Dave Houltonf3229d52017-02-21 15:59:08 -070016124 // Test Depth/Stencil copies
16125 if (missing_ds_support) {
16126 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16127 } else {
16128 VkBufferImageCopy ds_region = {};
16129 ds_region.bufferOffset = 0;
16130 ds_region.bufferRowLength = 0;
16131 ds_region.bufferImageHeight = 0;
16132 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16133 ds_region.imageSubresource.mipLevel = 0;
16134 ds_region.imageSubresource.baseArrayLayer = 0;
16135 ds_region.imageSubresource.layerCount = 1;
16136 ds_region.imageOffset = {0, 0, 0};
16137 ds_region.imageExtent = {256, 256, 1};
16138
16139 // Depth copies that should succeed
16140 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16141 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16142 buffer_256k.handle(), 1, &ds_region);
16143 m_errorMonitor->VerifyNotFound();
16144
16145 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16146 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16147 buffer_256k.handle(), 1, &ds_region);
16148 m_errorMonitor->VerifyNotFound();
16149
16150 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16151 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16152 buffer_128k.handle(), 1, &ds_region);
16153 m_errorMonitor->VerifyNotFound();
16154
16155 // Depth copies that should fail
16156 ds_region.bufferOffset = 4;
16157 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16158 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16159 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16160 buffer_256k.handle(), 1, &ds_region);
16161 m_errorMonitor->VerifyFound();
16162
16163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16164 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16165 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16166 buffer_256k.handle(), 1, &ds_region);
16167 m_errorMonitor->VerifyFound();
16168
16169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16170 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16171 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16172 buffer_128k.handle(), 1, &ds_region);
16173 m_errorMonitor->VerifyFound();
16174
16175 // Stencil copies that should succeed
16176 ds_region.bufferOffset = 0;
16177 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16178 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16179 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16180 buffer_64k.handle(), 1, &ds_region);
16181 m_errorMonitor->VerifyNotFound();
16182
16183 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16184 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16185 buffer_64k.handle(), 1, &ds_region);
16186 m_errorMonitor->VerifyNotFound();
16187
16188 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16189 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16190 buffer_64k.handle(), 1, &ds_region);
16191 m_errorMonitor->VerifyNotFound();
16192
16193 // Stencil copies that should fail
16194 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16195 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16196 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16197 buffer_16k.handle(), 1, &ds_region);
16198 m_errorMonitor->VerifyFound();
16199
16200 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16201 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16202 ds_region.bufferRowLength = 260;
16203 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16204 buffer_64k.handle(), 1, &ds_region);
16205 m_errorMonitor->VerifyFound();
16206
16207 ds_region.bufferRowLength = 0;
16208 ds_region.bufferOffset = 4;
16209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16210 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16211 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16212 buffer_64k.handle(), 1, &ds_region);
16213 m_errorMonitor->VerifyFound();
16214 }
16215
Dave Houlton584d51e2017-02-16 12:52:54 -070016216 // Test compressed formats, if supported
16217 VkPhysicalDeviceFeatures device_features;
16218 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016219 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16220 device_features.textureCompressionASTC_LDR)) {
16221 printf(" No compressed formats supported - block compression tests skipped.\n");
16222 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070016223 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16224 if (device_features.textureCompressionBC) {
16225 image_16k_4x4comp.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16226 } else if (device_features.textureCompressionETC2) {
16227 image_16k_4x4comp.init(32, 32, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16228 VK_IMAGE_TILING_OPTIMAL, 0);
16229 } else {
16230 image_16k_4x4comp.init(32, 32, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16231 0);
16232 }
16233 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016234
Dave Houlton584d51e2017-02-16 12:52:54 -070016235 // Just fits
16236 m_errorMonitor->ExpectSuccess();
16237 region.imageExtent = {128, 128, 1};
16238 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16239 buffer_16k.handle(), 1, &region);
16240 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016241
Dave Houlton584d51e2017-02-16 12:52:54 -070016242 // with offset, too big for buffer
16243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16244 region.bufferOffset = 16;
16245 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16246 buffer_16k.handle(), 1, &region);
16247 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016248
Dave Houlton584d51e2017-02-16 12:52:54 -070016249 // buffer offset must be a multiple of texel block size (16)
16250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16252 region.imageExtent = {64, 64, 1};
16253 region.bufferOffset = 24;
16254 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16255 buffer_16k.handle(), 1, &region);
16256 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016257
Dave Houlton584d51e2017-02-16 12:52:54 -070016258 // rowlength not a multiple of block width (4)
16259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16260 region.bufferOffset = 0;
16261 region.bufferRowLength = 130;
16262 region.bufferImageHeight = 0;
16263 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16264 buffer_64k.handle(), 1, &region);
16265 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016266
Dave Houlton584d51e2017-02-16 12:52:54 -070016267 // imageheight not a multiple of block height (4)
16268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16269 region.bufferRowLength = 0;
16270 region.bufferImageHeight = 130;
16271 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16272 buffer_64k.handle(), 1, &region);
16273 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016274
Dave Houlton584d51e2017-02-16 12:52:54 -070016275 // image extents must be multiple of block dimensions (4x4)
16276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16277 region.bufferImageHeight = 0;
16278 region.imageOffset = {4, 6, 0};
16279 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16280 buffer_64k.handle(), 1, &region);
16281 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016282
Dave Houlton584d51e2017-02-16 12:52:54 -070016283 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16284 region.imageOffset = {22, 0, 0};
16285 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16286 buffer_64k.handle(), 1, &region);
16287 m_errorMonitor->VerifyFound();
16288 }
Dave Houlton59a20702017-02-02 17:26:23 -070016289}
16290
Tony Barbourd6673642016-05-05 14:46:39 -060016291TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016292 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016293
16294 ASSERT_NO_FATAL_FAILURE(InitState());
16295
Rene Lindsay135204f2016-12-22 17:11:09 -070016296 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016297 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016298 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 -070016299 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016300 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016301 vk_testing::Buffer buffer;
16302 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016303 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016304 VkBufferImageCopy region = {};
16305 region.bufferRowLength = 128;
16306 region.bufferImageHeight = 128;
16307 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16308 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016309 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016310 region.imageExtent.height = 4;
16311 region.imageExtent.width = 4;
16312 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016313
16314 VkImageObj image2(m_device);
16315 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 -070016316 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016317 ASSERT_TRUE(image2.initialized());
16318 vk_testing::Buffer buffer2;
16319 VkMemoryPropertyFlags reqs2 = 0;
16320 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16321 VkBufferImageCopy region2 = {};
16322 region2.bufferRowLength = 128;
16323 region2.bufferImageHeight = 128;
16324 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16325 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16326 region2.imageSubresource.layerCount = 1;
16327 region2.imageExtent.height = 4;
16328 region2.imageExtent.width = 4;
16329 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016330 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016331
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016332 // Image must have offset.z of 0 and extent.depth of 1
16333 // Introduce failure by setting imageExtent.depth to 0
16334 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016336 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016337 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016338 m_errorMonitor->VerifyFound();
16339
16340 region.imageExtent.depth = 1;
16341
16342 // Image must have offset.z of 0 and extent.depth of 1
16343 // Introduce failure by setting imageOffset.z to 4
16344 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016346 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016347 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016348 m_errorMonitor->VerifyFound();
16349
16350 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016351 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16352 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016353 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016354 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016355 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16356 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016357 m_errorMonitor->VerifyFound();
16358
16359 // BufferOffset must be a multiple of 4
16360 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016361 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016363 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16364 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016365 m_errorMonitor->VerifyFound();
16366
16367 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16368 region.bufferOffset = 0;
16369 region.imageExtent.height = 128;
16370 region.imageExtent.width = 128;
16371 // Introduce failure by setting bufferRowLength > 0 but less than width
16372 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016374 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16375 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016376 m_errorMonitor->VerifyFound();
16377
16378 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16379 region.bufferRowLength = 128;
16380 // Introduce failure by setting bufferRowHeight > 0 but less than height
16381 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016382 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016383 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16384 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016385 m_errorMonitor->VerifyFound();
16386
16387 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016388 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016389 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16390 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016391 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016392 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16393 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016394 VkImageBlit blitRegion = {};
16395 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16396 blitRegion.srcSubresource.baseArrayLayer = 0;
16397 blitRegion.srcSubresource.layerCount = 1;
16398 blitRegion.srcSubresource.mipLevel = 0;
16399 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16400 blitRegion.dstSubresource.baseArrayLayer = 0;
16401 blitRegion.dstSubresource.layerCount = 1;
16402 blitRegion.dstSubresource.mipLevel = 0;
16403
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016404 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016406 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016407 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16408 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016409 m_errorMonitor->VerifyFound();
16410
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016412 VkImageMemoryBarrier img_barrier;
16413 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16414 img_barrier.pNext = NULL;
16415 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16416 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16417 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16418 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16419 img_barrier.image = image.handle();
16420 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16421 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16422 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16423 img_barrier.subresourceRange.baseArrayLayer = 0;
16424 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016425 img_barrier.subresourceRange.layerCount = 0;
16426 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016427 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16428 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016429 m_errorMonitor->VerifyFound();
16430 img_barrier.subresourceRange.layerCount = 1;
16431}
16432
16433TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016434 TEST_DESCRIPTION("Exceed the limits of image format ");
16435
Cody Northropc31a84f2016-08-22 10:41:47 -060016436 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016438 VkImageCreateInfo image_create_info = {};
16439 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16440 image_create_info.pNext = NULL;
16441 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16442 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16443 image_create_info.extent.width = 32;
16444 image_create_info.extent.height = 32;
16445 image_create_info.extent.depth = 1;
16446 image_create_info.mipLevels = 1;
16447 image_create_info.arrayLayers = 1;
16448 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16449 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16450 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16451 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16452 image_create_info.flags = 0;
16453
16454 VkImage nullImg;
16455 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016456 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16457 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016458 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016459 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16460 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16461 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016462 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016463
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016465 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16466 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16467 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16468 m_errorMonitor->VerifyFound();
16469 image_create_info.mipLevels = 1;
16470
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016472 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16473 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16474 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16475 m_errorMonitor->VerifyFound();
16476 image_create_info.arrayLayers = 1;
16477
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016479 int samples = imgFmtProps.sampleCounts >> 1;
16480 image_create_info.samples = (VkSampleCountFlagBits)samples;
16481 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16482 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16483 m_errorMonitor->VerifyFound();
16484 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16485
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16487 "pCreateInfo->initialLayout, must be "
16488 "VK_IMAGE_LAYOUT_UNDEFINED or "
16489 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016490 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16491 // Expect INVALID_LAYOUT
16492 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16493 m_errorMonitor->VerifyFound();
16494 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16495}
16496
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016497TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016498 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016500
16501 ASSERT_NO_FATAL_FAILURE(InitState());
16502
16503 VkImageObj src_image(m_device);
16504 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16505 VkImageObj dst_image(m_device);
16506 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16507
Tony Barbour552f6c02016-12-21 14:34:07 -070016508 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016509 VkImageCopy copy_region;
16510 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16511 copy_region.srcSubresource.mipLevel = 0;
16512 copy_region.srcSubresource.baseArrayLayer = 0;
16513 copy_region.srcSubresource.layerCount = 0;
16514 copy_region.srcOffset.x = 0;
16515 copy_region.srcOffset.y = 0;
16516 copy_region.srcOffset.z = 0;
16517 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16518 copy_region.dstSubresource.mipLevel = 0;
16519 copy_region.dstSubresource.baseArrayLayer = 0;
16520 copy_region.dstSubresource.layerCount = 0;
16521 copy_region.dstOffset.x = 0;
16522 copy_region.dstOffset.y = 0;
16523 copy_region.dstOffset.z = 0;
16524 copy_region.extent.width = 64;
16525 copy_region.extent.height = 64;
16526 copy_region.extent.depth = 1;
16527 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16528 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016529 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016530
16531 m_errorMonitor->VerifyFound();
16532}
16533
16534TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016535 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016537
16538 ASSERT_NO_FATAL_FAILURE(InitState());
16539
16540 VkImageObj src_image(m_device);
16541 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16542 VkImageObj dst_image(m_device);
16543 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16544
Tony Barbour552f6c02016-12-21 14:34:07 -070016545 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016546 VkImageCopy copy_region;
16547 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16548 copy_region.srcSubresource.mipLevel = 0;
16549 copy_region.srcSubresource.baseArrayLayer = 0;
16550 copy_region.srcSubresource.layerCount = 0;
16551 copy_region.srcOffset.x = 0;
16552 copy_region.srcOffset.y = 0;
16553 copy_region.srcOffset.z = 0;
16554 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16555 copy_region.dstSubresource.mipLevel = 0;
16556 copy_region.dstSubresource.baseArrayLayer = 0;
16557 copy_region.dstSubresource.layerCount = 0;
16558 copy_region.dstOffset.x = 0;
16559 copy_region.dstOffset.y = 0;
16560 copy_region.dstOffset.z = 0;
16561 copy_region.extent.width = 64;
16562 copy_region.extent.height = 64;
16563 copy_region.extent.depth = 1;
16564 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16565 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016566 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016567
16568 m_errorMonitor->VerifyFound();
16569}
16570
Karl Schultz6addd812016-02-02 17:17:23 -070016571TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016572 VkResult err;
16573 bool pass;
16574
16575 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016577
16578 ASSERT_NO_FATAL_FAILURE(InitState());
16579
16580 // Create two images of different types and try to copy between them
16581 VkImage srcImage;
16582 VkImage dstImage;
16583 VkDeviceMemory srcMem;
16584 VkDeviceMemory destMem;
16585 VkMemoryRequirements memReqs;
16586
16587 VkImageCreateInfo image_create_info = {};
16588 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16589 image_create_info.pNext = NULL;
16590 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16591 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16592 image_create_info.extent.width = 32;
16593 image_create_info.extent.height = 32;
16594 image_create_info.extent.depth = 1;
16595 image_create_info.mipLevels = 1;
16596 image_create_info.arrayLayers = 1;
16597 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16598 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16599 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16600 image_create_info.flags = 0;
16601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016602 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016603 ASSERT_VK_SUCCESS(err);
16604
16605 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16606 // Introduce failure by creating second image with a different-sized format.
16607 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16608
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016609 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016610 ASSERT_VK_SUCCESS(err);
16611
16612 // Allocate memory
16613 VkMemoryAllocateInfo memAlloc = {};
16614 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16615 memAlloc.pNext = NULL;
16616 memAlloc.allocationSize = 0;
16617 memAlloc.memoryTypeIndex = 0;
16618
16619 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16620 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016621 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016622 ASSERT_TRUE(pass);
16623 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16624 ASSERT_VK_SUCCESS(err);
16625
16626 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16627 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016628 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016629 ASSERT_TRUE(pass);
16630 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16631 ASSERT_VK_SUCCESS(err);
16632
16633 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16634 ASSERT_VK_SUCCESS(err);
16635 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16636 ASSERT_VK_SUCCESS(err);
16637
Tony Barbour552f6c02016-12-21 14:34:07 -070016638 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016639 VkImageCopy copyRegion;
16640 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16641 copyRegion.srcSubresource.mipLevel = 0;
16642 copyRegion.srcSubresource.baseArrayLayer = 0;
16643 copyRegion.srcSubresource.layerCount = 0;
16644 copyRegion.srcOffset.x = 0;
16645 copyRegion.srcOffset.y = 0;
16646 copyRegion.srcOffset.z = 0;
16647 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16648 copyRegion.dstSubresource.mipLevel = 0;
16649 copyRegion.dstSubresource.baseArrayLayer = 0;
16650 copyRegion.dstSubresource.layerCount = 0;
16651 copyRegion.dstOffset.x = 0;
16652 copyRegion.dstOffset.y = 0;
16653 copyRegion.dstOffset.z = 0;
16654 copyRegion.extent.width = 1;
16655 copyRegion.extent.height = 1;
16656 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016657 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016658 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016659
16660 m_errorMonitor->VerifyFound();
16661
16662 vkDestroyImage(m_device->device(), srcImage, NULL);
16663 vkDestroyImage(m_device->device(), dstImage, NULL);
16664 vkFreeMemory(m_device->device(), srcMem, NULL);
16665 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016666}
16667
Karl Schultz6addd812016-02-02 17:17:23 -070016668TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16669 VkResult err;
16670 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016671
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016672 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16674 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016675
Mike Stroyana3082432015-09-25 13:39:21 -060016676 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016677
16678 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016679 VkImage srcImage;
16680 VkImage dstImage;
16681 VkDeviceMemory srcMem;
16682 VkDeviceMemory destMem;
16683 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016684
16685 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016686 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16687 image_create_info.pNext = NULL;
16688 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16689 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16690 image_create_info.extent.width = 32;
16691 image_create_info.extent.height = 32;
16692 image_create_info.extent.depth = 1;
16693 image_create_info.mipLevels = 1;
16694 image_create_info.arrayLayers = 1;
16695 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16696 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16697 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16698 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016699
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016700 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016701 ASSERT_VK_SUCCESS(err);
16702
Karl Schultzbdb75952016-04-19 11:36:49 -060016703 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16704
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016705 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016706 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016707 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016708 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016709
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016710 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016711 ASSERT_VK_SUCCESS(err);
16712
16713 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016714 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016715 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16716 memAlloc.pNext = NULL;
16717 memAlloc.allocationSize = 0;
16718 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016719
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016720 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016721 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016722 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016723 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016724 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016725 ASSERT_VK_SUCCESS(err);
16726
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016727 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016728 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016729 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016730 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016731 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016732 ASSERT_VK_SUCCESS(err);
16733
16734 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16735 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016736 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016737 ASSERT_VK_SUCCESS(err);
16738
Tony Barbour552f6c02016-12-21 14:34:07 -070016739 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016740 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016741 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016742 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016743 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016744 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016745 copyRegion.srcOffset.x = 0;
16746 copyRegion.srcOffset.y = 0;
16747 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016748 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016749 copyRegion.dstSubresource.mipLevel = 0;
16750 copyRegion.dstSubresource.baseArrayLayer = 0;
16751 copyRegion.dstSubresource.layerCount = 0;
16752 copyRegion.dstOffset.x = 0;
16753 copyRegion.dstOffset.y = 0;
16754 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016755 copyRegion.extent.width = 1;
16756 copyRegion.extent.height = 1;
16757 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016758 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016759 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016760
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016761 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016762
Chia-I Wuf7458c52015-10-26 21:10:41 +080016763 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016764 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016765 vkFreeMemory(m_device->device(), srcMem, NULL);
16766 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016767}
16768
Karl Schultz6addd812016-02-02 17:17:23 -070016769TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16770 VkResult err;
16771 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016772
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16774 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016775
Mike Stroyana3082432015-09-25 13:39:21 -060016776 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016777
16778 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016779 VkImage srcImage;
16780 VkImage dstImage;
16781 VkDeviceMemory srcMem;
16782 VkDeviceMemory destMem;
16783 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016784
16785 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016786 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16787 image_create_info.pNext = NULL;
16788 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16789 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16790 image_create_info.extent.width = 32;
16791 image_create_info.extent.height = 1;
16792 image_create_info.extent.depth = 1;
16793 image_create_info.mipLevels = 1;
16794 image_create_info.arrayLayers = 1;
16795 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16796 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16797 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16798 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016799
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016800 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016801 ASSERT_VK_SUCCESS(err);
16802
Karl Schultz6addd812016-02-02 17:17:23 -070016803 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016804
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016805 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016806 ASSERT_VK_SUCCESS(err);
16807
16808 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016809 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016810 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16811 memAlloc.pNext = NULL;
16812 memAlloc.allocationSize = 0;
16813 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016814
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016815 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016816 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016817 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016818 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016819 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016820 ASSERT_VK_SUCCESS(err);
16821
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016822 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016823 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016824 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016825 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016826 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016827 ASSERT_VK_SUCCESS(err);
16828
16829 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16830 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016831 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016832 ASSERT_VK_SUCCESS(err);
16833
Tony Barbour552f6c02016-12-21 14:34:07 -070016834 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016835 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016836 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16837 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016838 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016839 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016840 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016841 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016842 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016843 resolveRegion.srcOffset.x = 0;
16844 resolveRegion.srcOffset.y = 0;
16845 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016846 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016847 resolveRegion.dstSubresource.mipLevel = 0;
16848 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016849 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016850 resolveRegion.dstOffset.x = 0;
16851 resolveRegion.dstOffset.y = 0;
16852 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016853 resolveRegion.extent.width = 1;
16854 resolveRegion.extent.height = 1;
16855 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016856 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016857 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016858
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016859 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016860
Chia-I Wuf7458c52015-10-26 21:10:41 +080016861 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016862 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016863 vkFreeMemory(m_device->device(), srcMem, NULL);
16864 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016865}
16866
Karl Schultz6addd812016-02-02 17:17:23 -070016867TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16868 VkResult err;
16869 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016870
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16872 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016873
Mike Stroyana3082432015-09-25 13:39:21 -060016874 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016875
Chris Forbesa7530692016-05-08 12:35:39 +120016876 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016877 VkImage srcImage;
16878 VkImage dstImage;
16879 VkDeviceMemory srcMem;
16880 VkDeviceMemory destMem;
16881 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016882
16883 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016884 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16885 image_create_info.pNext = NULL;
16886 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16887 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16888 image_create_info.extent.width = 32;
16889 image_create_info.extent.height = 1;
16890 image_create_info.extent.depth = 1;
16891 image_create_info.mipLevels = 1;
16892 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016893 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016894 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16895 // Note: Some implementations expect color attachment usage for any
16896 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016897 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016898 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016899
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016900 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016901 ASSERT_VK_SUCCESS(err);
16902
Karl Schultz6addd812016-02-02 17:17:23 -070016903 // Note: Some implementations expect color attachment usage for any
16904 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016905 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016906
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016907 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016908 ASSERT_VK_SUCCESS(err);
16909
16910 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016911 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016912 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16913 memAlloc.pNext = NULL;
16914 memAlloc.allocationSize = 0;
16915 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016916
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016917 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016918 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016919 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016920 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016921 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016922 ASSERT_VK_SUCCESS(err);
16923
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016924 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016925 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016926 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016927 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016928 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016929 ASSERT_VK_SUCCESS(err);
16930
16931 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16932 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016933 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016934 ASSERT_VK_SUCCESS(err);
16935
Tony Barbour552f6c02016-12-21 14:34:07 -070016936 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016937 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016938 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16939 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016940 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016941 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016942 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016943 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016944 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016945 resolveRegion.srcOffset.x = 0;
16946 resolveRegion.srcOffset.y = 0;
16947 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016948 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016949 resolveRegion.dstSubresource.mipLevel = 0;
16950 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016951 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016952 resolveRegion.dstOffset.x = 0;
16953 resolveRegion.dstOffset.y = 0;
16954 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016955 resolveRegion.extent.width = 1;
16956 resolveRegion.extent.height = 1;
16957 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016958 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016959 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016960
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016961 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016962
Chia-I Wuf7458c52015-10-26 21:10:41 +080016963 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016964 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016965 vkFreeMemory(m_device->device(), srcMem, NULL);
16966 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016967}
16968
Karl Schultz6addd812016-02-02 17:17:23 -070016969TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16970 VkResult err;
16971 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016972
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016973 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016974 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016975
Mike Stroyana3082432015-09-25 13:39:21 -060016976 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016977
16978 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016979 VkImage srcImage;
16980 VkImage dstImage;
16981 VkDeviceMemory srcMem;
16982 VkDeviceMemory destMem;
16983 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016984
16985 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016986 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16987 image_create_info.pNext = NULL;
16988 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16989 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16990 image_create_info.extent.width = 32;
16991 image_create_info.extent.height = 1;
16992 image_create_info.extent.depth = 1;
16993 image_create_info.mipLevels = 1;
16994 image_create_info.arrayLayers = 1;
16995 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
16996 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16997 // Note: Some implementations expect color attachment usage for any
16998 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016999 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017000 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017001
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017002 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017003 ASSERT_VK_SUCCESS(err);
17004
Karl Schultz6addd812016-02-02 17:17:23 -070017005 // Set format to something other than source image
17006 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17007 // Note: Some implementations expect color attachment usage for any
17008 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017009 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017010 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017011
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017012 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017013 ASSERT_VK_SUCCESS(err);
17014
17015 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017016 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017017 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17018 memAlloc.pNext = NULL;
17019 memAlloc.allocationSize = 0;
17020 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017021
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017022 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017023 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017025 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017026 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017027 ASSERT_VK_SUCCESS(err);
17028
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017029 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017030 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017031 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017032 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017033 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017034 ASSERT_VK_SUCCESS(err);
17035
17036 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17037 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017038 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017039 ASSERT_VK_SUCCESS(err);
17040
Tony Barbour552f6c02016-12-21 14:34:07 -070017041 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017042 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017043 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17044 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017045 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017046 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017047 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017048 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017049 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017050 resolveRegion.srcOffset.x = 0;
17051 resolveRegion.srcOffset.y = 0;
17052 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017053 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017054 resolveRegion.dstSubresource.mipLevel = 0;
17055 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017056 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017057 resolveRegion.dstOffset.x = 0;
17058 resolveRegion.dstOffset.y = 0;
17059 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017060 resolveRegion.extent.width = 1;
17061 resolveRegion.extent.height = 1;
17062 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017063 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017064 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017065
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017066 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017067
Chia-I Wuf7458c52015-10-26 21:10:41 +080017068 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017069 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017070 vkFreeMemory(m_device->device(), srcMem, NULL);
17071 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017072}
17073
Karl Schultz6addd812016-02-02 17:17:23 -070017074TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17075 VkResult err;
17076 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017077
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017079 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017080
Mike Stroyana3082432015-09-25 13:39:21 -060017081 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017082
17083 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017084 VkImage srcImage;
17085 VkImage dstImage;
17086 VkDeviceMemory srcMem;
17087 VkDeviceMemory destMem;
17088 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017089
17090 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017091 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17092 image_create_info.pNext = NULL;
17093 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17094 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17095 image_create_info.extent.width = 32;
17096 image_create_info.extent.height = 1;
17097 image_create_info.extent.depth = 1;
17098 image_create_info.mipLevels = 1;
17099 image_create_info.arrayLayers = 1;
17100 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17101 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17102 // Note: Some implementations expect color attachment usage for any
17103 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017104 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017105 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017106
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017107 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017108 ASSERT_VK_SUCCESS(err);
17109
Karl Schultz6addd812016-02-02 17:17:23 -070017110 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17111 // Note: Some implementations expect color attachment usage for any
17112 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017113 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017114 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017116 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017117 ASSERT_VK_SUCCESS(err);
17118
17119 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017120 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017121 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17122 memAlloc.pNext = NULL;
17123 memAlloc.allocationSize = 0;
17124 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017125
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017126 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017127 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017128 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017129 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017130 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017131 ASSERT_VK_SUCCESS(err);
17132
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017133 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017134 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017135 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017136 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017137 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017138 ASSERT_VK_SUCCESS(err);
17139
17140 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17141 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017142 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017143 ASSERT_VK_SUCCESS(err);
17144
Tony Barbour552f6c02016-12-21 14:34:07 -070017145 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017146 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017147 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17148 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017149 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017150 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017151 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017152 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017153 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017154 resolveRegion.srcOffset.x = 0;
17155 resolveRegion.srcOffset.y = 0;
17156 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017157 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017158 resolveRegion.dstSubresource.mipLevel = 0;
17159 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017160 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017161 resolveRegion.dstOffset.x = 0;
17162 resolveRegion.dstOffset.y = 0;
17163 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017164 resolveRegion.extent.width = 1;
17165 resolveRegion.extent.height = 1;
17166 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017167 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017168 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017169
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017170 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017171
Chia-I Wuf7458c52015-10-26 21:10:41 +080017172 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017173 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017174 vkFreeMemory(m_device->device(), srcMem, NULL);
17175 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017176}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017177
Karl Schultz6addd812016-02-02 17:17:23 -070017178TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017179 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017180 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17181 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017182 // The image format check comes 2nd in validation so we trigger it first,
17183 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017184 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17187 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017188
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017189 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017190
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017191 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017192 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17193 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017194
17195 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017196 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17197 ds_pool_ci.pNext = NULL;
17198 ds_pool_ci.maxSets = 1;
17199 ds_pool_ci.poolSizeCount = 1;
17200 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017201
17202 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017203 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017204 ASSERT_VK_SUCCESS(err);
17205
17206 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017207 dsl_binding.binding = 0;
17208 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17209 dsl_binding.descriptorCount = 1;
17210 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17211 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017212
17213 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017214 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17215 ds_layout_ci.pNext = NULL;
17216 ds_layout_ci.bindingCount = 1;
17217 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017218 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017219 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017220 ASSERT_VK_SUCCESS(err);
17221
17222 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017223 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017224 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017225 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017226 alloc_info.descriptorPool = ds_pool;
17227 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017228 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017229 ASSERT_VK_SUCCESS(err);
17230
Karl Schultz6addd812016-02-02 17:17:23 -070017231 VkImage image_bad;
17232 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017233 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017234 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017235 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017236 const int32_t tex_width = 32;
17237 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017238
17239 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017240 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17241 image_create_info.pNext = NULL;
17242 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17243 image_create_info.format = tex_format_bad;
17244 image_create_info.extent.width = tex_width;
17245 image_create_info.extent.height = tex_height;
17246 image_create_info.extent.depth = 1;
17247 image_create_info.mipLevels = 1;
17248 image_create_info.arrayLayers = 1;
17249 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17250 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017251 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017252 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017253
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017254 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017255 ASSERT_VK_SUCCESS(err);
17256 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017257 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17258 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017259 ASSERT_VK_SUCCESS(err);
17260
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017261 // ---Bind image memory---
17262 VkMemoryRequirements img_mem_reqs;
17263 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17264 VkMemoryAllocateInfo image_alloc_info = {};
17265 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17266 image_alloc_info.pNext = NULL;
17267 image_alloc_info.memoryTypeIndex = 0;
17268 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017269 bool pass =
17270 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 -070017271 ASSERT_TRUE(pass);
17272 VkDeviceMemory mem;
17273 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17274 ASSERT_VK_SUCCESS(err);
17275 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17276 ASSERT_VK_SUCCESS(err);
17277 // -----------------------
17278
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017279 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017280 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017281 image_view_create_info.image = image_bad;
17282 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17283 image_view_create_info.format = tex_format_bad;
17284 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17285 image_view_create_info.subresourceRange.baseMipLevel = 0;
17286 image_view_create_info.subresourceRange.layerCount = 1;
17287 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017288 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017289
17290 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017291 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017292
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017293 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017294
Chia-I Wuf7458c52015-10-26 21:10:41 +080017295 vkDestroyImage(m_device->device(), image_bad, NULL);
17296 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017297 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17298 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017299
17300 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017301}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017302
17303TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017304 TEST_DESCRIPTION(
17305 "Call ClearColorImage w/ a depth|stencil image and "
17306 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017307
17308 ASSERT_NO_FATAL_FAILURE(InitState());
17309 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17310
Tony Barbour552f6c02016-12-21 14:34:07 -070017311 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017312
17313 // Color image
17314 VkClearColorValue clear_color;
17315 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17316 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17317 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17318 const int32_t img_width = 32;
17319 const int32_t img_height = 32;
17320 VkImageCreateInfo image_create_info = {};
17321 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17322 image_create_info.pNext = NULL;
17323 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17324 image_create_info.format = color_format;
17325 image_create_info.extent.width = img_width;
17326 image_create_info.extent.height = img_height;
17327 image_create_info.extent.depth = 1;
17328 image_create_info.mipLevels = 1;
17329 image_create_info.arrayLayers = 1;
17330 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17331 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17332 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17333
17334 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017335 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017336
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017337 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017338
17339 // Depth/Stencil image
17340 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017341 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017342 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17343 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17344 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17345 ds_image_create_info.extent.width = 64;
17346 ds_image_create_info.extent.height = 64;
17347 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017348 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 -060017349
17350 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017351 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017353 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 -060017354
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017356
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017357 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017358 &color_range);
17359
17360 m_errorMonitor->VerifyFound();
17361
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017362 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17363 "vkCmdClearColorImage called with "
17364 "image created without "
17365 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017366
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017367 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017368 &color_range);
17369
17370 m_errorMonitor->VerifyFound();
17371
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017372 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17374 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017375
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017376 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17377 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017378
17379 m_errorMonitor->VerifyFound();
17380}
Tobin Ehliscde08892015-09-22 10:11:37 -060017381
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017382// WSI Enabled Tests
17383//
Chris Forbes09368e42016-10-13 11:59:22 +130017384#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017385TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17386
17387#if defined(VK_USE_PLATFORM_XCB_KHR)
17388 VkSurfaceKHR surface = VK_NULL_HANDLE;
17389
17390 VkResult err;
17391 bool pass;
17392 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17393 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17394 // uint32_t swapchain_image_count = 0;
17395 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17396 // uint32_t image_index = 0;
17397 // VkPresentInfoKHR present_info = {};
17398
17399 ASSERT_NO_FATAL_FAILURE(InitState());
17400
17401 // Use the create function from one of the VK_KHR_*_surface extension in
17402 // order to create a surface, testing all known errors in the process,
17403 // before successfully creating a surface:
17404 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17406 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17407 pass = (err != VK_SUCCESS);
17408 ASSERT_TRUE(pass);
17409 m_errorMonitor->VerifyFound();
17410
17411 // Next, try to create a surface with the wrong
17412 // VkXcbSurfaceCreateInfoKHR::sType:
17413 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17414 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17416 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17417 pass = (err != VK_SUCCESS);
17418 ASSERT_TRUE(pass);
17419 m_errorMonitor->VerifyFound();
17420
17421 // Create a native window, and then correctly create a surface:
17422 xcb_connection_t *connection;
17423 xcb_screen_t *screen;
17424 xcb_window_t xcb_window;
17425 xcb_intern_atom_reply_t *atom_wm_delete_window;
17426
17427 const xcb_setup_t *setup;
17428 xcb_screen_iterator_t iter;
17429 int scr;
17430 uint32_t value_mask, value_list[32];
17431 int width = 1;
17432 int height = 1;
17433
17434 connection = xcb_connect(NULL, &scr);
17435 ASSERT_TRUE(connection != NULL);
17436 setup = xcb_get_setup(connection);
17437 iter = xcb_setup_roots_iterator(setup);
17438 while (scr-- > 0)
17439 xcb_screen_next(&iter);
17440 screen = iter.data;
17441
17442 xcb_window = xcb_generate_id(connection);
17443
17444 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17445 value_list[0] = screen->black_pixel;
17446 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17447
17448 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17449 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17450
17451 /* Magic code that will send notification when window is destroyed */
17452 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17453 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17454
17455 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17456 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17457 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17458 free(reply);
17459
17460 xcb_map_window(connection, xcb_window);
17461
17462 // Force the x/y coordinates to 100,100 results are identical in consecutive
17463 // runs
17464 const uint32_t coords[] = { 100, 100 };
17465 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17466
17467 // Finally, try to correctly create a surface:
17468 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17469 xcb_create_info.pNext = NULL;
17470 xcb_create_info.flags = 0;
17471 xcb_create_info.connection = connection;
17472 xcb_create_info.window = xcb_window;
17473 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17474 pass = (err == VK_SUCCESS);
17475 ASSERT_TRUE(pass);
17476
17477 // Check if surface supports presentation:
17478
17479 // 1st, do so without having queried the queue families:
17480 VkBool32 supported = false;
17481 // TODO: Get the following error to come out:
17482 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17483 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17484 "function");
17485 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17486 pass = (err != VK_SUCCESS);
17487 // ASSERT_TRUE(pass);
17488 // m_errorMonitor->VerifyFound();
17489
17490 // Next, query a queue family index that's too large:
17491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17492 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17493 pass = (err != VK_SUCCESS);
17494 ASSERT_TRUE(pass);
17495 m_errorMonitor->VerifyFound();
17496
17497 // Finally, do so correctly:
17498 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17499 // SUPPORTED
17500 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17501 pass = (err == VK_SUCCESS);
17502 ASSERT_TRUE(pass);
17503
17504 // Before proceeding, try to create a swapchain without having called
17505 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17506 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17507 swapchain_create_info.pNext = NULL;
17508 swapchain_create_info.flags = 0;
17509 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17510 swapchain_create_info.surface = surface;
17511 swapchain_create_info.imageArrayLayers = 1;
17512 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17513 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17514 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17515 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17516 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17517 pass = (err != VK_SUCCESS);
17518 ASSERT_TRUE(pass);
17519 m_errorMonitor->VerifyFound();
17520
17521 // Get the surface capabilities:
17522 VkSurfaceCapabilitiesKHR surface_capabilities;
17523
17524 // Do so correctly (only error logged by this entrypoint is if the
17525 // extension isn't enabled):
17526 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17527 pass = (err == VK_SUCCESS);
17528 ASSERT_TRUE(pass);
17529
17530 // Get the surface formats:
17531 uint32_t surface_format_count;
17532
17533 // First, try without a pointer to surface_format_count:
17534 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17535 "specified as NULL");
17536 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17537 pass = (err == VK_SUCCESS);
17538 ASSERT_TRUE(pass);
17539 m_errorMonitor->VerifyFound();
17540
17541 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17542 // correctly done a 1st try (to get the count):
17543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17544 surface_format_count = 0;
17545 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_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 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17552 pass = (err == VK_SUCCESS);
17553 ASSERT_TRUE(pass);
17554
17555 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17556 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17557
17558 // Next, do a 2nd try with surface_format_count being set too high:
17559 surface_format_count += 5;
17560 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17561 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17562 pass = (err == VK_SUCCESS);
17563 ASSERT_TRUE(pass);
17564 m_errorMonitor->VerifyFound();
17565
17566 // Finally, do a correct 1st and 2nd try:
17567 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17568 pass = (err == VK_SUCCESS);
17569 ASSERT_TRUE(pass);
17570 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17571 pass = (err == VK_SUCCESS);
17572 ASSERT_TRUE(pass);
17573
17574 // Get the surface present modes:
17575 uint32_t surface_present_mode_count;
17576
17577 // First, try without a pointer to surface_format_count:
17578 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17579 "specified as NULL");
17580
17581 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17582 pass = (err == VK_SUCCESS);
17583 ASSERT_TRUE(pass);
17584 m_errorMonitor->VerifyFound();
17585
17586 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17587 // correctly done a 1st try (to get the count):
17588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17589 surface_present_mode_count = 0;
17590 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17591 (VkPresentModeKHR *)&surface_present_mode_count);
17592 pass = (err == VK_SUCCESS);
17593 ASSERT_TRUE(pass);
17594 m_errorMonitor->VerifyFound();
17595
17596 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17597 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17598 pass = (err == VK_SUCCESS);
17599 ASSERT_TRUE(pass);
17600
17601 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17602 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17603
17604 // Next, do a 2nd try with surface_format_count being set too high:
17605 surface_present_mode_count += 5;
17606 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17607 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17608 pass = (err == VK_SUCCESS);
17609 ASSERT_TRUE(pass);
17610 m_errorMonitor->VerifyFound();
17611
17612 // Finally, do a correct 1st and 2nd try:
17613 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17614 pass = (err == VK_SUCCESS);
17615 ASSERT_TRUE(pass);
17616 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17617 pass = (err == VK_SUCCESS);
17618 ASSERT_TRUE(pass);
17619
17620 // Create a swapchain:
17621
17622 // First, try without a pointer to swapchain_create_info:
17623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17624 "specified as NULL");
17625
17626 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17627 pass = (err != VK_SUCCESS);
17628 ASSERT_TRUE(pass);
17629 m_errorMonitor->VerifyFound();
17630
17631 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17632 // sType:
17633 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17635
17636 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17637 pass = (err != VK_SUCCESS);
17638 ASSERT_TRUE(pass);
17639 m_errorMonitor->VerifyFound();
17640
17641 // Next, call with a NULL swapchain pointer:
17642 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17643 swapchain_create_info.pNext = NULL;
17644 swapchain_create_info.flags = 0;
17645 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17646 "specified as NULL");
17647
17648 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17649 pass = (err != VK_SUCCESS);
17650 ASSERT_TRUE(pass);
17651 m_errorMonitor->VerifyFound();
17652
17653 // TODO: Enhance swapchain layer so that
17654 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17655
17656 // Next, call with a queue family index that's too large:
17657 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17658 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17659 swapchain_create_info.queueFamilyIndexCount = 2;
17660 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17662 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17663 pass = (err != VK_SUCCESS);
17664 ASSERT_TRUE(pass);
17665 m_errorMonitor->VerifyFound();
17666
17667 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17668 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17669 swapchain_create_info.queueFamilyIndexCount = 1;
17670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17671 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17672 "pCreateInfo->pQueueFamilyIndices).");
17673 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17674 pass = (err != VK_SUCCESS);
17675 ASSERT_TRUE(pass);
17676 m_errorMonitor->VerifyFound();
17677
17678 // Next, call with an invalid imageSharingMode:
17679 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17680 swapchain_create_info.queueFamilyIndexCount = 1;
17681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17682 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17683 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17684 pass = (err != VK_SUCCESS);
17685 ASSERT_TRUE(pass);
17686 m_errorMonitor->VerifyFound();
17687 // Fix for the future:
17688 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17689 // SUPPORTED
17690 swapchain_create_info.queueFamilyIndexCount = 0;
17691 queueFamilyIndex[0] = 0;
17692 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17693
17694 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17695 // Get the images from a swapchain:
17696 // Acquire an image from a swapchain:
17697 // Present an image to a swapchain:
17698 // Destroy the swapchain:
17699
17700 // TODOs:
17701 //
17702 // - Try destroying the device without first destroying the swapchain
17703 //
17704 // - Try destroying the device without first destroying the surface
17705 //
17706 // - Try destroying the surface without first destroying the swapchain
17707
17708 // Destroy the surface:
17709 vkDestroySurfaceKHR(instance(), surface, NULL);
17710
17711 // Tear down the window:
17712 xcb_destroy_window(connection, xcb_window);
17713 xcb_disconnect(connection);
17714
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017715#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017716 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017717#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017718}
Chris Forbes09368e42016-10-13 11:59:22 +130017719#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017720
17721//
17722// POSITIVE VALIDATION TESTS
17723//
17724// These tests do not expect to encounter ANY validation errors pass only if this is true
17725
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017726TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17727 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17728 ASSERT_NO_FATAL_FAILURE(InitState());
17729 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17730
17731 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17732 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17733 command_buffer_allocate_info.commandPool = m_commandPool;
17734 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17735 command_buffer_allocate_info.commandBufferCount = 1;
17736
17737 VkCommandBuffer secondary_command_buffer;
17738 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17739 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17740 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17741 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17742 command_buffer_inheritance_info.renderPass = m_renderPass;
17743 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17744
17745 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17746 command_buffer_begin_info.flags =
17747 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17748 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17749
17750 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17751 VkClearAttachment color_attachment;
17752 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17753 color_attachment.clearValue.color.float32[0] = 0;
17754 color_attachment.clearValue.color.float32[1] = 0;
17755 color_attachment.clearValue.color.float32[2] = 0;
17756 color_attachment.clearValue.color.float32[3] = 0;
17757 color_attachment.colorAttachment = 0;
17758 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17759 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17760}
17761
Tobin Ehlise0006882016-11-03 10:14:28 -060017762TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017763 TEST_DESCRIPTION(
17764 "Perform an image layout transition in a secondary command buffer followed "
17765 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017766 VkResult err;
17767 m_errorMonitor->ExpectSuccess();
17768 ASSERT_NO_FATAL_FAILURE(InitState());
17769 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17770 // Allocate a secondary and primary cmd buffer
17771 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17772 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17773 command_buffer_allocate_info.commandPool = m_commandPool;
17774 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17775 command_buffer_allocate_info.commandBufferCount = 1;
17776
17777 VkCommandBuffer secondary_command_buffer;
17778 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17779 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17780 VkCommandBuffer primary_command_buffer;
17781 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17782 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17783 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17784 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17785 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17786 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17787 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17788
17789 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17790 ASSERT_VK_SUCCESS(err);
17791 VkImageObj image(m_device);
17792 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17793 ASSERT_TRUE(image.initialized());
17794 VkImageMemoryBarrier img_barrier = {};
17795 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17796 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17797 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17798 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17799 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17800 img_barrier.image = image.handle();
17801 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17802 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17803 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17804 img_barrier.subresourceRange.baseArrayLayer = 0;
17805 img_barrier.subresourceRange.baseMipLevel = 0;
17806 img_barrier.subresourceRange.layerCount = 1;
17807 img_barrier.subresourceRange.levelCount = 1;
17808 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17809 0, nullptr, 1, &img_barrier);
17810 err = vkEndCommandBuffer(secondary_command_buffer);
17811 ASSERT_VK_SUCCESS(err);
17812
17813 // Now update primary cmd buffer to execute secondary and transitions image
17814 command_buffer_begin_info.pInheritanceInfo = nullptr;
17815 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17816 ASSERT_VK_SUCCESS(err);
17817 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17818 VkImageMemoryBarrier img_barrier2 = {};
17819 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17820 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17821 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17822 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17823 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17824 img_barrier2.image = image.handle();
17825 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17826 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17827 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17828 img_barrier2.subresourceRange.baseArrayLayer = 0;
17829 img_barrier2.subresourceRange.baseMipLevel = 0;
17830 img_barrier2.subresourceRange.layerCount = 1;
17831 img_barrier2.subresourceRange.levelCount = 1;
17832 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17833 nullptr, 1, &img_barrier2);
17834 err = vkEndCommandBuffer(primary_command_buffer);
17835 ASSERT_VK_SUCCESS(err);
17836 VkSubmitInfo submit_info = {};
17837 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17838 submit_info.commandBufferCount = 1;
17839 submit_info.pCommandBuffers = &primary_command_buffer;
17840 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17841 ASSERT_VK_SUCCESS(err);
17842 m_errorMonitor->VerifyNotFound();
17843 err = vkDeviceWaitIdle(m_device->device());
17844 ASSERT_VK_SUCCESS(err);
17845 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17846 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17847}
17848
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017849// This is a positive test. No failures are expected.
17850TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017851 TEST_DESCRIPTION(
17852 "Ensure that the vkUpdateDescriptorSets validation code "
17853 "is ignoring VkWriteDescriptorSet members that are not "
17854 "related to the descriptor type specified by "
17855 "VkWriteDescriptorSet::descriptorType. Correct "
17856 "validation behavior will result in the test running to "
17857 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017858
17859 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17860
17861 ASSERT_NO_FATAL_FAILURE(InitState());
17862
17863 // Image Case
17864 {
17865 m_errorMonitor->ExpectSuccess();
17866
17867 VkImage image;
17868 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17869 const int32_t tex_width = 32;
17870 const int32_t tex_height = 32;
17871 VkImageCreateInfo image_create_info = {};
17872 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17873 image_create_info.pNext = NULL;
17874 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17875 image_create_info.format = tex_format;
17876 image_create_info.extent.width = tex_width;
17877 image_create_info.extent.height = tex_height;
17878 image_create_info.extent.depth = 1;
17879 image_create_info.mipLevels = 1;
17880 image_create_info.arrayLayers = 1;
17881 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17882 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17883 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17884 image_create_info.flags = 0;
17885 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17886 ASSERT_VK_SUCCESS(err);
17887
17888 VkMemoryRequirements memory_reqs;
17889 VkDeviceMemory image_memory;
17890 bool pass;
17891 VkMemoryAllocateInfo memory_info = {};
17892 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17893 memory_info.pNext = NULL;
17894 memory_info.allocationSize = 0;
17895 memory_info.memoryTypeIndex = 0;
17896 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17897 memory_info.allocationSize = memory_reqs.size;
17898 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17899 ASSERT_TRUE(pass);
17900 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17901 ASSERT_VK_SUCCESS(err);
17902 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17903 ASSERT_VK_SUCCESS(err);
17904
17905 VkImageViewCreateInfo image_view_create_info = {};
17906 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17907 image_view_create_info.image = image;
17908 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17909 image_view_create_info.format = tex_format;
17910 image_view_create_info.subresourceRange.layerCount = 1;
17911 image_view_create_info.subresourceRange.baseMipLevel = 0;
17912 image_view_create_info.subresourceRange.levelCount = 1;
17913 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17914
17915 VkImageView view;
17916 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17917 ASSERT_VK_SUCCESS(err);
17918
17919 VkDescriptorPoolSize ds_type_count = {};
17920 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17921 ds_type_count.descriptorCount = 1;
17922
17923 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17924 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17925 ds_pool_ci.pNext = NULL;
17926 ds_pool_ci.maxSets = 1;
17927 ds_pool_ci.poolSizeCount = 1;
17928 ds_pool_ci.pPoolSizes = &ds_type_count;
17929
17930 VkDescriptorPool ds_pool;
17931 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17932 ASSERT_VK_SUCCESS(err);
17933
17934 VkDescriptorSetLayoutBinding dsl_binding = {};
17935 dsl_binding.binding = 0;
17936 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17937 dsl_binding.descriptorCount = 1;
17938 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17939 dsl_binding.pImmutableSamplers = NULL;
17940
17941 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17942 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17943 ds_layout_ci.pNext = NULL;
17944 ds_layout_ci.bindingCount = 1;
17945 ds_layout_ci.pBindings = &dsl_binding;
17946 VkDescriptorSetLayout ds_layout;
17947 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17948 ASSERT_VK_SUCCESS(err);
17949
17950 VkDescriptorSet descriptor_set;
17951 VkDescriptorSetAllocateInfo alloc_info = {};
17952 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17953 alloc_info.descriptorSetCount = 1;
17954 alloc_info.descriptorPool = ds_pool;
17955 alloc_info.pSetLayouts = &ds_layout;
17956 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17957 ASSERT_VK_SUCCESS(err);
17958
17959 VkDescriptorImageInfo image_info = {};
17960 image_info.imageView = view;
17961 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17962
17963 VkWriteDescriptorSet descriptor_write;
17964 memset(&descriptor_write, 0, sizeof(descriptor_write));
17965 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17966 descriptor_write.dstSet = descriptor_set;
17967 descriptor_write.dstBinding = 0;
17968 descriptor_write.descriptorCount = 1;
17969 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17970 descriptor_write.pImageInfo = &image_info;
17971
17972 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17973 // be
17974 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17975 // This will most likely produce a crash if the parameter_validation
17976 // layer
17977 // does not correctly ignore pBufferInfo.
17978 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17979 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17980
17981 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17982
17983 m_errorMonitor->VerifyNotFound();
17984
17985 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17986 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17987 vkDestroyImageView(m_device->device(), view, NULL);
17988 vkDestroyImage(m_device->device(), image, NULL);
17989 vkFreeMemory(m_device->device(), image_memory, NULL);
17990 }
17991
17992 // Buffer Case
17993 {
17994 m_errorMonitor->ExpectSuccess();
17995
17996 VkBuffer buffer;
17997 uint32_t queue_family_index = 0;
17998 VkBufferCreateInfo buffer_create_info = {};
17999 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18000 buffer_create_info.size = 1024;
18001 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18002 buffer_create_info.queueFamilyIndexCount = 1;
18003 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18004
18005 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18006 ASSERT_VK_SUCCESS(err);
18007
18008 VkMemoryRequirements memory_reqs;
18009 VkDeviceMemory buffer_memory;
18010 bool pass;
18011 VkMemoryAllocateInfo memory_info = {};
18012 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18013 memory_info.pNext = NULL;
18014 memory_info.allocationSize = 0;
18015 memory_info.memoryTypeIndex = 0;
18016
18017 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18018 memory_info.allocationSize = memory_reqs.size;
18019 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18020 ASSERT_TRUE(pass);
18021
18022 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18023 ASSERT_VK_SUCCESS(err);
18024 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18025 ASSERT_VK_SUCCESS(err);
18026
18027 VkDescriptorPoolSize ds_type_count = {};
18028 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18029 ds_type_count.descriptorCount = 1;
18030
18031 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18032 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18033 ds_pool_ci.pNext = NULL;
18034 ds_pool_ci.maxSets = 1;
18035 ds_pool_ci.poolSizeCount = 1;
18036 ds_pool_ci.pPoolSizes = &ds_type_count;
18037
18038 VkDescriptorPool ds_pool;
18039 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18040 ASSERT_VK_SUCCESS(err);
18041
18042 VkDescriptorSetLayoutBinding dsl_binding = {};
18043 dsl_binding.binding = 0;
18044 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18045 dsl_binding.descriptorCount = 1;
18046 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18047 dsl_binding.pImmutableSamplers = NULL;
18048
18049 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18050 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18051 ds_layout_ci.pNext = NULL;
18052 ds_layout_ci.bindingCount = 1;
18053 ds_layout_ci.pBindings = &dsl_binding;
18054 VkDescriptorSetLayout ds_layout;
18055 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18056 ASSERT_VK_SUCCESS(err);
18057
18058 VkDescriptorSet descriptor_set;
18059 VkDescriptorSetAllocateInfo alloc_info = {};
18060 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18061 alloc_info.descriptorSetCount = 1;
18062 alloc_info.descriptorPool = ds_pool;
18063 alloc_info.pSetLayouts = &ds_layout;
18064 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18065 ASSERT_VK_SUCCESS(err);
18066
18067 VkDescriptorBufferInfo buffer_info = {};
18068 buffer_info.buffer = buffer;
18069 buffer_info.offset = 0;
18070 buffer_info.range = 1024;
18071
18072 VkWriteDescriptorSet descriptor_write;
18073 memset(&descriptor_write, 0, sizeof(descriptor_write));
18074 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18075 descriptor_write.dstSet = descriptor_set;
18076 descriptor_write.dstBinding = 0;
18077 descriptor_write.descriptorCount = 1;
18078 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18079 descriptor_write.pBufferInfo = &buffer_info;
18080
18081 // Set pImageInfo and pTexelBufferView to invalid values, which should
18082 // be
18083 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18084 // This will most likely produce a crash if the parameter_validation
18085 // layer
18086 // does not correctly ignore pImageInfo.
18087 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18088 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18089
18090 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18091
18092 m_errorMonitor->VerifyNotFound();
18093
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018094 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18095 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18096 vkDestroyBuffer(m_device->device(), buffer, NULL);
18097 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18098 }
18099
18100 // Texel Buffer Case
18101 {
18102 m_errorMonitor->ExpectSuccess();
18103
18104 VkBuffer buffer;
18105 uint32_t queue_family_index = 0;
18106 VkBufferCreateInfo buffer_create_info = {};
18107 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18108 buffer_create_info.size = 1024;
18109 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18110 buffer_create_info.queueFamilyIndexCount = 1;
18111 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18112
18113 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18114 ASSERT_VK_SUCCESS(err);
18115
18116 VkMemoryRequirements memory_reqs;
18117 VkDeviceMemory buffer_memory;
18118 bool pass;
18119 VkMemoryAllocateInfo memory_info = {};
18120 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18121 memory_info.pNext = NULL;
18122 memory_info.allocationSize = 0;
18123 memory_info.memoryTypeIndex = 0;
18124
18125 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18126 memory_info.allocationSize = memory_reqs.size;
18127 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18128 ASSERT_TRUE(pass);
18129
18130 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18131 ASSERT_VK_SUCCESS(err);
18132 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18133 ASSERT_VK_SUCCESS(err);
18134
18135 VkBufferViewCreateInfo buff_view_ci = {};
18136 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18137 buff_view_ci.buffer = buffer;
18138 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18139 buff_view_ci.range = VK_WHOLE_SIZE;
18140 VkBufferView buffer_view;
18141 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18142
18143 VkDescriptorPoolSize ds_type_count = {};
18144 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18145 ds_type_count.descriptorCount = 1;
18146
18147 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18148 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18149 ds_pool_ci.pNext = NULL;
18150 ds_pool_ci.maxSets = 1;
18151 ds_pool_ci.poolSizeCount = 1;
18152 ds_pool_ci.pPoolSizes = &ds_type_count;
18153
18154 VkDescriptorPool ds_pool;
18155 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18156 ASSERT_VK_SUCCESS(err);
18157
18158 VkDescriptorSetLayoutBinding dsl_binding = {};
18159 dsl_binding.binding = 0;
18160 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18161 dsl_binding.descriptorCount = 1;
18162 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18163 dsl_binding.pImmutableSamplers = NULL;
18164
18165 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18166 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18167 ds_layout_ci.pNext = NULL;
18168 ds_layout_ci.bindingCount = 1;
18169 ds_layout_ci.pBindings = &dsl_binding;
18170 VkDescriptorSetLayout ds_layout;
18171 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18172 ASSERT_VK_SUCCESS(err);
18173
18174 VkDescriptorSet descriptor_set;
18175 VkDescriptorSetAllocateInfo alloc_info = {};
18176 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18177 alloc_info.descriptorSetCount = 1;
18178 alloc_info.descriptorPool = ds_pool;
18179 alloc_info.pSetLayouts = &ds_layout;
18180 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18181 ASSERT_VK_SUCCESS(err);
18182
18183 VkWriteDescriptorSet descriptor_write;
18184 memset(&descriptor_write, 0, sizeof(descriptor_write));
18185 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18186 descriptor_write.dstSet = descriptor_set;
18187 descriptor_write.dstBinding = 0;
18188 descriptor_write.descriptorCount = 1;
18189 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18190 descriptor_write.pTexelBufferView = &buffer_view;
18191
18192 // Set pImageInfo and pBufferInfo to invalid values, which should be
18193 // ignored for descriptorType ==
18194 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18195 // This will most likely produce a crash if the parameter_validation
18196 // layer
18197 // does not correctly ignore pImageInfo and pBufferInfo.
18198 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18199 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18200
18201 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18202
18203 m_errorMonitor->VerifyNotFound();
18204
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018205 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18206 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18207 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18208 vkDestroyBuffer(m_device->device(), buffer, NULL);
18209 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18210 }
18211}
18212
Tobin Ehlisf7428442016-10-25 07:58:24 -060018213TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18214 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18215
18216 ASSERT_NO_FATAL_FAILURE(InitState());
18217 // Create layout where two binding #s are "1"
18218 static const uint32_t NUM_BINDINGS = 3;
18219 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18220 dsl_binding[0].binding = 1;
18221 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18222 dsl_binding[0].descriptorCount = 1;
18223 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18224 dsl_binding[0].pImmutableSamplers = NULL;
18225 dsl_binding[1].binding = 0;
18226 dsl_binding[1].descriptorCount = 1;
18227 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18228 dsl_binding[1].descriptorCount = 1;
18229 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18230 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018231 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018232 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18233 dsl_binding[2].descriptorCount = 1;
18234 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18235 dsl_binding[2].pImmutableSamplers = NULL;
18236
18237 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18238 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18239 ds_layout_ci.pNext = NULL;
18240 ds_layout_ci.bindingCount = NUM_BINDINGS;
18241 ds_layout_ci.pBindings = dsl_binding;
18242 VkDescriptorSetLayout ds_layout;
18243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18244 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18245 m_errorMonitor->VerifyFound();
18246}
18247
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018248TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018249 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18250
18251 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018252
Tony Barbour552f6c02016-12-21 14:34:07 -070018253 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018254
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018255 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18256
18257 {
18258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18259 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18260 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18261 m_errorMonitor->VerifyFound();
18262 }
18263
18264 {
18265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18266 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18267 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18268 m_errorMonitor->VerifyFound();
18269 }
18270
18271 {
18272 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18273 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18274 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18275 m_errorMonitor->VerifyFound();
18276 }
18277
18278 {
18279 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18280 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18281 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18282 m_errorMonitor->VerifyFound();
18283 }
18284
18285 {
18286 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18287 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18288 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18289 m_errorMonitor->VerifyFound();
18290 }
18291
18292 {
18293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18294 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18295 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18296 m_errorMonitor->VerifyFound();
18297 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018298
18299 {
18300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18301 VkRect2D scissor = {{-1, 0}, {16, 16}};
18302 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18303 m_errorMonitor->VerifyFound();
18304 }
18305
18306 {
18307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18308 VkRect2D scissor = {{0, -2}, {16, 16}};
18309 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18310 m_errorMonitor->VerifyFound();
18311 }
18312
18313 {
18314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18315 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18316 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18317 m_errorMonitor->VerifyFound();
18318 }
18319
18320 {
18321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18322 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18323 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18324 m_errorMonitor->VerifyFound();
18325 }
18326
Tony Barbour552f6c02016-12-21 14:34:07 -070018327 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018328}
18329
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018330// This is a positive test. No failures are expected.
18331TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18332 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18333 VkResult err;
18334
18335 ASSERT_NO_FATAL_FAILURE(InitState());
18336 m_errorMonitor->ExpectSuccess();
18337 VkDescriptorPoolSize ds_type_count = {};
18338 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18339 ds_type_count.descriptorCount = 2;
18340
18341 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18342 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18343 ds_pool_ci.pNext = NULL;
18344 ds_pool_ci.maxSets = 1;
18345 ds_pool_ci.poolSizeCount = 1;
18346 ds_pool_ci.pPoolSizes = &ds_type_count;
18347
18348 VkDescriptorPool ds_pool;
18349 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18350 ASSERT_VK_SUCCESS(err);
18351
18352 // Create layout with two uniform buffer descriptors w/ empty binding between them
18353 static const uint32_t NUM_BINDINGS = 3;
18354 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18355 dsl_binding[0].binding = 0;
18356 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18357 dsl_binding[0].descriptorCount = 1;
18358 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18359 dsl_binding[0].pImmutableSamplers = NULL;
18360 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018361 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018362 dsl_binding[2].binding = 2;
18363 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18364 dsl_binding[2].descriptorCount = 1;
18365 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18366 dsl_binding[2].pImmutableSamplers = NULL;
18367
18368 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18369 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18370 ds_layout_ci.pNext = NULL;
18371 ds_layout_ci.bindingCount = NUM_BINDINGS;
18372 ds_layout_ci.pBindings = dsl_binding;
18373 VkDescriptorSetLayout ds_layout;
18374 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18375 ASSERT_VK_SUCCESS(err);
18376
18377 VkDescriptorSet descriptor_set = {};
18378 VkDescriptorSetAllocateInfo alloc_info = {};
18379 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18380 alloc_info.descriptorSetCount = 1;
18381 alloc_info.descriptorPool = ds_pool;
18382 alloc_info.pSetLayouts = &ds_layout;
18383 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18384 ASSERT_VK_SUCCESS(err);
18385
18386 // Create a buffer to be used for update
18387 VkBufferCreateInfo buff_ci = {};
18388 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18389 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18390 buff_ci.size = 256;
18391 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18392 VkBuffer buffer;
18393 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18394 ASSERT_VK_SUCCESS(err);
18395 // Have to bind memory to buffer before descriptor update
18396 VkMemoryAllocateInfo mem_alloc = {};
18397 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18398 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018399 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018400 mem_alloc.memoryTypeIndex = 0;
18401
18402 VkMemoryRequirements mem_reqs;
18403 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18404 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18405 if (!pass) {
18406 vkDestroyBuffer(m_device->device(), buffer, NULL);
18407 return;
18408 }
18409
18410 VkDeviceMemory mem;
18411 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18412 ASSERT_VK_SUCCESS(err);
18413 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18414 ASSERT_VK_SUCCESS(err);
18415
18416 // Only update the descriptor at binding 2
18417 VkDescriptorBufferInfo buff_info = {};
18418 buff_info.buffer = buffer;
18419 buff_info.offset = 0;
18420 buff_info.range = VK_WHOLE_SIZE;
18421 VkWriteDescriptorSet descriptor_write = {};
18422 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18423 descriptor_write.dstBinding = 2;
18424 descriptor_write.descriptorCount = 1;
18425 descriptor_write.pTexelBufferView = nullptr;
18426 descriptor_write.pBufferInfo = &buff_info;
18427 descriptor_write.pImageInfo = nullptr;
18428 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18429 descriptor_write.dstSet = descriptor_set;
18430
18431 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18432
18433 m_errorMonitor->VerifyNotFound();
18434 // Cleanup
18435 vkFreeMemory(m_device->device(), mem, NULL);
18436 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18437 vkDestroyBuffer(m_device->device(), buffer, NULL);
18438 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18439}
18440
18441// This is a positive test. No failures are expected.
18442TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18443 VkResult err;
18444 bool pass;
18445
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018446 TEST_DESCRIPTION(
18447 "Create a buffer, allocate memory, bind memory, destroy "
18448 "the buffer, create an image, and bind the same memory to "
18449 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018450
18451 m_errorMonitor->ExpectSuccess();
18452
18453 ASSERT_NO_FATAL_FAILURE(InitState());
18454
18455 VkBuffer buffer;
18456 VkImage image;
18457 VkDeviceMemory mem;
18458 VkMemoryRequirements mem_reqs;
18459
18460 VkBufferCreateInfo buf_info = {};
18461 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18462 buf_info.pNext = NULL;
18463 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18464 buf_info.size = 256;
18465 buf_info.queueFamilyIndexCount = 0;
18466 buf_info.pQueueFamilyIndices = NULL;
18467 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18468 buf_info.flags = 0;
18469 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18470 ASSERT_VK_SUCCESS(err);
18471
18472 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18473
18474 VkMemoryAllocateInfo alloc_info = {};
18475 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18476 alloc_info.pNext = NULL;
18477 alloc_info.memoryTypeIndex = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070018478
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018479 // Ensure memory is big enough for both bindings
18480 alloc_info.allocationSize = 0x10000;
18481
18482 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18483 if (!pass) {
18484 vkDestroyBuffer(m_device->device(), buffer, NULL);
18485 return;
18486 }
18487
18488 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18489 ASSERT_VK_SUCCESS(err);
18490
18491 uint8_t *pData;
18492 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18493 ASSERT_VK_SUCCESS(err);
18494
18495 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18496
18497 vkUnmapMemory(m_device->device(), mem);
18498
18499 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18500 ASSERT_VK_SUCCESS(err);
18501
18502 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18503 // memory. In fact, it was never used by the GPU.
18504 // Just be be sure, wait for idle.
18505 vkDestroyBuffer(m_device->device(), buffer, NULL);
18506 vkDeviceWaitIdle(m_device->device());
18507
Tobin Ehlis6a005702016-12-28 15:25:56 -070018508 // Use optimal as some platforms report linear support but then fail image creation
18509 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18510 VkImageFormatProperties image_format_properties;
18511 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18512 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18513 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018514 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018515 vkFreeMemory(m_device->device(), mem, NULL);
18516 return;
18517 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018518 VkImageCreateInfo image_create_info = {};
18519 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18520 image_create_info.pNext = NULL;
18521 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18522 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18523 image_create_info.extent.width = 64;
18524 image_create_info.extent.height = 64;
18525 image_create_info.extent.depth = 1;
18526 image_create_info.mipLevels = 1;
18527 image_create_info.arrayLayers = 1;
18528 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018529 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018530 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18531 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18532 image_create_info.queueFamilyIndexCount = 0;
18533 image_create_info.pQueueFamilyIndices = NULL;
18534 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18535 image_create_info.flags = 0;
18536
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018537 /* Create a mappable image. It will be the texture if linear images are ok
18538 * to be textures or it will be the staging image if they are not.
18539 */
18540 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18541 ASSERT_VK_SUCCESS(err);
18542
18543 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18544
Tobin Ehlis6a005702016-12-28 15:25:56 -070018545 VkMemoryAllocateInfo mem_alloc = {};
18546 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18547 mem_alloc.pNext = NULL;
18548 mem_alloc.allocationSize = 0;
18549 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018550 mem_alloc.allocationSize = mem_reqs.size;
18551
18552 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18553 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018554 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018555 vkDestroyImage(m_device->device(), image, NULL);
18556 return;
18557 }
18558
18559 // VALIDATION FAILURE:
18560 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18561 ASSERT_VK_SUCCESS(err);
18562
18563 m_errorMonitor->VerifyNotFound();
18564
18565 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018566 vkDestroyImage(m_device->device(), image, NULL);
18567}
18568
Tony Barbourab713912017-02-02 14:17:35 -070018569// This is a positive test. No failures are expected.
18570TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18571 VkResult err;
18572
18573 TEST_DESCRIPTION(
18574 "Call all applicable destroy and free routines with NULL"
18575 "handles, expecting no validation errors");
18576
18577 m_errorMonitor->ExpectSuccess();
18578
18579 ASSERT_NO_FATAL_FAILURE(InitState());
18580 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18581 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18582 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18583 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18584 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18585 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18586 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18587 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18588 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18589 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18590 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18591 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18592 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18593 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18594 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18595 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18596 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18597 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18598 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18599 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18600
18601 VkCommandPool command_pool;
18602 VkCommandPoolCreateInfo pool_create_info{};
18603 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18604 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18605 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18606 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18607 VkCommandBuffer command_buffers[3] = {};
18608 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18609 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18610 command_buffer_allocate_info.commandPool = command_pool;
18611 command_buffer_allocate_info.commandBufferCount = 1;
18612 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18613 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18614 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18615 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18616
18617 VkDescriptorPoolSize ds_type_count = {};
18618 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18619 ds_type_count.descriptorCount = 1;
18620
18621 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18622 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18623 ds_pool_ci.pNext = NULL;
18624 ds_pool_ci.maxSets = 1;
18625 ds_pool_ci.poolSizeCount = 1;
18626 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18627 ds_pool_ci.pPoolSizes = &ds_type_count;
18628
18629 VkDescriptorPool ds_pool;
18630 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18631 ASSERT_VK_SUCCESS(err);
18632
18633 VkDescriptorSetLayoutBinding dsl_binding = {};
18634 dsl_binding.binding = 2;
18635 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18636 dsl_binding.descriptorCount = 1;
18637 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18638 dsl_binding.pImmutableSamplers = NULL;
18639 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18640 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18641 ds_layout_ci.pNext = NULL;
18642 ds_layout_ci.bindingCount = 1;
18643 ds_layout_ci.pBindings = &dsl_binding;
18644 VkDescriptorSetLayout ds_layout;
18645 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18646 ASSERT_VK_SUCCESS(err);
18647
18648 VkDescriptorSet descriptor_sets[3] = {};
18649 VkDescriptorSetAllocateInfo alloc_info = {};
18650 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18651 alloc_info.descriptorSetCount = 1;
18652 alloc_info.descriptorPool = ds_pool;
18653 alloc_info.pSetLayouts = &ds_layout;
18654 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18655 ASSERT_VK_SUCCESS(err);
18656 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18657 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18658 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18659
18660 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18661
18662 m_errorMonitor->VerifyNotFound();
18663}
18664
Tony Barbour626994c2017-02-08 15:29:37 -070018665TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018666 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018667
18668 m_errorMonitor->ExpectSuccess();
18669
18670 ASSERT_NO_FATAL_FAILURE(InitState());
18671 VkCommandBuffer cmd_bufs[4];
18672 VkCommandBufferAllocateInfo alloc_info;
18673 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18674 alloc_info.pNext = NULL;
18675 alloc_info.commandBufferCount = 4;
18676 alloc_info.commandPool = m_commandPool;
18677 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18678 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18679 VkImageObj image(m_device);
18680 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18681 ASSERT_TRUE(image.initialized());
18682 VkCommandBufferBeginInfo cb_binfo;
18683 cb_binfo.pNext = NULL;
18684 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18685 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18686 cb_binfo.flags = 0;
18687 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18688 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18689 VkImageMemoryBarrier img_barrier = {};
18690 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18691 img_barrier.pNext = NULL;
18692 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18693 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18694 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18695 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18696 img_barrier.image = image.handle();
18697 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18698 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18699 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18700 img_barrier.subresourceRange.baseArrayLayer = 0;
18701 img_barrier.subresourceRange.baseMipLevel = 0;
18702 img_barrier.subresourceRange.layerCount = 1;
18703 img_barrier.subresourceRange.levelCount = 1;
18704 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18705 &img_barrier);
18706 vkEndCommandBuffer(cmd_bufs[0]);
18707 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18708 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18709 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18710 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18711 &img_barrier);
18712 vkEndCommandBuffer(cmd_bufs[1]);
18713 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18714 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18715 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18716 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18717 &img_barrier);
18718 vkEndCommandBuffer(cmd_bufs[2]);
18719 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18720 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18721 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18722 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18723 &img_barrier);
18724 vkEndCommandBuffer(cmd_bufs[3]);
18725
18726 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18727 VkSemaphore semaphore1, semaphore2;
18728 VkSemaphoreCreateInfo semaphore_create_info{};
18729 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18730 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18731 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18732 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18733 VkSubmitInfo submit_info[3];
18734 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18735 submit_info[0].pNext = nullptr;
18736 submit_info[0].commandBufferCount = 1;
18737 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18738 submit_info[0].signalSemaphoreCount = 1;
18739 submit_info[0].pSignalSemaphores = &semaphore1;
18740 submit_info[0].waitSemaphoreCount = 0;
18741 submit_info[0].pWaitDstStageMask = nullptr;
18742 submit_info[0].pWaitDstStageMask = flags;
18743 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18744 submit_info[1].pNext = nullptr;
18745 submit_info[1].commandBufferCount = 1;
18746 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18747 submit_info[1].waitSemaphoreCount = 1;
18748 submit_info[1].pWaitSemaphores = &semaphore1;
18749 submit_info[1].signalSemaphoreCount = 1;
18750 submit_info[1].pSignalSemaphores = &semaphore2;
18751 submit_info[1].pWaitDstStageMask = flags;
18752 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18753 submit_info[2].pNext = nullptr;
18754 submit_info[2].commandBufferCount = 2;
18755 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18756 submit_info[2].waitSemaphoreCount = 1;
18757 submit_info[2].pWaitSemaphores = &semaphore2;
18758 submit_info[2].signalSemaphoreCount = 0;
18759 submit_info[2].pSignalSemaphores = nullptr;
18760 submit_info[2].pWaitDstStageMask = flags;
18761 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18762 vkQueueWaitIdle(m_device->m_queue);
18763
18764 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18765 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18766 m_errorMonitor->VerifyNotFound();
18767}
18768
Tobin Ehlis953e8392016-11-17 10:54:13 -070018769TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18770 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18771 // We previously had a bug where dynamic offset of inactive bindings was still being used
18772 VkResult err;
18773 m_errorMonitor->ExpectSuccess();
18774
18775 ASSERT_NO_FATAL_FAILURE(InitState());
18776 ASSERT_NO_FATAL_FAILURE(InitViewport());
18777 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18778
18779 VkDescriptorPoolSize ds_type_count = {};
18780 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18781 ds_type_count.descriptorCount = 3;
18782
18783 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18784 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18785 ds_pool_ci.pNext = NULL;
18786 ds_pool_ci.maxSets = 1;
18787 ds_pool_ci.poolSizeCount = 1;
18788 ds_pool_ci.pPoolSizes = &ds_type_count;
18789
18790 VkDescriptorPool ds_pool;
18791 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18792 ASSERT_VK_SUCCESS(err);
18793
18794 const uint32_t BINDING_COUNT = 3;
18795 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018796 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018797 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18798 dsl_binding[0].descriptorCount = 1;
18799 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18800 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018801 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018802 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18803 dsl_binding[1].descriptorCount = 1;
18804 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18805 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018806 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018807 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18808 dsl_binding[2].descriptorCount = 1;
18809 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18810 dsl_binding[2].pImmutableSamplers = NULL;
18811
18812 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18813 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18814 ds_layout_ci.pNext = NULL;
18815 ds_layout_ci.bindingCount = BINDING_COUNT;
18816 ds_layout_ci.pBindings = dsl_binding;
18817 VkDescriptorSetLayout ds_layout;
18818 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18819 ASSERT_VK_SUCCESS(err);
18820
18821 VkDescriptorSet descriptor_set;
18822 VkDescriptorSetAllocateInfo alloc_info = {};
18823 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18824 alloc_info.descriptorSetCount = 1;
18825 alloc_info.descriptorPool = ds_pool;
18826 alloc_info.pSetLayouts = &ds_layout;
18827 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18828 ASSERT_VK_SUCCESS(err);
18829
18830 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18831 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18832 pipeline_layout_ci.pNext = NULL;
18833 pipeline_layout_ci.setLayoutCount = 1;
18834 pipeline_layout_ci.pSetLayouts = &ds_layout;
18835
18836 VkPipelineLayout pipeline_layout;
18837 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18838 ASSERT_VK_SUCCESS(err);
18839
18840 // Create two buffers to update the descriptors with
18841 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18842 uint32_t qfi = 0;
18843 VkBufferCreateInfo buffCI = {};
18844 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18845 buffCI.size = 2048;
18846 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18847 buffCI.queueFamilyIndexCount = 1;
18848 buffCI.pQueueFamilyIndices = &qfi;
18849
18850 VkBuffer dyub1;
18851 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18852 ASSERT_VK_SUCCESS(err);
18853 // buffer2
18854 buffCI.size = 1024;
18855 VkBuffer dyub2;
18856 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18857 ASSERT_VK_SUCCESS(err);
18858 // Allocate memory and bind to buffers
18859 VkMemoryAllocateInfo mem_alloc[2] = {};
18860 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18861 mem_alloc[0].pNext = NULL;
18862 mem_alloc[0].memoryTypeIndex = 0;
18863 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18864 mem_alloc[1].pNext = NULL;
18865 mem_alloc[1].memoryTypeIndex = 0;
18866
18867 VkMemoryRequirements mem_reqs1;
18868 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18869 VkMemoryRequirements mem_reqs2;
18870 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18871 mem_alloc[0].allocationSize = mem_reqs1.size;
18872 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18873 mem_alloc[1].allocationSize = mem_reqs2.size;
18874 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18875 if (!pass) {
18876 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18877 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18878 return;
18879 }
18880
18881 VkDeviceMemory mem1;
18882 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18883 ASSERT_VK_SUCCESS(err);
18884 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18885 ASSERT_VK_SUCCESS(err);
18886 VkDeviceMemory mem2;
18887 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18888 ASSERT_VK_SUCCESS(err);
18889 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18890 ASSERT_VK_SUCCESS(err);
18891 // Update descriptors
18892 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18893 buff_info[0].buffer = dyub1;
18894 buff_info[0].offset = 0;
18895 buff_info[0].range = 256;
18896 buff_info[1].buffer = dyub1;
18897 buff_info[1].offset = 256;
18898 buff_info[1].range = 512;
18899 buff_info[2].buffer = dyub2;
18900 buff_info[2].offset = 0;
18901 buff_info[2].range = 512;
18902
18903 VkWriteDescriptorSet descriptor_write;
18904 memset(&descriptor_write, 0, sizeof(descriptor_write));
18905 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18906 descriptor_write.dstSet = descriptor_set;
18907 descriptor_write.dstBinding = 0;
18908 descriptor_write.descriptorCount = BINDING_COUNT;
18909 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18910 descriptor_write.pBufferInfo = buff_info;
18911
18912 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18913
Tony Barbour552f6c02016-12-21 14:34:07 -070018914 m_commandBuffer->BeginCommandBuffer();
18915 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018916
18917 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018918 char const *vsSource =
18919 "#version 450\n"
18920 "\n"
18921 "out gl_PerVertex { \n"
18922 " vec4 gl_Position;\n"
18923 "};\n"
18924 "void main(){\n"
18925 " gl_Position = vec4(1);\n"
18926 "}\n";
18927 char const *fsSource =
18928 "#version 450\n"
18929 "\n"
18930 "layout(location=0) out vec4 x;\n"
18931 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18932 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18933 "void main(){\n"
18934 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18935 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018936 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18937 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18938 VkPipelineObj pipe(m_device);
18939 pipe.SetViewport(m_viewports);
18940 pipe.SetScissor(m_scissors);
18941 pipe.AddShader(&vs);
18942 pipe.AddShader(&fs);
18943 pipe.AddColorAttachment();
18944 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18945
18946 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18947 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18948 // we used to have a bug in this case.
18949 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18950 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18951 &descriptor_set, BINDING_COUNT, dyn_off);
18952 Draw(1, 0, 0, 0);
18953 m_errorMonitor->VerifyNotFound();
18954
18955 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18956 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18957 vkFreeMemory(m_device->device(), mem1, NULL);
18958 vkFreeMemory(m_device->device(), mem2, NULL);
18959
18960 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18961 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18962 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18963}
18964
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018965TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018966 TEST_DESCRIPTION(
18967 "Ensure that validations handling of non-coherent memory "
18968 "mapping while using VK_WHOLE_SIZE does not cause access "
18969 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018970 VkResult err;
18971 uint8_t *pData;
18972 ASSERT_NO_FATAL_FAILURE(InitState());
18973
18974 VkDeviceMemory mem;
18975 VkMemoryRequirements mem_reqs;
18976 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018977 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018978 VkMemoryAllocateInfo alloc_info = {};
18979 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18980 alloc_info.pNext = NULL;
18981 alloc_info.memoryTypeIndex = 0;
18982
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018983 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018984 alloc_info.allocationSize = allocation_size;
18985
18986 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18987 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 -070018988 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018989 if (!pass) {
18990 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070018991 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
18992 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018993 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018994 pass = m_device->phy().set_memory_type(
18995 mem_reqs.memoryTypeBits, &alloc_info,
18996 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
18997 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018998 if (!pass) {
18999 return;
19000 }
19001 }
19002 }
19003
19004 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19005 ASSERT_VK_SUCCESS(err);
19006
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019007 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019008 m_errorMonitor->ExpectSuccess();
19009 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19010 ASSERT_VK_SUCCESS(err);
19011 VkMappedMemoryRange mmr = {};
19012 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19013 mmr.memory = mem;
19014 mmr.offset = 0;
19015 mmr.size = VK_WHOLE_SIZE;
19016 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19017 ASSERT_VK_SUCCESS(err);
19018 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19019 ASSERT_VK_SUCCESS(err);
19020 m_errorMonitor->VerifyNotFound();
19021 vkUnmapMemory(m_device->device(), mem);
19022
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019023 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019024 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019025 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019026 ASSERT_VK_SUCCESS(err);
19027 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19028 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019029 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019030 mmr.size = VK_WHOLE_SIZE;
19031 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19032 ASSERT_VK_SUCCESS(err);
19033 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19034 ASSERT_VK_SUCCESS(err);
19035 m_errorMonitor->VerifyNotFound();
19036 vkUnmapMemory(m_device->device(), mem);
19037
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019038 // Map with offset and size
19039 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019040 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019041 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019042 ASSERT_VK_SUCCESS(err);
19043 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19044 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019045 mmr.offset = 4 * atom_size;
19046 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019047 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19048 ASSERT_VK_SUCCESS(err);
19049 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19050 ASSERT_VK_SUCCESS(err);
19051 m_errorMonitor->VerifyNotFound();
19052 vkUnmapMemory(m_device->device(), mem);
19053
19054 // Map without offset and flush WHOLE_SIZE with two separate offsets
19055 m_errorMonitor->ExpectSuccess();
19056 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19057 ASSERT_VK_SUCCESS(err);
19058 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19059 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019060 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019061 mmr.size = VK_WHOLE_SIZE;
19062 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19063 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019064 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019065 mmr.size = VK_WHOLE_SIZE;
19066 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19067 ASSERT_VK_SUCCESS(err);
19068 m_errorMonitor->VerifyNotFound();
19069 vkUnmapMemory(m_device->device(), mem);
19070
19071 vkFreeMemory(m_device->device(), mem, NULL);
19072}
19073
19074// This is a positive test. We used to expect error in this case but spec now allows it
19075TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19076 m_errorMonitor->ExpectSuccess();
19077 vk_testing::Fence testFence;
19078 VkFenceCreateInfo fenceInfo = {};
19079 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19080 fenceInfo.pNext = NULL;
19081
19082 ASSERT_NO_FATAL_FAILURE(InitState());
19083 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019084 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019085 VkResult result = vkResetFences(m_device->device(), 1, fences);
19086 ASSERT_VK_SUCCESS(result);
19087
19088 m_errorMonitor->VerifyNotFound();
19089}
19090
19091TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19092 m_errorMonitor->ExpectSuccess();
19093
19094 ASSERT_NO_FATAL_FAILURE(InitState());
19095 VkResult err;
19096
19097 // Record (empty!) command buffer that can be submitted multiple times
19098 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019099 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19100 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019101 m_commandBuffer->BeginCommandBuffer(&cbbi);
19102 m_commandBuffer->EndCommandBuffer();
19103
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019104 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019105 VkFence fence;
19106 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19107 ASSERT_VK_SUCCESS(err);
19108
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019109 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019110 VkSemaphore s1, s2;
19111 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19112 ASSERT_VK_SUCCESS(err);
19113 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19114 ASSERT_VK_SUCCESS(err);
19115
19116 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019117 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019118 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19119 ASSERT_VK_SUCCESS(err);
19120
19121 // Submit CB again, signaling s2.
19122 si.pSignalSemaphores = &s2;
19123 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19124 ASSERT_VK_SUCCESS(err);
19125
19126 // Wait for fence.
19127 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19128 ASSERT_VK_SUCCESS(err);
19129
19130 // CB is still in flight from second submission, but semaphore s1 is no
19131 // longer in flight. delete it.
19132 vkDestroySemaphore(m_device->device(), s1, nullptr);
19133
19134 m_errorMonitor->VerifyNotFound();
19135
19136 // Force device idle and clean up remaining objects
19137 vkDeviceWaitIdle(m_device->device());
19138 vkDestroySemaphore(m_device->device(), s2, nullptr);
19139 vkDestroyFence(m_device->device(), fence, nullptr);
19140}
19141
19142TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19143 m_errorMonitor->ExpectSuccess();
19144
19145 ASSERT_NO_FATAL_FAILURE(InitState());
19146 VkResult err;
19147
19148 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019149 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019150 VkFence f1;
19151 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19152 ASSERT_VK_SUCCESS(err);
19153
19154 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019155 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019156 VkFence f2;
19157 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19158 ASSERT_VK_SUCCESS(err);
19159
19160 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019161 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019162 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19163
19164 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019165 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019166 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19167
19168 // Should have both retired!
19169 vkDestroyFence(m_device->device(), f1, nullptr);
19170 vkDestroyFence(m_device->device(), f2, nullptr);
19171
19172 m_errorMonitor->VerifyNotFound();
19173}
19174
19175TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019176 TEST_DESCRIPTION(
19177 "Verify that creating an image view from an image with valid usage "
19178 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019179
19180 ASSERT_NO_FATAL_FAILURE(InitState());
19181
19182 m_errorMonitor->ExpectSuccess();
19183 // Verify that we can create a view with usage INPUT_ATTACHMENT
19184 VkImageObj image(m_device);
19185 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19186 ASSERT_TRUE(image.initialized());
19187 VkImageView imageView;
19188 VkImageViewCreateInfo ivci = {};
19189 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19190 ivci.image = image.handle();
19191 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19192 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19193 ivci.subresourceRange.layerCount = 1;
19194 ivci.subresourceRange.baseMipLevel = 0;
19195 ivci.subresourceRange.levelCount = 1;
19196 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19197
19198 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19199 m_errorMonitor->VerifyNotFound();
19200 vkDestroyImageView(m_device->device(), imageView, NULL);
19201}
19202
19203// This is a positive test. No failures are expected.
19204TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019205 TEST_DESCRIPTION(
19206 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19207 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019208
19209 ASSERT_NO_FATAL_FAILURE(InitState());
19210
19211 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019212 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019213
19214 m_errorMonitor->ExpectSuccess();
19215
19216 VkImage image;
19217 VkImageCreateInfo image_create_info = {};
19218 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19219 image_create_info.pNext = NULL;
19220 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19221 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19222 image_create_info.extent.width = 64;
19223 image_create_info.extent.height = 64;
19224 image_create_info.extent.depth = 1;
19225 image_create_info.mipLevels = 1;
19226 image_create_info.arrayLayers = 1;
19227 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19228 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19229 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19230 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19231 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19232 ASSERT_VK_SUCCESS(err);
19233
19234 VkMemoryRequirements memory_reqs;
19235 VkDeviceMemory memory_one, memory_two;
19236 bool pass;
19237 VkMemoryAllocateInfo memory_info = {};
19238 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19239 memory_info.pNext = NULL;
19240 memory_info.allocationSize = 0;
19241 memory_info.memoryTypeIndex = 0;
19242 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19243 // Find an image big enough to allow sparse mapping of 2 memory regions
19244 // Increase the image size until it is at least twice the
19245 // size of the required alignment, to ensure we can bind both
19246 // allocated memory blocks to the image on aligned offsets.
19247 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19248 vkDestroyImage(m_device->device(), image, nullptr);
19249 image_create_info.extent.width *= 2;
19250 image_create_info.extent.height *= 2;
19251 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19252 ASSERT_VK_SUCCESS(err);
19253 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19254 }
19255 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19256 // at the end of the first
19257 memory_info.allocationSize = memory_reqs.alignment;
19258 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19259 ASSERT_TRUE(pass);
19260 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19261 ASSERT_VK_SUCCESS(err);
19262 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19263 ASSERT_VK_SUCCESS(err);
19264 VkSparseMemoryBind binds[2];
19265 binds[0].flags = 0;
19266 binds[0].memory = memory_one;
19267 binds[0].memoryOffset = 0;
19268 binds[0].resourceOffset = 0;
19269 binds[0].size = memory_info.allocationSize;
19270 binds[1].flags = 0;
19271 binds[1].memory = memory_two;
19272 binds[1].memoryOffset = 0;
19273 binds[1].resourceOffset = memory_info.allocationSize;
19274 binds[1].size = memory_info.allocationSize;
19275
19276 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19277 opaqueBindInfo.image = image;
19278 opaqueBindInfo.bindCount = 2;
19279 opaqueBindInfo.pBinds = binds;
19280
19281 VkFence fence = VK_NULL_HANDLE;
19282 VkBindSparseInfo bindSparseInfo = {};
19283 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19284 bindSparseInfo.imageOpaqueBindCount = 1;
19285 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19286
19287 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19288 vkQueueWaitIdle(m_device->m_queue);
19289 vkDestroyImage(m_device->device(), image, NULL);
19290 vkFreeMemory(m_device->device(), memory_one, NULL);
19291 vkFreeMemory(m_device->device(), memory_two, NULL);
19292 m_errorMonitor->VerifyNotFound();
19293}
19294
19295TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019296 TEST_DESCRIPTION(
19297 "Ensure that CmdBeginRenderPass with an attachment's "
19298 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19299 "the command buffer has prior knowledge of that "
19300 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019301
19302 m_errorMonitor->ExpectSuccess();
19303
19304 ASSERT_NO_FATAL_FAILURE(InitState());
19305
19306 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019307 VkAttachmentDescription attachment = {0,
19308 VK_FORMAT_R8G8B8A8_UNORM,
19309 VK_SAMPLE_COUNT_1_BIT,
19310 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19311 VK_ATTACHMENT_STORE_OP_STORE,
19312 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19313 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19314 VK_IMAGE_LAYOUT_UNDEFINED,
19315 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019316
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019317 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019318
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019319 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019320
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019321 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019322
19323 VkRenderPass rp;
19324 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19325 ASSERT_VK_SUCCESS(err);
19326
19327 // A compatible framebuffer.
19328 VkImageObj image(m_device);
19329 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19330 ASSERT_TRUE(image.initialized());
19331
19332 VkImageViewCreateInfo ivci = {
19333 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19334 nullptr,
19335 0,
19336 image.handle(),
19337 VK_IMAGE_VIEW_TYPE_2D,
19338 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019339 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19340 VK_COMPONENT_SWIZZLE_IDENTITY},
19341 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019342 };
19343 VkImageView view;
19344 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19345 ASSERT_VK_SUCCESS(err);
19346
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019347 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019348 VkFramebuffer fb;
19349 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19350 ASSERT_VK_SUCCESS(err);
19351
19352 // Record a single command buffer which uses this renderpass twice. The
19353 // bug is triggered at the beginning of the second renderpass, when the
19354 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019355 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 -070019356 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019357 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19358 vkCmdEndRenderPass(m_commandBuffer->handle());
19359 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19360
19361 m_errorMonitor->VerifyNotFound();
19362
19363 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019364 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019365
19366 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19367 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19368 vkDestroyImageView(m_device->device(), view, nullptr);
19369}
19370
19371TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019372 TEST_DESCRIPTION(
19373 "This test should pass. Create a Framebuffer and "
19374 "command buffer, bind them together, then destroy "
19375 "command pool and framebuffer and verify there are no "
19376 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019377
19378 m_errorMonitor->ExpectSuccess();
19379
19380 ASSERT_NO_FATAL_FAILURE(InitState());
19381
19382 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019383 VkAttachmentDescription attachment = {0,
19384 VK_FORMAT_R8G8B8A8_UNORM,
19385 VK_SAMPLE_COUNT_1_BIT,
19386 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19387 VK_ATTACHMENT_STORE_OP_STORE,
19388 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19389 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19390 VK_IMAGE_LAYOUT_UNDEFINED,
19391 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019392
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019393 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019394
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019395 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019396
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019397 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019398
19399 VkRenderPass rp;
19400 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19401 ASSERT_VK_SUCCESS(err);
19402
19403 // A compatible framebuffer.
19404 VkImageObj image(m_device);
19405 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19406 ASSERT_TRUE(image.initialized());
19407
19408 VkImageViewCreateInfo ivci = {
19409 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19410 nullptr,
19411 0,
19412 image.handle(),
19413 VK_IMAGE_VIEW_TYPE_2D,
19414 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019415 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19416 VK_COMPONENT_SWIZZLE_IDENTITY},
19417 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019418 };
19419 VkImageView view;
19420 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19421 ASSERT_VK_SUCCESS(err);
19422
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019423 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019424 VkFramebuffer fb;
19425 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19426 ASSERT_VK_SUCCESS(err);
19427
19428 // Explicitly create a command buffer to bind the FB to so that we can then
19429 // destroy the command pool in order to implicitly free command buffer
19430 VkCommandPool command_pool;
19431 VkCommandPoolCreateInfo pool_create_info{};
19432 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19433 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19434 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19435 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19436
19437 VkCommandBuffer command_buffer;
19438 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19439 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19440 command_buffer_allocate_info.commandPool = command_pool;
19441 command_buffer_allocate_info.commandBufferCount = 1;
19442 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19443 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19444
19445 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019446 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 -060019447 VkCommandBufferBeginInfo begin_info{};
19448 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19449 vkBeginCommandBuffer(command_buffer, &begin_info);
19450
19451 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19452 vkCmdEndRenderPass(command_buffer);
19453 vkEndCommandBuffer(command_buffer);
19454 vkDestroyImageView(m_device->device(), view, nullptr);
19455 // Destroy command pool to implicitly free command buffer
19456 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19457 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19458 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19459 m_errorMonitor->VerifyNotFound();
19460}
19461
19462TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019463 TEST_DESCRIPTION(
19464 "Ensure that CmdBeginRenderPass applies the layout "
19465 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019466
19467 m_errorMonitor->ExpectSuccess();
19468
19469 ASSERT_NO_FATAL_FAILURE(InitState());
19470
19471 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019472 VkAttachmentDescription attachment = {0,
19473 VK_FORMAT_R8G8B8A8_UNORM,
19474 VK_SAMPLE_COUNT_1_BIT,
19475 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19476 VK_ATTACHMENT_STORE_OP_STORE,
19477 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19478 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19479 VK_IMAGE_LAYOUT_UNDEFINED,
19480 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019481
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019482 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019483
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019484 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019485
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019486 VkSubpassDependency dep = {0,
19487 0,
19488 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19489 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19490 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19491 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19492 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019493
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019494 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019495
19496 VkResult err;
19497 VkRenderPass rp;
19498 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19499 ASSERT_VK_SUCCESS(err);
19500
19501 // A compatible framebuffer.
19502 VkImageObj image(m_device);
19503 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19504 ASSERT_TRUE(image.initialized());
19505
19506 VkImageViewCreateInfo ivci = {
19507 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19508 nullptr,
19509 0,
19510 image.handle(),
19511 VK_IMAGE_VIEW_TYPE_2D,
19512 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019513 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19514 VK_COMPONENT_SWIZZLE_IDENTITY},
19515 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019516 };
19517 VkImageView view;
19518 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19519 ASSERT_VK_SUCCESS(err);
19520
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019521 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019522 VkFramebuffer fb;
19523 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19524 ASSERT_VK_SUCCESS(err);
19525
19526 // Record a single command buffer which issues a pipeline barrier w/
19527 // image memory barrier for the attachment. This detects the previously
19528 // missing tracking of the subpass layout by throwing a validation error
19529 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019530 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 -070019531 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019532 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19533
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019534 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19535 nullptr,
19536 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19537 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19538 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19539 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19540 VK_QUEUE_FAMILY_IGNORED,
19541 VK_QUEUE_FAMILY_IGNORED,
19542 image.handle(),
19543 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019544 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019545 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19546 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019547
19548 vkCmdEndRenderPass(m_commandBuffer->handle());
19549 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019550 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019551
19552 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19553 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19554 vkDestroyImageView(m_device->device(), view, nullptr);
19555}
19556
19557TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019558 TEST_DESCRIPTION(
19559 "Validate that when an imageView of a depth/stencil image "
19560 "is used as a depth/stencil framebuffer attachment, the "
19561 "aspectMask is ignored and both depth and stencil image "
19562 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019563
19564 VkFormatProperties format_properties;
19565 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19566 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19567 return;
19568 }
19569
19570 m_errorMonitor->ExpectSuccess();
19571
19572 ASSERT_NO_FATAL_FAILURE(InitState());
19573
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019574 VkAttachmentDescription attachment = {0,
19575 VK_FORMAT_D32_SFLOAT_S8_UINT,
19576 VK_SAMPLE_COUNT_1_BIT,
19577 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19578 VK_ATTACHMENT_STORE_OP_STORE,
19579 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19580 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19581 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19582 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019583
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019584 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019585
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019586 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019587
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019588 VkSubpassDependency dep = {0,
19589 0,
19590 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19591 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19592 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19593 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19594 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019595
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019596 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019597
19598 VkResult err;
19599 VkRenderPass rp;
19600 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19601 ASSERT_VK_SUCCESS(err);
19602
19603 VkImageObj image(m_device);
19604 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019605 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019606 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019607 ASSERT_TRUE(image.initialized());
19608 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19609
19610 VkImageViewCreateInfo ivci = {
19611 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19612 nullptr,
19613 0,
19614 image.handle(),
19615 VK_IMAGE_VIEW_TYPE_2D,
19616 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019617 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19618 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019619 };
19620 VkImageView view;
19621 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19622 ASSERT_VK_SUCCESS(err);
19623
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019624 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019625 VkFramebuffer fb;
19626 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19627 ASSERT_VK_SUCCESS(err);
19628
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019629 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 -070019630 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019631 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19632
19633 VkImageMemoryBarrier imb = {};
19634 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19635 imb.pNext = nullptr;
19636 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19637 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19638 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19639 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19640 imb.srcQueueFamilyIndex = 0;
19641 imb.dstQueueFamilyIndex = 0;
19642 imb.image = image.handle();
19643 imb.subresourceRange.aspectMask = 0x6;
19644 imb.subresourceRange.baseMipLevel = 0;
19645 imb.subresourceRange.levelCount = 0x1;
19646 imb.subresourceRange.baseArrayLayer = 0;
19647 imb.subresourceRange.layerCount = 0x1;
19648
19649 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019650 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19651 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019652
19653 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019654 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019655 QueueCommandBuffer(false);
19656 m_errorMonitor->VerifyNotFound();
19657
19658 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19659 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19660 vkDestroyImageView(m_device->device(), view, nullptr);
19661}
19662
19663TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019664 TEST_DESCRIPTION(
19665 "Ensure that layout transitions work correctly without "
19666 "errors, when an attachment reference is "
19667 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019668
19669 m_errorMonitor->ExpectSuccess();
19670
19671 ASSERT_NO_FATAL_FAILURE(InitState());
19672
19673 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019674 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019675
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019676 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019677
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019678 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019679
19680 VkRenderPass rp;
19681 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19682 ASSERT_VK_SUCCESS(err);
19683
19684 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019685 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019686 VkFramebuffer fb;
19687 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19688 ASSERT_VK_SUCCESS(err);
19689
19690 // Record a command buffer which just begins and ends the renderpass. The
19691 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019692 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 -070019693 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019694 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19695 vkCmdEndRenderPass(m_commandBuffer->handle());
19696 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019697 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019698
19699 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19700 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19701}
19702
19703// This is a positive test. No errors are expected.
19704TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019705 TEST_DESCRIPTION(
19706 "Create a stencil-only attachment with a LOAD_OP set to "
19707 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019708 VkResult result = VK_SUCCESS;
19709 VkImageFormatProperties formatProps;
19710 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019711 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19712 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019713 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19714 return;
19715 }
19716
19717 ASSERT_NO_FATAL_FAILURE(InitState());
19718 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19719 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019720 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019721 VkAttachmentDescription att = {};
19722 VkAttachmentReference ref = {};
19723 att.format = depth_stencil_fmt;
19724 att.samples = VK_SAMPLE_COUNT_1_BIT;
19725 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19726 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19727 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19728 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19729 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19730 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19731
19732 VkClearValue clear;
19733 clear.depthStencil.depth = 1.0;
19734 clear.depthStencil.stencil = 0;
19735 ref.attachment = 0;
19736 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19737
19738 VkSubpassDescription subpass = {};
19739 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19740 subpass.flags = 0;
19741 subpass.inputAttachmentCount = 0;
19742 subpass.pInputAttachments = NULL;
19743 subpass.colorAttachmentCount = 0;
19744 subpass.pColorAttachments = NULL;
19745 subpass.pResolveAttachments = NULL;
19746 subpass.pDepthStencilAttachment = &ref;
19747 subpass.preserveAttachmentCount = 0;
19748 subpass.pPreserveAttachments = NULL;
19749
19750 VkRenderPass rp;
19751 VkRenderPassCreateInfo rp_info = {};
19752 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19753 rp_info.attachmentCount = 1;
19754 rp_info.pAttachments = &att;
19755 rp_info.subpassCount = 1;
19756 rp_info.pSubpasses = &subpass;
19757 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19758 ASSERT_VK_SUCCESS(result);
19759
19760 VkImageView *depthView = m_depthStencil->BindInfo();
19761 VkFramebufferCreateInfo fb_info = {};
19762 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19763 fb_info.pNext = NULL;
19764 fb_info.renderPass = rp;
19765 fb_info.attachmentCount = 1;
19766 fb_info.pAttachments = depthView;
19767 fb_info.width = 100;
19768 fb_info.height = 100;
19769 fb_info.layers = 1;
19770 VkFramebuffer fb;
19771 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19772 ASSERT_VK_SUCCESS(result);
19773
19774 VkRenderPassBeginInfo rpbinfo = {};
19775 rpbinfo.clearValueCount = 1;
19776 rpbinfo.pClearValues = &clear;
19777 rpbinfo.pNext = NULL;
19778 rpbinfo.renderPass = rp;
19779 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19780 rpbinfo.renderArea.extent.width = 100;
19781 rpbinfo.renderArea.extent.height = 100;
19782 rpbinfo.renderArea.offset.x = 0;
19783 rpbinfo.renderArea.offset.y = 0;
19784 rpbinfo.framebuffer = fb;
19785
19786 VkFence fence = {};
19787 VkFenceCreateInfo fence_ci = {};
19788 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19789 fence_ci.pNext = nullptr;
19790 fence_ci.flags = 0;
19791 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19792 ASSERT_VK_SUCCESS(result);
19793
19794 m_commandBuffer->BeginCommandBuffer();
19795 m_commandBuffer->BeginRenderPass(rpbinfo);
19796 m_commandBuffer->EndRenderPass();
19797 m_commandBuffer->EndCommandBuffer();
19798 m_commandBuffer->QueueCommandBuffer(fence);
19799
19800 VkImageObj destImage(m_device);
19801 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 -070019802 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019803 VkImageMemoryBarrier barrier = {};
19804 VkImageSubresourceRange range;
19805 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19806 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19807 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19808 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19809 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19810 barrier.image = m_depthStencil->handle();
19811 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19812 range.baseMipLevel = 0;
19813 range.levelCount = 1;
19814 range.baseArrayLayer = 0;
19815 range.layerCount = 1;
19816 barrier.subresourceRange = range;
19817 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19818 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19819 cmdbuf.BeginCommandBuffer();
19820 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 -070019821 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019822 barrier.srcAccessMask = 0;
19823 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19824 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19825 barrier.image = destImage.handle();
19826 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19827 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 -070019828 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019829 VkImageCopy cregion;
19830 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19831 cregion.srcSubresource.mipLevel = 0;
19832 cregion.srcSubresource.baseArrayLayer = 0;
19833 cregion.srcSubresource.layerCount = 1;
19834 cregion.srcOffset.x = 0;
19835 cregion.srcOffset.y = 0;
19836 cregion.srcOffset.z = 0;
19837 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19838 cregion.dstSubresource.mipLevel = 0;
19839 cregion.dstSubresource.baseArrayLayer = 0;
19840 cregion.dstSubresource.layerCount = 1;
19841 cregion.dstOffset.x = 0;
19842 cregion.dstOffset.y = 0;
19843 cregion.dstOffset.z = 0;
19844 cregion.extent.width = 100;
19845 cregion.extent.height = 100;
19846 cregion.extent.depth = 1;
19847 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019848 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019849 cmdbuf.EndCommandBuffer();
19850
19851 VkSubmitInfo submit_info;
19852 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19853 submit_info.pNext = NULL;
19854 submit_info.waitSemaphoreCount = 0;
19855 submit_info.pWaitSemaphores = NULL;
19856 submit_info.pWaitDstStageMask = NULL;
19857 submit_info.commandBufferCount = 1;
19858 submit_info.pCommandBuffers = &cmdbuf.handle();
19859 submit_info.signalSemaphoreCount = 0;
19860 submit_info.pSignalSemaphores = NULL;
19861
19862 m_errorMonitor->ExpectSuccess();
19863 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19864 m_errorMonitor->VerifyNotFound();
19865
19866 vkQueueWaitIdle(m_device->m_queue);
19867 vkDestroyFence(m_device->device(), fence, nullptr);
19868 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19869 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19870}
19871
19872// This is a positive test. No errors should be generated.
19873TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19874 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19875
19876 m_errorMonitor->ExpectSuccess();
19877 ASSERT_NO_FATAL_FAILURE(InitState());
19878
19879 VkEvent event;
19880 VkEventCreateInfo event_create_info{};
19881 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19882 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19883
19884 VkCommandPool command_pool;
19885 VkCommandPoolCreateInfo pool_create_info{};
19886 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19887 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19888 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19889 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19890
19891 VkCommandBuffer command_buffer;
19892 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19893 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19894 command_buffer_allocate_info.commandPool = command_pool;
19895 command_buffer_allocate_info.commandBufferCount = 1;
19896 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19897 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19898
19899 VkQueue queue = VK_NULL_HANDLE;
19900 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19901
19902 {
19903 VkCommandBufferBeginInfo begin_info{};
19904 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19905 vkBeginCommandBuffer(command_buffer, &begin_info);
19906
19907 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 -070019908 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019909 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19910 vkEndCommandBuffer(command_buffer);
19911 }
19912 {
19913 VkSubmitInfo submit_info{};
19914 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19915 submit_info.commandBufferCount = 1;
19916 submit_info.pCommandBuffers = &command_buffer;
19917 submit_info.signalSemaphoreCount = 0;
19918 submit_info.pSignalSemaphores = nullptr;
19919 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19920 }
19921 { vkSetEvent(m_device->device(), event); }
19922
19923 vkQueueWaitIdle(queue);
19924
19925 vkDestroyEvent(m_device->device(), event, nullptr);
19926 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19927 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19928
19929 m_errorMonitor->VerifyNotFound();
19930}
19931// This is a positive test. No errors should be generated.
19932TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19933 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19934
19935 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019936 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019937
19938 m_errorMonitor->ExpectSuccess();
19939
19940 VkQueryPool query_pool;
19941 VkQueryPoolCreateInfo query_pool_create_info{};
19942 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19943 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19944 query_pool_create_info.queryCount = 1;
19945 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19946
19947 VkCommandPool command_pool;
19948 VkCommandPoolCreateInfo pool_create_info{};
19949 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19950 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19951 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19952 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19953
19954 VkCommandBuffer command_buffer;
19955 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19956 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19957 command_buffer_allocate_info.commandPool = command_pool;
19958 command_buffer_allocate_info.commandBufferCount = 1;
19959 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19960 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19961
19962 VkCommandBuffer secondary_command_buffer;
19963 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19964 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19965
19966 VkQueue queue = VK_NULL_HANDLE;
19967 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19968
19969 uint32_t qfi = 0;
19970 VkBufferCreateInfo buff_create_info = {};
19971 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19972 buff_create_info.size = 1024;
19973 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19974 buff_create_info.queueFamilyIndexCount = 1;
19975 buff_create_info.pQueueFamilyIndices = &qfi;
19976
19977 VkResult err;
19978 VkBuffer buffer;
19979 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19980 ASSERT_VK_SUCCESS(err);
19981 VkMemoryAllocateInfo mem_alloc = {};
19982 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19983 mem_alloc.pNext = NULL;
19984 mem_alloc.allocationSize = 1024;
19985 mem_alloc.memoryTypeIndex = 0;
19986
19987 VkMemoryRequirements memReqs;
19988 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
19989 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
19990 if (!pass) {
19991 vkDestroyBuffer(m_device->device(), buffer, NULL);
19992 return;
19993 }
19994
19995 VkDeviceMemory mem;
19996 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
19997 ASSERT_VK_SUCCESS(err);
19998 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
19999 ASSERT_VK_SUCCESS(err);
20000
20001 VkCommandBufferInheritanceInfo hinfo = {};
20002 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20003 hinfo.renderPass = VK_NULL_HANDLE;
20004 hinfo.subpass = 0;
20005 hinfo.framebuffer = VK_NULL_HANDLE;
20006 hinfo.occlusionQueryEnable = VK_FALSE;
20007 hinfo.queryFlags = 0;
20008 hinfo.pipelineStatistics = 0;
20009
20010 {
20011 VkCommandBufferBeginInfo begin_info{};
20012 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20013 begin_info.pInheritanceInfo = &hinfo;
20014 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20015
20016 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20017 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20018
20019 vkEndCommandBuffer(secondary_command_buffer);
20020
20021 begin_info.pInheritanceInfo = nullptr;
20022 vkBeginCommandBuffer(command_buffer, &begin_info);
20023
20024 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20025 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20026
20027 vkEndCommandBuffer(command_buffer);
20028 }
20029 {
20030 VkSubmitInfo submit_info{};
20031 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20032 submit_info.commandBufferCount = 1;
20033 submit_info.pCommandBuffers = &command_buffer;
20034 submit_info.signalSemaphoreCount = 0;
20035 submit_info.pSignalSemaphores = nullptr;
20036 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20037 }
20038
20039 vkQueueWaitIdle(queue);
20040
20041 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20042 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20043 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20044 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20045 vkDestroyBuffer(m_device->device(), buffer, NULL);
20046 vkFreeMemory(m_device->device(), mem, NULL);
20047
20048 m_errorMonitor->VerifyNotFound();
20049}
20050
20051// This is a positive test. No errors should be generated.
20052TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20053 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20054
20055 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020056 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020057
20058 m_errorMonitor->ExpectSuccess();
20059
20060 VkQueryPool query_pool;
20061 VkQueryPoolCreateInfo query_pool_create_info{};
20062 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20063 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20064 query_pool_create_info.queryCount = 1;
20065 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20066
20067 VkCommandPool command_pool;
20068 VkCommandPoolCreateInfo pool_create_info{};
20069 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20070 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20071 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20072 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20073
20074 VkCommandBuffer command_buffer[2];
20075 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20076 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20077 command_buffer_allocate_info.commandPool = command_pool;
20078 command_buffer_allocate_info.commandBufferCount = 2;
20079 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20080 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20081
20082 VkQueue queue = VK_NULL_HANDLE;
20083 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20084
20085 uint32_t qfi = 0;
20086 VkBufferCreateInfo buff_create_info = {};
20087 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20088 buff_create_info.size = 1024;
20089 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20090 buff_create_info.queueFamilyIndexCount = 1;
20091 buff_create_info.pQueueFamilyIndices = &qfi;
20092
20093 VkResult err;
20094 VkBuffer buffer;
20095 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20096 ASSERT_VK_SUCCESS(err);
20097 VkMemoryAllocateInfo mem_alloc = {};
20098 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20099 mem_alloc.pNext = NULL;
20100 mem_alloc.allocationSize = 1024;
20101 mem_alloc.memoryTypeIndex = 0;
20102
20103 VkMemoryRequirements memReqs;
20104 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20105 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20106 if (!pass) {
20107 vkDestroyBuffer(m_device->device(), buffer, NULL);
20108 return;
20109 }
20110
20111 VkDeviceMemory mem;
20112 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20113 ASSERT_VK_SUCCESS(err);
20114 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20115 ASSERT_VK_SUCCESS(err);
20116
20117 {
20118 VkCommandBufferBeginInfo begin_info{};
20119 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20120 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20121
20122 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20123 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20124
20125 vkEndCommandBuffer(command_buffer[0]);
20126
20127 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20128
20129 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20130
20131 vkEndCommandBuffer(command_buffer[1]);
20132 }
20133 {
20134 VkSubmitInfo submit_info{};
20135 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20136 submit_info.commandBufferCount = 2;
20137 submit_info.pCommandBuffers = command_buffer;
20138 submit_info.signalSemaphoreCount = 0;
20139 submit_info.pSignalSemaphores = nullptr;
20140 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20141 }
20142
20143 vkQueueWaitIdle(queue);
20144
20145 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20146 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20147 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20148 vkDestroyBuffer(m_device->device(), buffer, NULL);
20149 vkFreeMemory(m_device->device(), mem, NULL);
20150
20151 m_errorMonitor->VerifyNotFound();
20152}
20153
Tony Barbourc46924f2016-11-04 11:49:52 -060020154TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020155 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20156
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020157 ASSERT_NO_FATAL_FAILURE(InitState());
20158 VkEvent event;
20159 VkEventCreateInfo event_create_info{};
20160 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20161 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20162
20163 VkCommandPool command_pool;
20164 VkCommandPoolCreateInfo pool_create_info{};
20165 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20166 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20167 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20168 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20169
20170 VkCommandBuffer command_buffer;
20171 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20172 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20173 command_buffer_allocate_info.commandPool = command_pool;
20174 command_buffer_allocate_info.commandBufferCount = 1;
20175 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20176 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20177
20178 VkQueue queue = VK_NULL_HANDLE;
20179 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20180
20181 {
20182 VkCommandBufferBeginInfo begin_info{};
20183 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20184 vkBeginCommandBuffer(command_buffer, &begin_info);
20185
20186 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020187 vkEndCommandBuffer(command_buffer);
20188 }
20189 {
20190 VkSubmitInfo submit_info{};
20191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20192 submit_info.commandBufferCount = 1;
20193 submit_info.pCommandBuffers = &command_buffer;
20194 submit_info.signalSemaphoreCount = 0;
20195 submit_info.pSignalSemaphores = nullptr;
20196 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20197 }
20198 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020199 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20200 "that is already in use by a "
20201 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020202 vkSetEvent(m_device->device(), event);
20203 m_errorMonitor->VerifyFound();
20204 }
20205
20206 vkQueueWaitIdle(queue);
20207
20208 vkDestroyEvent(m_device->device(), event, nullptr);
20209 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20210 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20211}
20212
20213// This is a positive test. No errors should be generated.
20214TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020215 TEST_DESCRIPTION(
20216 "Two command buffers with two separate fences are each "
20217 "run through a Submit & WaitForFences cycle 3 times. This "
20218 "previously revealed a bug so running this positive test "
20219 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020220 m_errorMonitor->ExpectSuccess();
20221
20222 ASSERT_NO_FATAL_FAILURE(InitState());
20223 VkQueue queue = VK_NULL_HANDLE;
20224 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20225
20226 static const uint32_t NUM_OBJECTS = 2;
20227 static const uint32_t NUM_FRAMES = 3;
20228 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20229 VkFence fences[NUM_OBJECTS] = {};
20230
20231 VkCommandPool cmd_pool;
20232 VkCommandPoolCreateInfo cmd_pool_ci = {};
20233 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20234 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20235 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20236 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20237 ASSERT_VK_SUCCESS(err);
20238
20239 VkCommandBufferAllocateInfo cmd_buf_info = {};
20240 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20241 cmd_buf_info.commandPool = cmd_pool;
20242 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20243 cmd_buf_info.commandBufferCount = 1;
20244
20245 VkFenceCreateInfo fence_ci = {};
20246 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20247 fence_ci.pNext = nullptr;
20248 fence_ci.flags = 0;
20249
20250 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20251 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20252 ASSERT_VK_SUCCESS(err);
20253 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20254 ASSERT_VK_SUCCESS(err);
20255 }
20256
20257 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20258 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20259 // Create empty cmd buffer
20260 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20261 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20262
20263 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20264 ASSERT_VK_SUCCESS(err);
20265 err = vkEndCommandBuffer(cmd_buffers[obj]);
20266 ASSERT_VK_SUCCESS(err);
20267
20268 VkSubmitInfo submit_info = {};
20269 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20270 submit_info.commandBufferCount = 1;
20271 submit_info.pCommandBuffers = &cmd_buffers[obj];
20272 // Submit cmd buffer and wait for fence
20273 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20274 ASSERT_VK_SUCCESS(err);
20275 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20276 ASSERT_VK_SUCCESS(err);
20277 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20278 ASSERT_VK_SUCCESS(err);
20279 }
20280 }
20281 m_errorMonitor->VerifyNotFound();
20282 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20283 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20284 vkDestroyFence(m_device->device(), fences[i], nullptr);
20285 }
20286}
20287// This is a positive test. No errors should be generated.
20288TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020289 TEST_DESCRIPTION(
20290 "Two command buffers, each in a separate QueueSubmit call "
20291 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020292
20293 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020294 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020295
20296 m_errorMonitor->ExpectSuccess();
20297
20298 VkSemaphore semaphore;
20299 VkSemaphoreCreateInfo semaphore_create_info{};
20300 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20301 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20302
20303 VkCommandPool command_pool;
20304 VkCommandPoolCreateInfo pool_create_info{};
20305 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20306 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20307 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20308 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20309
20310 VkCommandBuffer command_buffer[2];
20311 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20312 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20313 command_buffer_allocate_info.commandPool = command_pool;
20314 command_buffer_allocate_info.commandBufferCount = 2;
20315 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20316 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20317
20318 VkQueue queue = VK_NULL_HANDLE;
20319 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20320
20321 {
20322 VkCommandBufferBeginInfo begin_info{};
20323 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20324 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20325
20326 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 -070020327 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020328
20329 VkViewport viewport{};
20330 viewport.maxDepth = 1.0f;
20331 viewport.minDepth = 0.0f;
20332 viewport.width = 512;
20333 viewport.height = 512;
20334 viewport.x = 0;
20335 viewport.y = 0;
20336 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20337 vkEndCommandBuffer(command_buffer[0]);
20338 }
20339 {
20340 VkCommandBufferBeginInfo begin_info{};
20341 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20342 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20343
20344 VkViewport viewport{};
20345 viewport.maxDepth = 1.0f;
20346 viewport.minDepth = 0.0f;
20347 viewport.width = 512;
20348 viewport.height = 512;
20349 viewport.x = 0;
20350 viewport.y = 0;
20351 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20352 vkEndCommandBuffer(command_buffer[1]);
20353 }
20354 {
20355 VkSubmitInfo submit_info{};
20356 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20357 submit_info.commandBufferCount = 1;
20358 submit_info.pCommandBuffers = &command_buffer[0];
20359 submit_info.signalSemaphoreCount = 1;
20360 submit_info.pSignalSemaphores = &semaphore;
20361 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20362 }
20363 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020364 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020365 VkSubmitInfo submit_info{};
20366 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20367 submit_info.commandBufferCount = 1;
20368 submit_info.pCommandBuffers = &command_buffer[1];
20369 submit_info.waitSemaphoreCount = 1;
20370 submit_info.pWaitSemaphores = &semaphore;
20371 submit_info.pWaitDstStageMask = flags;
20372 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20373 }
20374
20375 vkQueueWaitIdle(m_device->m_queue);
20376
20377 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20378 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20379 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20380
20381 m_errorMonitor->VerifyNotFound();
20382}
20383
20384// This is a positive test. No errors should be generated.
20385TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020386 TEST_DESCRIPTION(
20387 "Two command buffers, each in a separate QueueSubmit call "
20388 "submitted on separate queues, the second having a fence"
20389 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020390
20391 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020392 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020393
20394 m_errorMonitor->ExpectSuccess();
20395
20396 VkFence fence;
20397 VkFenceCreateInfo fence_create_info{};
20398 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20399 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20400
20401 VkSemaphore semaphore;
20402 VkSemaphoreCreateInfo semaphore_create_info{};
20403 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20404 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20405
20406 VkCommandPool command_pool;
20407 VkCommandPoolCreateInfo pool_create_info{};
20408 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20409 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20410 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20411 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20412
20413 VkCommandBuffer command_buffer[2];
20414 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20415 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20416 command_buffer_allocate_info.commandPool = command_pool;
20417 command_buffer_allocate_info.commandBufferCount = 2;
20418 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20419 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20420
20421 VkQueue queue = VK_NULL_HANDLE;
20422 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20423
20424 {
20425 VkCommandBufferBeginInfo begin_info{};
20426 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20427 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20428
20429 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 -070020430 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020431
20432 VkViewport viewport{};
20433 viewport.maxDepth = 1.0f;
20434 viewport.minDepth = 0.0f;
20435 viewport.width = 512;
20436 viewport.height = 512;
20437 viewport.x = 0;
20438 viewport.y = 0;
20439 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20440 vkEndCommandBuffer(command_buffer[0]);
20441 }
20442 {
20443 VkCommandBufferBeginInfo begin_info{};
20444 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20445 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20446
20447 VkViewport viewport{};
20448 viewport.maxDepth = 1.0f;
20449 viewport.minDepth = 0.0f;
20450 viewport.width = 512;
20451 viewport.height = 512;
20452 viewport.x = 0;
20453 viewport.y = 0;
20454 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20455 vkEndCommandBuffer(command_buffer[1]);
20456 }
20457 {
20458 VkSubmitInfo submit_info{};
20459 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20460 submit_info.commandBufferCount = 1;
20461 submit_info.pCommandBuffers = &command_buffer[0];
20462 submit_info.signalSemaphoreCount = 1;
20463 submit_info.pSignalSemaphores = &semaphore;
20464 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20465 }
20466 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020467 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020468 VkSubmitInfo submit_info{};
20469 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20470 submit_info.commandBufferCount = 1;
20471 submit_info.pCommandBuffers = &command_buffer[1];
20472 submit_info.waitSemaphoreCount = 1;
20473 submit_info.pWaitSemaphores = &semaphore;
20474 submit_info.pWaitDstStageMask = flags;
20475 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20476 }
20477
20478 vkQueueWaitIdle(m_device->m_queue);
20479
20480 vkDestroyFence(m_device->device(), fence, nullptr);
20481 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20482 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20483 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20484
20485 m_errorMonitor->VerifyNotFound();
20486}
20487
20488// This is a positive test. No errors should be generated.
20489TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020490 TEST_DESCRIPTION(
20491 "Two command buffers, each in a separate QueueSubmit call "
20492 "submitted on separate queues, the second having a fence"
20493 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020494
20495 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020496 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020497
20498 m_errorMonitor->ExpectSuccess();
20499
20500 VkFence fence;
20501 VkFenceCreateInfo fence_create_info{};
20502 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20503 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20504
20505 VkSemaphore semaphore;
20506 VkSemaphoreCreateInfo semaphore_create_info{};
20507 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20508 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20509
20510 VkCommandPool command_pool;
20511 VkCommandPoolCreateInfo pool_create_info{};
20512 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20513 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20514 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20515 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20516
20517 VkCommandBuffer command_buffer[2];
20518 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20519 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20520 command_buffer_allocate_info.commandPool = command_pool;
20521 command_buffer_allocate_info.commandBufferCount = 2;
20522 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20523 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20524
20525 VkQueue queue = VK_NULL_HANDLE;
20526 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20527
20528 {
20529 VkCommandBufferBeginInfo begin_info{};
20530 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20531 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20532
20533 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 -070020534 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020535
20536 VkViewport viewport{};
20537 viewport.maxDepth = 1.0f;
20538 viewport.minDepth = 0.0f;
20539 viewport.width = 512;
20540 viewport.height = 512;
20541 viewport.x = 0;
20542 viewport.y = 0;
20543 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20544 vkEndCommandBuffer(command_buffer[0]);
20545 }
20546 {
20547 VkCommandBufferBeginInfo begin_info{};
20548 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20549 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20550
20551 VkViewport viewport{};
20552 viewport.maxDepth = 1.0f;
20553 viewport.minDepth = 0.0f;
20554 viewport.width = 512;
20555 viewport.height = 512;
20556 viewport.x = 0;
20557 viewport.y = 0;
20558 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20559 vkEndCommandBuffer(command_buffer[1]);
20560 }
20561 {
20562 VkSubmitInfo submit_info{};
20563 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20564 submit_info.commandBufferCount = 1;
20565 submit_info.pCommandBuffers = &command_buffer[0];
20566 submit_info.signalSemaphoreCount = 1;
20567 submit_info.pSignalSemaphores = &semaphore;
20568 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20569 }
20570 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020571 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020572 VkSubmitInfo submit_info{};
20573 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20574 submit_info.commandBufferCount = 1;
20575 submit_info.pCommandBuffers = &command_buffer[1];
20576 submit_info.waitSemaphoreCount = 1;
20577 submit_info.pWaitSemaphores = &semaphore;
20578 submit_info.pWaitDstStageMask = flags;
20579 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20580 }
20581
20582 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20583 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20584
20585 vkDestroyFence(m_device->device(), fence, nullptr);
20586 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20587 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20588 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20589
20590 m_errorMonitor->VerifyNotFound();
20591}
20592
20593TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020594 ASSERT_NO_FATAL_FAILURE(InitState());
20595 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020596 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020597 return;
20598 }
20599
20600 VkResult err;
20601
20602 m_errorMonitor->ExpectSuccess();
20603
20604 VkQueue q0 = m_device->m_queue;
20605 VkQueue q1 = nullptr;
20606 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20607 ASSERT_NE(q1, nullptr);
20608
20609 // An (empty) command buffer. We must have work in the first submission --
20610 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020611 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020612 VkCommandPool pool;
20613 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20614 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020615 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20616 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020617 VkCommandBuffer cb;
20618 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20619 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020620 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020621 err = vkBeginCommandBuffer(cb, &cbbi);
20622 ASSERT_VK_SUCCESS(err);
20623 err = vkEndCommandBuffer(cb);
20624 ASSERT_VK_SUCCESS(err);
20625
20626 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020627 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020628 VkSemaphore s;
20629 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20630 ASSERT_VK_SUCCESS(err);
20631
20632 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020633 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020634
20635 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20636 ASSERT_VK_SUCCESS(err);
20637
20638 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020639 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020640 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020641
20642 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20643 ASSERT_VK_SUCCESS(err);
20644
20645 // Wait for q0 idle
20646 err = vkQueueWaitIdle(q0);
20647 ASSERT_VK_SUCCESS(err);
20648
20649 // Command buffer should have been completed (it was on q0); reset the pool.
20650 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20651
20652 m_errorMonitor->VerifyNotFound();
20653
20654 // Force device completely idle and clean up resources
20655 vkDeviceWaitIdle(m_device->device());
20656 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20657 vkDestroySemaphore(m_device->device(), s, nullptr);
20658}
20659
20660// This is a positive test. No errors should be generated.
20661TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020662 TEST_DESCRIPTION(
20663 "Two command buffers, each in a separate QueueSubmit call "
20664 "submitted on separate queues, the second having a fence, "
20665 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020666
20667 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020668 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020669
20670 m_errorMonitor->ExpectSuccess();
20671
20672 ASSERT_NO_FATAL_FAILURE(InitState());
20673 VkFence fence;
20674 VkFenceCreateInfo fence_create_info{};
20675 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20676 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20677
20678 VkSemaphore semaphore;
20679 VkSemaphoreCreateInfo semaphore_create_info{};
20680 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20681 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20682
20683 VkCommandPool command_pool;
20684 VkCommandPoolCreateInfo pool_create_info{};
20685 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20686 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20687 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20688 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20689
20690 VkCommandBuffer command_buffer[2];
20691 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20692 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20693 command_buffer_allocate_info.commandPool = command_pool;
20694 command_buffer_allocate_info.commandBufferCount = 2;
20695 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20696 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20697
20698 VkQueue queue = VK_NULL_HANDLE;
20699 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20700
20701 {
20702 VkCommandBufferBeginInfo begin_info{};
20703 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20704 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20705
20706 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 -070020707 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020708
20709 VkViewport viewport{};
20710 viewport.maxDepth = 1.0f;
20711 viewport.minDepth = 0.0f;
20712 viewport.width = 512;
20713 viewport.height = 512;
20714 viewport.x = 0;
20715 viewport.y = 0;
20716 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20717 vkEndCommandBuffer(command_buffer[0]);
20718 }
20719 {
20720 VkCommandBufferBeginInfo begin_info{};
20721 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20722 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20723
20724 VkViewport viewport{};
20725 viewport.maxDepth = 1.0f;
20726 viewport.minDepth = 0.0f;
20727 viewport.width = 512;
20728 viewport.height = 512;
20729 viewport.x = 0;
20730 viewport.y = 0;
20731 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20732 vkEndCommandBuffer(command_buffer[1]);
20733 }
20734 {
20735 VkSubmitInfo submit_info{};
20736 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20737 submit_info.commandBufferCount = 1;
20738 submit_info.pCommandBuffers = &command_buffer[0];
20739 submit_info.signalSemaphoreCount = 1;
20740 submit_info.pSignalSemaphores = &semaphore;
20741 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20742 }
20743 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020744 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020745 VkSubmitInfo submit_info{};
20746 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20747 submit_info.commandBufferCount = 1;
20748 submit_info.pCommandBuffers = &command_buffer[1];
20749 submit_info.waitSemaphoreCount = 1;
20750 submit_info.pWaitSemaphores = &semaphore;
20751 submit_info.pWaitDstStageMask = flags;
20752 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20753 }
20754
20755 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20756
20757 vkDestroyFence(m_device->device(), fence, nullptr);
20758 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20759 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20760 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20761
20762 m_errorMonitor->VerifyNotFound();
20763}
20764
20765// This is a positive test. No errors should be generated.
20766TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020767 TEST_DESCRIPTION(
20768 "Two command buffers, each in a separate QueueSubmit call "
20769 "on the same queue, sharing a signal/wait semaphore, the "
20770 "second having a fence, "
20771 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020772
20773 m_errorMonitor->ExpectSuccess();
20774
20775 ASSERT_NO_FATAL_FAILURE(InitState());
20776 VkFence fence;
20777 VkFenceCreateInfo fence_create_info{};
20778 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20779 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20780
20781 VkSemaphore semaphore;
20782 VkSemaphoreCreateInfo semaphore_create_info{};
20783 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20784 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20785
20786 VkCommandPool command_pool;
20787 VkCommandPoolCreateInfo pool_create_info{};
20788 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20789 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20790 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20791 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20792
20793 VkCommandBuffer command_buffer[2];
20794 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20795 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20796 command_buffer_allocate_info.commandPool = command_pool;
20797 command_buffer_allocate_info.commandBufferCount = 2;
20798 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20799 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20800
20801 {
20802 VkCommandBufferBeginInfo begin_info{};
20803 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20804 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20805
20806 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 -070020807 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020808
20809 VkViewport viewport{};
20810 viewport.maxDepth = 1.0f;
20811 viewport.minDepth = 0.0f;
20812 viewport.width = 512;
20813 viewport.height = 512;
20814 viewport.x = 0;
20815 viewport.y = 0;
20816 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20817 vkEndCommandBuffer(command_buffer[0]);
20818 }
20819 {
20820 VkCommandBufferBeginInfo begin_info{};
20821 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20822 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20823
20824 VkViewport viewport{};
20825 viewport.maxDepth = 1.0f;
20826 viewport.minDepth = 0.0f;
20827 viewport.width = 512;
20828 viewport.height = 512;
20829 viewport.x = 0;
20830 viewport.y = 0;
20831 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20832 vkEndCommandBuffer(command_buffer[1]);
20833 }
20834 {
20835 VkSubmitInfo submit_info{};
20836 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20837 submit_info.commandBufferCount = 1;
20838 submit_info.pCommandBuffers = &command_buffer[0];
20839 submit_info.signalSemaphoreCount = 1;
20840 submit_info.pSignalSemaphores = &semaphore;
20841 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20842 }
20843 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020844 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020845 VkSubmitInfo submit_info{};
20846 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20847 submit_info.commandBufferCount = 1;
20848 submit_info.pCommandBuffers = &command_buffer[1];
20849 submit_info.waitSemaphoreCount = 1;
20850 submit_info.pWaitSemaphores = &semaphore;
20851 submit_info.pWaitDstStageMask = flags;
20852 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20853 }
20854
20855 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20856
20857 vkDestroyFence(m_device->device(), fence, nullptr);
20858 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20859 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20860 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20861
20862 m_errorMonitor->VerifyNotFound();
20863}
20864
20865// This is a positive test. No errors should be generated.
20866TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020867 TEST_DESCRIPTION(
20868 "Two command buffers, each in a separate QueueSubmit call "
20869 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20870 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020871
20872 m_errorMonitor->ExpectSuccess();
20873
20874 ASSERT_NO_FATAL_FAILURE(InitState());
20875 VkFence fence;
20876 VkFenceCreateInfo fence_create_info{};
20877 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20878 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20879
20880 VkCommandPool command_pool;
20881 VkCommandPoolCreateInfo pool_create_info{};
20882 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20883 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20884 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20885 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20886
20887 VkCommandBuffer command_buffer[2];
20888 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20889 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20890 command_buffer_allocate_info.commandPool = command_pool;
20891 command_buffer_allocate_info.commandBufferCount = 2;
20892 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20893 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20894
20895 {
20896 VkCommandBufferBeginInfo begin_info{};
20897 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20898 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20899
20900 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 -070020901 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020902
20903 VkViewport viewport{};
20904 viewport.maxDepth = 1.0f;
20905 viewport.minDepth = 0.0f;
20906 viewport.width = 512;
20907 viewport.height = 512;
20908 viewport.x = 0;
20909 viewport.y = 0;
20910 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20911 vkEndCommandBuffer(command_buffer[0]);
20912 }
20913 {
20914 VkCommandBufferBeginInfo begin_info{};
20915 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20916 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20917
20918 VkViewport viewport{};
20919 viewport.maxDepth = 1.0f;
20920 viewport.minDepth = 0.0f;
20921 viewport.width = 512;
20922 viewport.height = 512;
20923 viewport.x = 0;
20924 viewport.y = 0;
20925 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20926 vkEndCommandBuffer(command_buffer[1]);
20927 }
20928 {
20929 VkSubmitInfo submit_info{};
20930 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20931 submit_info.commandBufferCount = 1;
20932 submit_info.pCommandBuffers = &command_buffer[0];
20933 submit_info.signalSemaphoreCount = 0;
20934 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20935 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20936 }
20937 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020938 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020939 VkSubmitInfo submit_info{};
20940 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20941 submit_info.commandBufferCount = 1;
20942 submit_info.pCommandBuffers = &command_buffer[1];
20943 submit_info.waitSemaphoreCount = 0;
20944 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20945 submit_info.pWaitDstStageMask = flags;
20946 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20947 }
20948
20949 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20950
20951 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20952 ASSERT_VK_SUCCESS(err);
20953
20954 vkDestroyFence(m_device->device(), fence, nullptr);
20955 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20956 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20957
20958 m_errorMonitor->VerifyNotFound();
20959}
20960
20961// This is a positive test. No errors should be generated.
20962TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020963 TEST_DESCRIPTION(
20964 "Two command buffers, each in a separate QueueSubmit call "
20965 "on the same queue, the second having a fence, followed "
20966 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020967
20968 m_errorMonitor->ExpectSuccess();
20969
20970 ASSERT_NO_FATAL_FAILURE(InitState());
20971 VkFence fence;
20972 VkFenceCreateInfo fence_create_info{};
20973 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20974 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20975
20976 VkCommandPool command_pool;
20977 VkCommandPoolCreateInfo pool_create_info{};
20978 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20979 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20980 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20981 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20982
20983 VkCommandBuffer command_buffer[2];
20984 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20985 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20986 command_buffer_allocate_info.commandPool = command_pool;
20987 command_buffer_allocate_info.commandBufferCount = 2;
20988 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20989 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20990
20991 {
20992 VkCommandBufferBeginInfo begin_info{};
20993 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20994 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20995
20996 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 -070020997 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020998
20999 VkViewport viewport{};
21000 viewport.maxDepth = 1.0f;
21001 viewport.minDepth = 0.0f;
21002 viewport.width = 512;
21003 viewport.height = 512;
21004 viewport.x = 0;
21005 viewport.y = 0;
21006 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21007 vkEndCommandBuffer(command_buffer[0]);
21008 }
21009 {
21010 VkCommandBufferBeginInfo begin_info{};
21011 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21012 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21013
21014 VkViewport viewport{};
21015 viewport.maxDepth = 1.0f;
21016 viewport.minDepth = 0.0f;
21017 viewport.width = 512;
21018 viewport.height = 512;
21019 viewport.x = 0;
21020 viewport.y = 0;
21021 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21022 vkEndCommandBuffer(command_buffer[1]);
21023 }
21024 {
21025 VkSubmitInfo submit_info{};
21026 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21027 submit_info.commandBufferCount = 1;
21028 submit_info.pCommandBuffers = &command_buffer[0];
21029 submit_info.signalSemaphoreCount = 0;
21030 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21031 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21032 }
21033 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021034 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021035 VkSubmitInfo submit_info{};
21036 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21037 submit_info.commandBufferCount = 1;
21038 submit_info.pCommandBuffers = &command_buffer[1];
21039 submit_info.waitSemaphoreCount = 0;
21040 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21041 submit_info.pWaitDstStageMask = flags;
21042 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21043 }
21044
21045 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21046
21047 vkDestroyFence(m_device->device(), fence, nullptr);
21048 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21049 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21050
21051 m_errorMonitor->VerifyNotFound();
21052}
21053
21054// This is a positive test. No errors should be generated.
21055TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021056 TEST_DESCRIPTION(
21057 "Two command buffers each in a separate SubmitInfo sent in a single "
21058 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021059 ASSERT_NO_FATAL_FAILURE(InitState());
21060
21061 m_errorMonitor->ExpectSuccess();
21062
21063 VkFence fence;
21064 VkFenceCreateInfo fence_create_info{};
21065 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21066 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21067
21068 VkSemaphore semaphore;
21069 VkSemaphoreCreateInfo semaphore_create_info{};
21070 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21071 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21072
21073 VkCommandPool command_pool;
21074 VkCommandPoolCreateInfo pool_create_info{};
21075 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21076 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21077 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21078 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21079
21080 VkCommandBuffer command_buffer[2];
21081 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21082 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21083 command_buffer_allocate_info.commandPool = command_pool;
21084 command_buffer_allocate_info.commandBufferCount = 2;
21085 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21086 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21087
21088 {
21089 VkCommandBufferBeginInfo begin_info{};
21090 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21091 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21092
21093 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 -070021094 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021095
21096 VkViewport viewport{};
21097 viewport.maxDepth = 1.0f;
21098 viewport.minDepth = 0.0f;
21099 viewport.width = 512;
21100 viewport.height = 512;
21101 viewport.x = 0;
21102 viewport.y = 0;
21103 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21104 vkEndCommandBuffer(command_buffer[0]);
21105 }
21106 {
21107 VkCommandBufferBeginInfo begin_info{};
21108 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21109 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21110
21111 VkViewport viewport{};
21112 viewport.maxDepth = 1.0f;
21113 viewport.minDepth = 0.0f;
21114 viewport.width = 512;
21115 viewport.height = 512;
21116 viewport.x = 0;
21117 viewport.y = 0;
21118 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21119 vkEndCommandBuffer(command_buffer[1]);
21120 }
21121 {
21122 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021123 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021124
21125 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21126 submit_info[0].pNext = NULL;
21127 submit_info[0].commandBufferCount = 1;
21128 submit_info[0].pCommandBuffers = &command_buffer[0];
21129 submit_info[0].signalSemaphoreCount = 1;
21130 submit_info[0].pSignalSemaphores = &semaphore;
21131 submit_info[0].waitSemaphoreCount = 0;
21132 submit_info[0].pWaitSemaphores = NULL;
21133 submit_info[0].pWaitDstStageMask = 0;
21134
21135 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21136 submit_info[1].pNext = NULL;
21137 submit_info[1].commandBufferCount = 1;
21138 submit_info[1].pCommandBuffers = &command_buffer[1];
21139 submit_info[1].waitSemaphoreCount = 1;
21140 submit_info[1].pWaitSemaphores = &semaphore;
21141 submit_info[1].pWaitDstStageMask = flags;
21142 submit_info[1].signalSemaphoreCount = 0;
21143 submit_info[1].pSignalSemaphores = NULL;
21144 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21145 }
21146
21147 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21148
21149 vkDestroyFence(m_device->device(), fence, nullptr);
21150 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21151 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21152 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21153
21154 m_errorMonitor->VerifyNotFound();
21155}
21156
21157TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21158 m_errorMonitor->ExpectSuccess();
21159
21160 ASSERT_NO_FATAL_FAILURE(InitState());
21161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21162
Tony Barbour552f6c02016-12-21 14:34:07 -070021163 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021164
21165 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21166 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21167 m_errorMonitor->VerifyNotFound();
21168 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21169 m_errorMonitor->VerifyNotFound();
21170 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21171 m_errorMonitor->VerifyNotFound();
21172
21173 m_commandBuffer->EndCommandBuffer();
21174 m_errorMonitor->VerifyNotFound();
21175}
21176
21177TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021178 TEST_DESCRIPTION(
21179 "Positive test where we create a renderpass with an "
21180 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21181 "has a valid layout, and a second subpass then uses a "
21182 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021183 m_errorMonitor->ExpectSuccess();
21184 ASSERT_NO_FATAL_FAILURE(InitState());
21185
21186 VkAttachmentReference attach[2] = {};
21187 attach[0].attachment = 0;
21188 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21189 attach[1].attachment = 0;
21190 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21191 VkSubpassDescription subpasses[2] = {};
21192 // First subpass clears DS attach on load
21193 subpasses[0].pDepthStencilAttachment = &attach[0];
21194 // 2nd subpass reads in DS as input attachment
21195 subpasses[1].inputAttachmentCount = 1;
21196 subpasses[1].pInputAttachments = &attach[1];
21197 VkAttachmentDescription attach_desc = {};
21198 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21199 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21200 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21201 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21202 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21203 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21204 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21205 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21206 VkRenderPassCreateInfo rpci = {};
21207 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21208 rpci.attachmentCount = 1;
21209 rpci.pAttachments = &attach_desc;
21210 rpci.subpassCount = 2;
21211 rpci.pSubpasses = subpasses;
21212
21213 // Now create RenderPass and verify no errors
21214 VkRenderPass rp;
21215 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21216 m_errorMonitor->VerifyNotFound();
21217
21218 vkDestroyRenderPass(m_device->device(), rp, NULL);
21219}
21220
Tobin Ehlis01103de2017-02-16 13:22:47 -070021221TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21222 TEST_DESCRIPTION(
21223 "Create a render pass with depth-stencil attachment where layout transition "
21224 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21225 "transition has correctly occurred at queue submit time with no validation errors.");
21226
21227 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21228 VkImageFormatProperties format_props;
21229 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21230 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21231 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21232 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21233 return;
21234 }
21235
21236 m_errorMonitor->ExpectSuccess();
21237 ASSERT_NO_FATAL_FAILURE(InitState());
21238 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21239
21240 // A renderpass with one depth/stencil attachment.
21241 VkAttachmentDescription attachment = {0,
21242 ds_format,
21243 VK_SAMPLE_COUNT_1_BIT,
21244 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21245 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21246 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21247 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21248 VK_IMAGE_LAYOUT_UNDEFINED,
21249 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21250
21251 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21252
21253 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21254
21255 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21256
21257 VkRenderPass rp;
21258 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21259 ASSERT_VK_SUCCESS(err);
21260 // A compatible ds image.
21261 VkImageObj image(m_device);
21262 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21263 ASSERT_TRUE(image.initialized());
21264
21265 VkImageViewCreateInfo ivci = {
21266 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21267 nullptr,
21268 0,
21269 image.handle(),
21270 VK_IMAGE_VIEW_TYPE_2D,
21271 ds_format,
21272 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21273 VK_COMPONENT_SWIZZLE_IDENTITY},
21274 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21275 };
21276 VkImageView view;
21277 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21278 ASSERT_VK_SUCCESS(err);
21279
21280 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21281 VkFramebuffer fb;
21282 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21283 ASSERT_VK_SUCCESS(err);
21284
21285 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21286 m_commandBuffer->BeginCommandBuffer();
21287 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21288 vkCmdEndRenderPass(m_commandBuffer->handle());
21289 m_commandBuffer->EndCommandBuffer();
21290 QueueCommandBuffer(false);
21291 m_errorMonitor->VerifyNotFound();
21292
21293 // Cleanup
21294 vkDestroyImageView(m_device->device(), view, NULL);
21295 vkDestroyRenderPass(m_device->device(), rp, NULL);
21296 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21297}
21298
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021299TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021300 TEST_DESCRIPTION(
21301 "Test that pipeline validation accepts matrices passed "
21302 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021303 m_errorMonitor->ExpectSuccess();
21304
21305 ASSERT_NO_FATAL_FAILURE(InitState());
21306 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21307
21308 VkVertexInputBindingDescription input_binding;
21309 memset(&input_binding, 0, sizeof(input_binding));
21310
21311 VkVertexInputAttributeDescription input_attribs[2];
21312 memset(input_attribs, 0, sizeof(input_attribs));
21313
21314 for (int i = 0; i < 2; i++) {
21315 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21316 input_attribs[i].location = i;
21317 }
21318
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021319 char const *vsSource =
21320 "#version 450\n"
21321 "\n"
21322 "layout(location=0) in mat2x4 x;\n"
21323 "out gl_PerVertex {\n"
21324 " vec4 gl_Position;\n"
21325 "};\n"
21326 "void main(){\n"
21327 " gl_Position = x[0] + x[1];\n"
21328 "}\n";
21329 char const *fsSource =
21330 "#version 450\n"
21331 "\n"
21332 "layout(location=0) out vec4 color;\n"
21333 "void main(){\n"
21334 " color = vec4(1);\n"
21335 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021336
21337 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21338 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21339
21340 VkPipelineObj pipe(m_device);
21341 pipe.AddColorAttachment();
21342 pipe.AddShader(&vs);
21343 pipe.AddShader(&fs);
21344
21345 pipe.AddVertexInputBindings(&input_binding, 1);
21346 pipe.AddVertexInputAttribs(input_attribs, 2);
21347
21348 VkDescriptorSetObj descriptorSet(m_device);
21349 descriptorSet.AppendDummy();
21350 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21351
21352 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21353
21354 /* expect success */
21355 m_errorMonitor->VerifyNotFound();
21356}
21357
21358TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21359 m_errorMonitor->ExpectSuccess();
21360
21361 ASSERT_NO_FATAL_FAILURE(InitState());
21362 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21363
21364 VkVertexInputBindingDescription input_binding;
21365 memset(&input_binding, 0, sizeof(input_binding));
21366
21367 VkVertexInputAttributeDescription input_attribs[2];
21368 memset(input_attribs, 0, sizeof(input_attribs));
21369
21370 for (int i = 0; i < 2; i++) {
21371 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21372 input_attribs[i].location = i;
21373 }
21374
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021375 char const *vsSource =
21376 "#version 450\n"
21377 "\n"
21378 "layout(location=0) in vec4 x[2];\n"
21379 "out gl_PerVertex {\n"
21380 " vec4 gl_Position;\n"
21381 "};\n"
21382 "void main(){\n"
21383 " gl_Position = x[0] + x[1];\n"
21384 "}\n";
21385 char const *fsSource =
21386 "#version 450\n"
21387 "\n"
21388 "layout(location=0) out vec4 color;\n"
21389 "void main(){\n"
21390 " color = vec4(1);\n"
21391 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021392
21393 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21394 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21395
21396 VkPipelineObj pipe(m_device);
21397 pipe.AddColorAttachment();
21398 pipe.AddShader(&vs);
21399 pipe.AddShader(&fs);
21400
21401 pipe.AddVertexInputBindings(&input_binding, 1);
21402 pipe.AddVertexInputAttribs(input_attribs, 2);
21403
21404 VkDescriptorSetObj descriptorSet(m_device);
21405 descriptorSet.AppendDummy();
21406 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21407
21408 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21409
21410 m_errorMonitor->VerifyNotFound();
21411}
21412
21413TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021414 TEST_DESCRIPTION(
21415 "Test that pipeline validation accepts consuming a vertex attribute "
21416 "through multiple vertex shader inputs, each consuming a different "
21417 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021418 m_errorMonitor->ExpectSuccess();
21419
21420 ASSERT_NO_FATAL_FAILURE(InitState());
21421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21422
21423 VkVertexInputBindingDescription input_binding;
21424 memset(&input_binding, 0, sizeof(input_binding));
21425
21426 VkVertexInputAttributeDescription input_attribs[3];
21427 memset(input_attribs, 0, sizeof(input_attribs));
21428
21429 for (int i = 0; i < 3; i++) {
21430 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21431 input_attribs[i].location = i;
21432 }
21433
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021434 char const *vsSource =
21435 "#version 450\n"
21436 "\n"
21437 "layout(location=0) in vec4 x;\n"
21438 "layout(location=1) in vec3 y1;\n"
21439 "layout(location=1, component=3) in float y2;\n"
21440 "layout(location=2) in vec4 z;\n"
21441 "out gl_PerVertex {\n"
21442 " vec4 gl_Position;\n"
21443 "};\n"
21444 "void main(){\n"
21445 " gl_Position = x + vec4(y1, y2) + z;\n"
21446 "}\n";
21447 char const *fsSource =
21448 "#version 450\n"
21449 "\n"
21450 "layout(location=0) out vec4 color;\n"
21451 "void main(){\n"
21452 " color = vec4(1);\n"
21453 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021454
21455 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21456 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21457
21458 VkPipelineObj pipe(m_device);
21459 pipe.AddColorAttachment();
21460 pipe.AddShader(&vs);
21461 pipe.AddShader(&fs);
21462
21463 pipe.AddVertexInputBindings(&input_binding, 1);
21464 pipe.AddVertexInputAttribs(input_attribs, 3);
21465
21466 VkDescriptorSetObj descriptorSet(m_device);
21467 descriptorSet.AppendDummy();
21468 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21469
21470 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21471
21472 m_errorMonitor->VerifyNotFound();
21473}
21474
21475TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21476 m_errorMonitor->ExpectSuccess();
21477
21478 ASSERT_NO_FATAL_FAILURE(InitState());
21479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21480
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021481 char const *vsSource =
21482 "#version 450\n"
21483 "out gl_PerVertex {\n"
21484 " vec4 gl_Position;\n"
21485 "};\n"
21486 "void main(){\n"
21487 " gl_Position = vec4(0);\n"
21488 "}\n";
21489 char const *fsSource =
21490 "#version 450\n"
21491 "\n"
21492 "layout(location=0) out vec4 color;\n"
21493 "void main(){\n"
21494 " color = vec4(1);\n"
21495 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021496
21497 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21498 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21499
21500 VkPipelineObj pipe(m_device);
21501 pipe.AddColorAttachment();
21502 pipe.AddShader(&vs);
21503 pipe.AddShader(&fs);
21504
21505 VkDescriptorSetObj descriptorSet(m_device);
21506 descriptorSet.AppendDummy();
21507 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21508
21509 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21510
21511 m_errorMonitor->VerifyNotFound();
21512}
21513
21514TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021515 TEST_DESCRIPTION(
21516 "Test that pipeline validation accepts the relaxed type matching rules "
21517 "set out in 14.1.3: fundamental type must match, and producer side must "
21518 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021519 m_errorMonitor->ExpectSuccess();
21520
21521 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21522
21523 ASSERT_NO_FATAL_FAILURE(InitState());
21524 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21525
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021526 char const *vsSource =
21527 "#version 450\n"
21528 "out gl_PerVertex {\n"
21529 " vec4 gl_Position;\n"
21530 "};\n"
21531 "layout(location=0) out vec3 x;\n"
21532 "layout(location=1) out ivec3 y;\n"
21533 "layout(location=2) out vec3 z;\n"
21534 "void main(){\n"
21535 " gl_Position = vec4(0);\n"
21536 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21537 "}\n";
21538 char const *fsSource =
21539 "#version 450\n"
21540 "\n"
21541 "layout(location=0) out vec4 color;\n"
21542 "layout(location=0) in float x;\n"
21543 "layout(location=1) flat in int y;\n"
21544 "layout(location=2) in vec2 z;\n"
21545 "void main(){\n"
21546 " color = vec4(1 + x + y + z.x);\n"
21547 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021548
21549 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21550 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21551
21552 VkPipelineObj pipe(m_device);
21553 pipe.AddColorAttachment();
21554 pipe.AddShader(&vs);
21555 pipe.AddShader(&fs);
21556
21557 VkDescriptorSetObj descriptorSet(m_device);
21558 descriptorSet.AppendDummy();
21559 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21560
21561 VkResult err = VK_SUCCESS;
21562 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21563 ASSERT_VK_SUCCESS(err);
21564
21565 m_errorMonitor->VerifyNotFound();
21566}
21567
21568TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021569 TEST_DESCRIPTION(
21570 "Test that pipeline validation accepts per-vertex variables "
21571 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021572 m_errorMonitor->ExpectSuccess();
21573
21574 ASSERT_NO_FATAL_FAILURE(InitState());
21575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21576
21577 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021578 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021579 return;
21580 }
21581
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021582 char const *vsSource =
21583 "#version 450\n"
21584 "void main(){}\n";
21585 char const *tcsSource =
21586 "#version 450\n"
21587 "layout(location=0) out int x[];\n"
21588 "layout(vertices=3) out;\n"
21589 "void main(){\n"
21590 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21591 " gl_TessLevelInner[0] = 1;\n"
21592 " x[gl_InvocationID] = gl_InvocationID;\n"
21593 "}\n";
21594 char const *tesSource =
21595 "#version 450\n"
21596 "layout(triangles, equal_spacing, cw) in;\n"
21597 "layout(location=0) in int x[];\n"
21598 "out gl_PerVertex { vec4 gl_Position; };\n"
21599 "void main(){\n"
21600 " gl_Position.xyz = gl_TessCoord;\n"
21601 " gl_Position.w = x[0] + x[1] + x[2];\n"
21602 "}\n";
21603 char const *fsSource =
21604 "#version 450\n"
21605 "layout(location=0) out vec4 color;\n"
21606 "void main(){\n"
21607 " color = vec4(1);\n"
21608 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021609
21610 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21611 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21612 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21613 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21614
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021615 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21616 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021617
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021618 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021619
21620 VkPipelineObj pipe(m_device);
21621 pipe.SetInputAssembly(&iasci);
21622 pipe.SetTessellation(&tsci);
21623 pipe.AddColorAttachment();
21624 pipe.AddShader(&vs);
21625 pipe.AddShader(&tcs);
21626 pipe.AddShader(&tes);
21627 pipe.AddShader(&fs);
21628
21629 VkDescriptorSetObj descriptorSet(m_device);
21630 descriptorSet.AppendDummy();
21631 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21632
21633 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21634
21635 m_errorMonitor->VerifyNotFound();
21636}
21637
21638TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021639 TEST_DESCRIPTION(
21640 "Test that pipeline validation accepts a user-defined "
21641 "interface block passed into the geometry shader. This "
21642 "is interesting because the 'extra' array level is not "
21643 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021644 m_errorMonitor->ExpectSuccess();
21645
21646 ASSERT_NO_FATAL_FAILURE(InitState());
21647 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21648
21649 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021650 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021651 return;
21652 }
21653
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021654 char const *vsSource =
21655 "#version 450\n"
21656 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21657 "void main(){\n"
21658 " vs_out.x = vec4(1);\n"
21659 "}\n";
21660 char const *gsSource =
21661 "#version 450\n"
21662 "layout(triangles) in;\n"
21663 "layout(triangle_strip, max_vertices=3) out;\n"
21664 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21665 "out gl_PerVertex { vec4 gl_Position; };\n"
21666 "void main() {\n"
21667 " gl_Position = gs_in[0].x;\n"
21668 " EmitVertex();\n"
21669 "}\n";
21670 char const *fsSource =
21671 "#version 450\n"
21672 "layout(location=0) out vec4 color;\n"
21673 "void main(){\n"
21674 " color = vec4(1);\n"
21675 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021676
21677 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21678 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21679 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21680
21681 VkPipelineObj pipe(m_device);
21682 pipe.AddColorAttachment();
21683 pipe.AddShader(&vs);
21684 pipe.AddShader(&gs);
21685 pipe.AddShader(&fs);
21686
21687 VkDescriptorSetObj descriptorSet(m_device);
21688 descriptorSet.AppendDummy();
21689 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21690
21691 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21692
21693 m_errorMonitor->VerifyNotFound();
21694}
21695
21696TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021697 TEST_DESCRIPTION(
21698 "Test that pipeline validation accepts basic use of 64bit vertex "
21699 "attributes. This is interesting because they consume multiple "
21700 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021701 m_errorMonitor->ExpectSuccess();
21702
21703 ASSERT_NO_FATAL_FAILURE(InitState());
21704 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21705
21706 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021707 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021708 return;
21709 }
21710
21711 VkVertexInputBindingDescription input_bindings[1];
21712 memset(input_bindings, 0, sizeof(input_bindings));
21713
21714 VkVertexInputAttributeDescription input_attribs[4];
21715 memset(input_attribs, 0, sizeof(input_attribs));
21716 input_attribs[0].location = 0;
21717 input_attribs[0].offset = 0;
21718 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21719 input_attribs[1].location = 2;
21720 input_attribs[1].offset = 32;
21721 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21722 input_attribs[2].location = 4;
21723 input_attribs[2].offset = 64;
21724 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21725 input_attribs[3].location = 6;
21726 input_attribs[3].offset = 96;
21727 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21728
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021729 char const *vsSource =
21730 "#version 450\n"
21731 "\n"
21732 "layout(location=0) in dmat4 x;\n"
21733 "out gl_PerVertex {\n"
21734 " vec4 gl_Position;\n"
21735 "};\n"
21736 "void main(){\n"
21737 " gl_Position = vec4(x[0][0]);\n"
21738 "}\n";
21739 char const *fsSource =
21740 "#version 450\n"
21741 "\n"
21742 "layout(location=0) out vec4 color;\n"
21743 "void main(){\n"
21744 " color = vec4(1);\n"
21745 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021746
21747 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21748 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21749
21750 VkPipelineObj pipe(m_device);
21751 pipe.AddColorAttachment();
21752 pipe.AddShader(&vs);
21753 pipe.AddShader(&fs);
21754
21755 pipe.AddVertexInputBindings(input_bindings, 1);
21756 pipe.AddVertexInputAttribs(input_attribs, 4);
21757
21758 VkDescriptorSetObj descriptorSet(m_device);
21759 descriptorSet.AppendDummy();
21760 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21761
21762 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21763
21764 m_errorMonitor->VerifyNotFound();
21765}
21766
21767TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21768 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21769 m_errorMonitor->ExpectSuccess();
21770
21771 ASSERT_NO_FATAL_FAILURE(InitState());
21772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021773 char const *vsSource =
21774 "#version 450\n"
21775 "\n"
21776 "out gl_PerVertex {\n"
21777 " vec4 gl_Position;\n"
21778 "};\n"
21779 "void main(){\n"
21780 " gl_Position = vec4(1);\n"
21781 "}\n";
21782 char const *fsSource =
21783 "#version 450\n"
21784 "\n"
21785 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21786 "layout(location=0) out vec4 color;\n"
21787 "void main() {\n"
21788 " color = subpassLoad(x);\n"
21789 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021790
21791 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21792 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21793
21794 VkPipelineObj pipe(m_device);
21795 pipe.AddShader(&vs);
21796 pipe.AddShader(&fs);
21797 pipe.AddColorAttachment();
21798 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21799
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021800 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21801 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021802 VkDescriptorSetLayout dsl;
21803 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21804 ASSERT_VK_SUCCESS(err);
21805
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021806 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021807 VkPipelineLayout pl;
21808 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21809 ASSERT_VK_SUCCESS(err);
21810
21811 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021812 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21813 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21814 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21815 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21816 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 -060021817 };
21818 VkAttachmentReference color = {
21819 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21820 };
21821 VkAttachmentReference input = {
21822 1, VK_IMAGE_LAYOUT_GENERAL,
21823 };
21824
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021825 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021826
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021827 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021828 VkRenderPass rp;
21829 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21830 ASSERT_VK_SUCCESS(err);
21831
21832 // should be OK. would go wrong here if it's going to...
21833 pipe.CreateVKPipeline(pl, rp);
21834
21835 m_errorMonitor->VerifyNotFound();
21836
21837 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21838 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21839 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21840}
21841
21842TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021843 TEST_DESCRIPTION(
21844 "Test that pipeline validation accepts a compute pipeline which declares a "
21845 "descriptor-backed resource which is not provided, but the shader does not "
21846 "statically use it. This is interesting because it requires compute pipelines "
21847 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021848 m_errorMonitor->ExpectSuccess();
21849
21850 ASSERT_NO_FATAL_FAILURE(InitState());
21851
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021852 char const *csSource =
21853 "#version 450\n"
21854 "\n"
21855 "layout(local_size_x=1) in;\n"
21856 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21857 "void main(){\n"
21858 " // x is not used.\n"
21859 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021860
21861 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21862
21863 VkDescriptorSetObj descriptorSet(m_device);
21864 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21865
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021866 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21867 nullptr,
21868 0,
21869 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21870 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21871 descriptorSet.GetPipelineLayout(),
21872 VK_NULL_HANDLE,
21873 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021874
21875 VkPipeline pipe;
21876 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21877
21878 m_errorMonitor->VerifyNotFound();
21879
21880 if (err == VK_SUCCESS) {
21881 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21882 }
21883}
21884
21885TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021886 TEST_DESCRIPTION(
21887 "Test that pipeline validation accepts a shader consuming only the "
21888 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021889 m_errorMonitor->ExpectSuccess();
21890
21891 ASSERT_NO_FATAL_FAILURE(InitState());
21892
21893 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021894 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21895 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21896 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021897 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021898 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021899 VkDescriptorSetLayout dsl;
21900 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21901 ASSERT_VK_SUCCESS(err);
21902
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021903 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021904 VkPipelineLayout pl;
21905 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21906 ASSERT_VK_SUCCESS(err);
21907
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021908 char const *csSource =
21909 "#version 450\n"
21910 "\n"
21911 "layout(local_size_x=1) in;\n"
21912 "layout(set=0, binding=0) uniform sampler s;\n"
21913 "layout(set=0, binding=1) uniform texture2D t;\n"
21914 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21915 "void main() {\n"
21916 " x = texture(sampler2D(t, s), vec2(0));\n"
21917 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021918 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21919
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021920 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21921 nullptr,
21922 0,
21923 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21924 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21925 pl,
21926 VK_NULL_HANDLE,
21927 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021928
21929 VkPipeline pipe;
21930 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21931
21932 m_errorMonitor->VerifyNotFound();
21933
21934 if (err == VK_SUCCESS) {
21935 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21936 }
21937
21938 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21939 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21940}
21941
21942TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021943 TEST_DESCRIPTION(
21944 "Test that pipeline validation accepts a shader consuming only the "
21945 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021946 m_errorMonitor->ExpectSuccess();
21947
21948 ASSERT_NO_FATAL_FAILURE(InitState());
21949
21950 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021951 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21952 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21953 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021954 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021955 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021956 VkDescriptorSetLayout dsl;
21957 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21958 ASSERT_VK_SUCCESS(err);
21959
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021960 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021961 VkPipelineLayout pl;
21962 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21963 ASSERT_VK_SUCCESS(err);
21964
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021965 char const *csSource =
21966 "#version 450\n"
21967 "\n"
21968 "layout(local_size_x=1) in;\n"
21969 "layout(set=0, binding=0) uniform texture2D t;\n"
21970 "layout(set=0, binding=1) uniform sampler s;\n"
21971 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21972 "void main() {\n"
21973 " x = texture(sampler2D(t, s), vec2(0));\n"
21974 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021975 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21976
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021977 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21978 nullptr,
21979 0,
21980 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21981 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21982 pl,
21983 VK_NULL_HANDLE,
21984 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021985
21986 VkPipeline pipe;
21987 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21988
21989 m_errorMonitor->VerifyNotFound();
21990
21991 if (err == VK_SUCCESS) {
21992 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21993 }
21994
21995 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21996 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21997}
21998
21999TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022000 TEST_DESCRIPTION(
22001 "Test that pipeline validation accepts a shader consuming "
22002 "both the sampler and the image of a combined image+sampler "
22003 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022004 m_errorMonitor->ExpectSuccess();
22005
22006 ASSERT_NO_FATAL_FAILURE(InitState());
22007
22008 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022009 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22010 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022011 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022012 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022013 VkDescriptorSetLayout dsl;
22014 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22015 ASSERT_VK_SUCCESS(err);
22016
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022017 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022018 VkPipelineLayout pl;
22019 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22020 ASSERT_VK_SUCCESS(err);
22021
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022022 char const *csSource =
22023 "#version 450\n"
22024 "\n"
22025 "layout(local_size_x=1) in;\n"
22026 "layout(set=0, binding=0) uniform texture2D t;\n"
22027 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22028 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22029 "void main() {\n"
22030 " x = texture(sampler2D(t, s), vec2(0));\n"
22031 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022032 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22033
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022034 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22035 nullptr,
22036 0,
22037 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22038 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22039 pl,
22040 VK_NULL_HANDLE,
22041 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022042
22043 VkPipeline pipe;
22044 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22045
22046 m_errorMonitor->VerifyNotFound();
22047
22048 if (err == VK_SUCCESS) {
22049 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22050 }
22051
22052 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22053 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22054}
22055
22056TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22057 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22058
22059 ASSERT_NO_FATAL_FAILURE(InitState());
22060
22061 // Positive test to check parameter_validation and unique_objects support
22062 // for NV_dedicated_allocation
22063 uint32_t extension_count = 0;
22064 bool supports_nv_dedicated_allocation = false;
22065 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22066 ASSERT_VK_SUCCESS(err);
22067
22068 if (extension_count > 0) {
22069 std::vector<VkExtensionProperties> available_extensions(extension_count);
22070
22071 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22072 ASSERT_VK_SUCCESS(err);
22073
22074 for (const auto &extension_props : available_extensions) {
22075 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22076 supports_nv_dedicated_allocation = true;
22077 }
22078 }
22079 }
22080
22081 if (supports_nv_dedicated_allocation) {
22082 m_errorMonitor->ExpectSuccess();
22083
22084 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22085 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22086 dedicated_buffer_create_info.pNext = nullptr;
22087 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22088
22089 uint32_t queue_family_index = 0;
22090 VkBufferCreateInfo buffer_create_info = {};
22091 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22092 buffer_create_info.pNext = &dedicated_buffer_create_info;
22093 buffer_create_info.size = 1024;
22094 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22095 buffer_create_info.queueFamilyIndexCount = 1;
22096 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22097
22098 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022099 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022100 ASSERT_VK_SUCCESS(err);
22101
22102 VkMemoryRequirements memory_reqs;
22103 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22104
22105 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22106 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22107 dedicated_memory_info.pNext = nullptr;
22108 dedicated_memory_info.buffer = buffer;
22109 dedicated_memory_info.image = VK_NULL_HANDLE;
22110
22111 VkMemoryAllocateInfo memory_info = {};
22112 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22113 memory_info.pNext = &dedicated_memory_info;
22114 memory_info.allocationSize = memory_reqs.size;
22115
22116 bool pass;
22117 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22118 ASSERT_TRUE(pass);
22119
22120 VkDeviceMemory buffer_memory;
22121 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22122 ASSERT_VK_SUCCESS(err);
22123
22124 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22125 ASSERT_VK_SUCCESS(err);
22126
22127 vkDestroyBuffer(m_device->device(), buffer, NULL);
22128 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22129
22130 m_errorMonitor->VerifyNotFound();
22131 }
22132}
22133
22134TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22135 VkResult err;
22136
22137 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22138
22139 ASSERT_NO_FATAL_FAILURE(InitState());
22140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22141
22142 std::vector<const char *> device_extension_names;
22143 auto features = m_device->phy().features();
22144 // Artificially disable support for non-solid fill modes
22145 features.fillModeNonSolid = false;
22146 // The sacrificial device object
22147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22148
22149 VkRenderpassObj render_pass(&test_device);
22150
22151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22153 pipeline_layout_ci.setLayoutCount = 0;
22154 pipeline_layout_ci.pSetLayouts = NULL;
22155
22156 VkPipelineLayout pipeline_layout;
22157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22158 ASSERT_VK_SUCCESS(err);
22159
22160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22162 rs_ci.pNext = nullptr;
22163 rs_ci.lineWidth = 1.0f;
22164 rs_ci.rasterizerDiscardEnable = true;
22165
22166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22168
22169 // Set polygonMode=FILL. No error is expected
22170 m_errorMonitor->ExpectSuccess();
22171 {
22172 VkPipelineObj pipe(&test_device);
22173 pipe.AddShader(&vs);
22174 pipe.AddShader(&fs);
22175 pipe.AddColorAttachment();
22176 // Set polygonMode to a good value
22177 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22178 pipe.SetRasterization(&rs_ci);
22179 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22180 }
22181 m_errorMonitor->VerifyNotFound();
22182
22183 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22184}
22185
22186TEST_F(VkPositiveLayerTest, ValidPushConstants) {
22187 VkResult err;
22188 ASSERT_NO_FATAL_FAILURE(InitState());
22189 ASSERT_NO_FATAL_FAILURE(InitViewport());
22190 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22191
22192 VkPipelineLayout pipeline_layout;
22193 VkPushConstantRange pc_range = {};
22194 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22195 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22196 pipeline_layout_ci.pushConstantRangeCount = 1;
22197 pipeline_layout_ci.pPushConstantRanges = &pc_range;
22198
22199 //
22200 // Check for invalid push constant ranges in pipeline layouts.
22201 //
22202 struct PipelineLayoutTestCase {
22203 VkPushConstantRange const range;
22204 char const *msg;
22205 };
22206
22207 // Check for overlapping ranges
22208 const uint32_t ranges_per_test = 5;
22209 struct OverlappingRangeTestCase {
22210 VkPushConstantRange const ranges[ranges_per_test];
22211 char const *msg;
22212 };
22213
22214 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022215 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
22216 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
22217 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
22218 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
22219 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
22220 ""},
22221 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
22222 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
22223 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
22224 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
22225 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
22226 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022227 for (const auto &iter : overlapping_range_tests_pos) {
22228 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
22229 m_errorMonitor->ExpectSuccess();
22230 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22231 m_errorMonitor->VerifyNotFound();
22232 if (VK_SUCCESS == err) {
22233 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22234 }
22235 }
22236
22237 //
22238 // CmdPushConstants tests
22239 //
22240 const uint8_t dummy_values[100] = {};
22241
Tony Barbour552f6c02016-12-21 14:34:07 -070022242 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022243
22244 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022245 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
22246 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
22247 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
22248 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
22249 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
22250 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022251
22252 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
22253 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022254 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
22255 {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 -060022256 };
22257
22258 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
22259 pipeline_layout_ci.pPushConstantRanges = pc_range4;
22260 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22261 ASSERT_VK_SUCCESS(err);
22262 for (const auto &iter : cmd_overlap_tests_pos) {
22263 m_errorMonitor->ExpectSuccess();
22264 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022265 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022266 m_errorMonitor->VerifyNotFound();
22267 }
22268 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22269
Tony Barbour552f6c02016-12-21 14:34:07 -070022270 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022271}
22272
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022273#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022274TEST_F(VkPositiveLayerTest, LongFenceChain)
22275{
22276 m_errorMonitor->ExpectSuccess();
22277
22278 ASSERT_NO_FATAL_FAILURE(InitState());
22279 VkResult err;
22280
22281 std::vector<VkFence> fences;
22282
22283 const int chainLength = 32768;
22284
22285 for (int i = 0; i < chainLength; i++) {
22286 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22287 VkFence fence;
22288 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22289 ASSERT_VK_SUCCESS(err);
22290
22291 fences.push_back(fence);
22292
22293 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22294 0, nullptr, 0, nullptr };
22295 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22296 ASSERT_VK_SUCCESS(err);
22297
22298 }
22299
22300 // BOOM, stack overflow.
22301 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22302
22303 for (auto fence : fences)
22304 vkDestroyFence(m_device->device(), fence, nullptr);
22305
22306 m_errorMonitor->VerifyNotFound();
22307}
22308#endif
22309
Cody Northrop1242dfd2016-07-13 17:24:59 -060022310#if defined(ANDROID) && defined(VALIDATION_APK)
22311static bool initialized = false;
22312static bool active = false;
22313
22314// Convert Intents to argv
22315// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022316std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022317 std::vector<std::string> args;
22318 JavaVM &vm = *app.activity->vm;
22319 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022320 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022321
22322 JNIEnv &env = *p_env;
22323 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022324 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022325 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022326 jmethodID get_string_extra_method =
22327 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022328 jvalue get_string_extra_args;
22329 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022330 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022331
22332 std::string args_str;
22333 if (extra_str) {
22334 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22335 args_str = extra_utf;
22336 env.ReleaseStringUTFChars(extra_str, extra_utf);
22337 env.DeleteLocalRef(extra_str);
22338 }
22339
22340 env.DeleteLocalRef(get_string_extra_args.l);
22341 env.DeleteLocalRef(intent);
22342 vm.DetachCurrentThread();
22343
22344 // split args_str
22345 std::stringstream ss(args_str);
22346 std::string arg;
22347 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022348 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022349 }
22350
22351 return args;
22352}
22353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022354static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022356static void processCommand(struct android_app *app, int32_t cmd) {
22357 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022358 case APP_CMD_INIT_WINDOW: {
22359 if (app->window) {
22360 initialized = true;
22361 }
22362 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022363 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022364 case APP_CMD_GAINED_FOCUS: {
22365 active = true;
22366 break;
22367 }
22368 case APP_CMD_LOST_FOCUS: {
22369 active = false;
22370 break;
22371 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022372 }
22373}
22374
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022375void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022376 app_dummy();
22377
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022378 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022379
22380 int vulkanSupport = InitVulkan();
22381 if (vulkanSupport == 0) {
22382 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22383 return;
22384 }
22385
22386 app->onAppCmd = processCommand;
22387 app->onInputEvent = processInput;
22388
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022389 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022390 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022391 struct android_poll_source *source;
22392 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022393 if (source) {
22394 source->process(app, source);
22395 }
22396
22397 if (app->destroyRequested != 0) {
22398 VkTestFramework::Finish();
22399 return;
22400 }
22401 }
22402
22403 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022404 // Use the following key to send arguments to gtest, i.e.
22405 // --es args "--gtest_filter=-VkLayerTest.foo"
22406 const char key[] = "args";
22407 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022409 std::string filter = "";
22410 if (args.size() > 0) {
22411 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22412 filter += args[0];
22413 } else {
22414 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22415 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022416
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022417 int argc = 2;
22418 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22419 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022421 // Route output to files until we can override the gtest output
22422 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22423 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022425 ::testing::InitGoogleTest(&argc, argv);
22426 VkTestFramework::InitArgs(&argc, argv);
22427 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022429 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022430
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022431 if (result != 0) {
22432 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22433 } else {
22434 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22435 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022437 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022438
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022439 fclose(stdout);
22440 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022441
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022442 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022443 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022444 }
22445 }
22446}
22447#endif
22448
Tony Barbour300a6082015-04-07 13:44:53 -060022449int main(int argc, char **argv) {
22450 int result;
22451
Cody Northrop8e54a402016-03-08 22:25:52 -070022452#ifdef ANDROID
22453 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022454 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022455#endif
22456
Tony Barbour300a6082015-04-07 13:44:53 -060022457 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022458 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022459
22460 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22461
22462 result = RUN_ALL_TESTS();
22463
Tony Barbour6918cd52015-04-09 12:58:51 -060022464 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022465 return result;
22466}