blob: e84b54690320fc8fda9dd3a0c71bd16e8c216a89 [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();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004661 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004662 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4663
4664 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004665 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004666 vkFreeMemory(m_device->handle(), mem, NULL);
4667}
4668
Tobin Ehlisea413442016-09-28 10:23:59 -06004669TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4670 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4671
4672 ASSERT_NO_FATAL_FAILURE(InitState());
4673 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4674
4675 VkDescriptorPoolSize ds_type_count;
4676 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4677 ds_type_count.descriptorCount = 1;
4678
4679 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4680 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4681 ds_pool_ci.maxSets = 1;
4682 ds_pool_ci.poolSizeCount = 1;
4683 ds_pool_ci.pPoolSizes = &ds_type_count;
4684
4685 VkDescriptorPool ds_pool;
4686 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4687 ASSERT_VK_SUCCESS(err);
4688
4689 VkDescriptorSetLayoutBinding layout_binding;
4690 layout_binding.binding = 0;
4691 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4692 layout_binding.descriptorCount = 1;
4693 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4694 layout_binding.pImmutableSamplers = NULL;
4695
4696 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4697 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4698 ds_layout_ci.bindingCount = 1;
4699 ds_layout_ci.pBindings = &layout_binding;
4700 VkDescriptorSetLayout ds_layout;
4701 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4702 ASSERT_VK_SUCCESS(err);
4703
4704 VkDescriptorSetAllocateInfo alloc_info = {};
4705 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4706 alloc_info.descriptorSetCount = 1;
4707 alloc_info.descriptorPool = ds_pool;
4708 alloc_info.pSetLayouts = &ds_layout;
4709 VkDescriptorSet descriptor_set;
4710 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4711 ASSERT_VK_SUCCESS(err);
4712
4713 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4714 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4715 pipeline_layout_ci.pNext = NULL;
4716 pipeline_layout_ci.setLayoutCount = 1;
4717 pipeline_layout_ci.pSetLayouts = &ds_layout;
4718
4719 VkPipelineLayout pipeline_layout;
4720 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4721 ASSERT_VK_SUCCESS(err);
4722
4723 VkBuffer buffer;
4724 uint32_t queue_family_index = 0;
4725 VkBufferCreateInfo buffer_create_info = {};
4726 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4727 buffer_create_info.size = 1024;
4728 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4729 buffer_create_info.queueFamilyIndexCount = 1;
4730 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4731
4732 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4733 ASSERT_VK_SUCCESS(err);
4734
4735 VkMemoryRequirements memory_reqs;
4736 VkDeviceMemory buffer_memory;
4737
4738 VkMemoryAllocateInfo memory_info = {};
4739 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4740 memory_info.allocationSize = 0;
4741 memory_info.memoryTypeIndex = 0;
4742
4743 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4744 memory_info.allocationSize = memory_reqs.size;
4745 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4746 ASSERT_TRUE(pass);
4747
4748 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4749 ASSERT_VK_SUCCESS(err);
4750 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4751 ASSERT_VK_SUCCESS(err);
4752
4753 VkBufferView view;
4754 VkBufferViewCreateInfo bvci = {};
4755 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4756 bvci.buffer = buffer;
4757 bvci.format = VK_FORMAT_R8_UNORM;
4758 bvci.range = VK_WHOLE_SIZE;
4759
4760 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4761 ASSERT_VK_SUCCESS(err);
4762
4763 VkWriteDescriptorSet descriptor_write = {};
4764 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4765 descriptor_write.dstSet = descriptor_set;
4766 descriptor_write.dstBinding = 0;
4767 descriptor_write.descriptorCount = 1;
4768 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4769 descriptor_write.pTexelBufferView = &view;
4770
4771 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4772
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004773 char const *vsSource =
4774 "#version 450\n"
4775 "\n"
4776 "out gl_PerVertex { \n"
4777 " vec4 gl_Position;\n"
4778 "};\n"
4779 "void main(){\n"
4780 " gl_Position = vec4(1);\n"
4781 "}\n";
4782 char const *fsSource =
4783 "#version 450\n"
4784 "\n"
4785 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4786 "layout(location=0) out vec4 x;\n"
4787 "void main(){\n"
4788 " x = imageLoad(s, 0);\n"
4789 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004790 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4791 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4792 VkPipelineObj pipe(m_device);
4793 pipe.AddShader(&vs);
4794 pipe.AddShader(&fs);
4795 pipe.AddColorAttachment();
4796 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4797
4798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted buffer view ");
4799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4800
Tony Barbour552f6c02016-12-21 14:34:07 -07004801 m_commandBuffer->BeginCommandBuffer();
4802 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4803
Tobin Ehlisea413442016-09-28 10:23:59 -06004804 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4805 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4806 VkRect2D scissor = {{0, 0}, {16, 16}};
4807 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4808 // Bind pipeline to cmd buffer
4809 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4810 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4811 &descriptor_set, 0, nullptr);
4812 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004813 m_commandBuffer->EndRenderPass();
4814 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004815
4816 // Delete BufferView in order to invalidate cmd buffer
4817 vkDestroyBufferView(m_device->device(), view, NULL);
4818 // Now attempt submit of cmd buffer
4819 VkSubmitInfo submit_info = {};
4820 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4821 submit_info.commandBufferCount = 1;
4822 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4823 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4824 m_errorMonitor->VerifyFound();
4825
4826 // Clean-up
4827 vkDestroyBuffer(m_device->device(), buffer, NULL);
4828 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4829 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4830 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4831 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4832}
4833
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004834TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004835 TEST_DESCRIPTION(
4836 "Attempt to draw with a command buffer that is invalid "
4837 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004838 ASSERT_NO_FATAL_FAILURE(InitState());
4839
4840 VkImage image;
4841 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4842 VkImageCreateInfo image_create_info = {};
4843 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4844 image_create_info.pNext = NULL;
4845 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4846 image_create_info.format = tex_format;
4847 image_create_info.extent.width = 32;
4848 image_create_info.extent.height = 32;
4849 image_create_info.extent.depth = 1;
4850 image_create_info.mipLevels = 1;
4851 image_create_info.arrayLayers = 1;
4852 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4853 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004854 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004855 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004856 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004857 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004858 // Have to bind memory to image before recording cmd in cmd buffer using it
4859 VkMemoryRequirements mem_reqs;
4860 VkDeviceMemory image_mem;
4861 bool pass;
4862 VkMemoryAllocateInfo mem_alloc = {};
4863 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4864 mem_alloc.pNext = NULL;
4865 mem_alloc.memoryTypeIndex = 0;
4866 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4867 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004868 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004869 ASSERT_TRUE(pass);
4870 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4871 ASSERT_VK_SUCCESS(err);
4872 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4873 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004874
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004875 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004876 VkClearColorValue ccv;
4877 ccv.float32[0] = 1.0f;
4878 ccv.float32[1] = 1.0f;
4879 ccv.float32[2] = 1.0f;
4880 ccv.float32[3] = 1.0f;
4881 VkImageSubresourceRange isr = {};
4882 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004883 isr.baseArrayLayer = 0;
4884 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004885 isr.layerCount = 1;
4886 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004887 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004888 m_commandBuffer->EndCommandBuffer();
4889
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004891 // Destroy image dependency prior to submit to cause ERROR
4892 vkDestroyImage(m_device->device(), image, NULL);
4893
4894 VkSubmitInfo submit_info = {};
4895 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4896 submit_info.commandBufferCount = 1;
4897 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004898 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004899 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4900
4901 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004902 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004903}
4904
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004905TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004906 TEST_DESCRIPTION(
4907 "Attempt to draw with a command buffer that is invalid "
4908 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004909 VkFormatProperties format_properties;
4910 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004911 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4912 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004913 return;
4914 }
4915
4916 ASSERT_NO_FATAL_FAILURE(InitState());
4917 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4918
4919 VkImageCreateInfo image_ci = {};
4920 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4921 image_ci.pNext = NULL;
4922 image_ci.imageType = VK_IMAGE_TYPE_2D;
4923 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4924 image_ci.extent.width = 32;
4925 image_ci.extent.height = 32;
4926 image_ci.extent.depth = 1;
4927 image_ci.mipLevels = 1;
4928 image_ci.arrayLayers = 1;
4929 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4930 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004931 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004932 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4933 image_ci.flags = 0;
4934 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004935 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004936
4937 VkMemoryRequirements memory_reqs;
4938 VkDeviceMemory image_memory;
4939 bool pass;
4940 VkMemoryAllocateInfo memory_info = {};
4941 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4942 memory_info.pNext = NULL;
4943 memory_info.allocationSize = 0;
4944 memory_info.memoryTypeIndex = 0;
4945 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4946 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004947 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004948 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004950 ASSERT_VK_SUCCESS(err);
4951 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
4952 ASSERT_VK_SUCCESS(err);
4953
4954 VkImageViewCreateInfo ivci = {
4955 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
4956 nullptr,
4957 0,
4958 image,
4959 VK_IMAGE_VIEW_TYPE_2D,
4960 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004961 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004962 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
4963 };
4964 VkImageView view;
4965 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
4966 ASSERT_VK_SUCCESS(err);
4967
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004968 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004969 VkFramebuffer fb;
4970 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
4971 ASSERT_VK_SUCCESS(err);
4972
4973 // Just use default renderpass with our framebuffer
4974 m_renderPassBeginInfo.framebuffer = fb;
4975 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07004976 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004977 m_errorMonitor->SetUnexpectedError("Cannot execute a render pass with renderArea not within the bound of the framebuffer.");
Tony Barbour552f6c02016-12-21 14:34:07 -07004978 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4979 m_commandBuffer->EndRenderPass();
4980 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004981 // Destroy image attached to framebuffer to invalidate cmd buffer
4982 vkDestroyImage(m_device->device(), image, NULL);
4983 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004985 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004986 QueueCommandBuffer(false);
4987 m_errorMonitor->VerifyFound();
4988
4989 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
4990 vkDestroyImageView(m_device->device(), view, nullptr);
4991 vkFreeMemory(m_device->device(), image_memory, nullptr);
4992}
4993
Tobin Ehlisb329f992016-10-12 13:20:29 -06004994TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
4995 TEST_DESCRIPTION("Delete in-use framebuffer.");
4996 VkFormatProperties format_properties;
4997 VkResult err = VK_SUCCESS;
4998 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4999
5000 ASSERT_NO_FATAL_FAILURE(InitState());
5001 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5002
5003 VkImageObj image(m_device);
5004 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5005 ASSERT_TRUE(image.initialized());
5006 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5007
5008 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5009 VkFramebuffer fb;
5010 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5011 ASSERT_VK_SUCCESS(err);
5012
5013 // Just use default renderpass with our framebuffer
5014 m_renderPassBeginInfo.framebuffer = fb;
5015 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005016 m_commandBuffer->BeginCommandBuffer();
5017 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5018 m_commandBuffer->EndRenderPass();
5019 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005020 // Submit cmd buffer to put it in-flight
5021 VkSubmitInfo submit_info = {};
5022 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5023 submit_info.commandBufferCount = 1;
5024 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5025 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5026 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005027 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005028 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5029 m_errorMonitor->VerifyFound();
5030 // Wait for queue to complete so we can safely destroy everything
5031 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005032 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5033 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005034 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5035}
5036
Tobin Ehlis88becd72016-09-21 14:33:41 -06005037TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5038 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5039 VkFormatProperties format_properties;
5040 VkResult err = VK_SUCCESS;
5041 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005042
5043 ASSERT_NO_FATAL_FAILURE(InitState());
5044 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5045
5046 VkImageCreateInfo image_ci = {};
5047 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5048 image_ci.pNext = NULL;
5049 image_ci.imageType = VK_IMAGE_TYPE_2D;
5050 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5051 image_ci.extent.width = 256;
5052 image_ci.extent.height = 256;
5053 image_ci.extent.depth = 1;
5054 image_ci.mipLevels = 1;
5055 image_ci.arrayLayers = 1;
5056 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5057 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005058 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005059 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5060 image_ci.flags = 0;
5061 VkImage image;
5062 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5063
5064 VkMemoryRequirements memory_reqs;
5065 VkDeviceMemory image_memory;
5066 bool pass;
5067 VkMemoryAllocateInfo memory_info = {};
5068 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5069 memory_info.pNext = NULL;
5070 memory_info.allocationSize = 0;
5071 memory_info.memoryTypeIndex = 0;
5072 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5073 memory_info.allocationSize = memory_reqs.size;
5074 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5075 ASSERT_TRUE(pass);
5076 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5077 ASSERT_VK_SUCCESS(err);
5078 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5079 ASSERT_VK_SUCCESS(err);
5080
5081 VkImageViewCreateInfo ivci = {
5082 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5083 nullptr,
5084 0,
5085 image,
5086 VK_IMAGE_VIEW_TYPE_2D,
5087 VK_FORMAT_B8G8R8A8_UNORM,
5088 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5089 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5090 };
5091 VkImageView view;
5092 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5093 ASSERT_VK_SUCCESS(err);
5094
5095 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5096 VkFramebuffer fb;
5097 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5098 ASSERT_VK_SUCCESS(err);
5099
5100 // Just use default renderpass with our framebuffer
5101 m_renderPassBeginInfo.framebuffer = fb;
5102 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005103 m_commandBuffer->BeginCommandBuffer();
5104 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5105 m_commandBuffer->EndRenderPass();
5106 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005107 // Submit cmd buffer to put it (and attached imageView) in-flight
5108 VkSubmitInfo submit_info = {};
5109 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5110 submit_info.commandBufferCount = 1;
5111 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5112 // Submit cmd buffer to put framebuffer and children in-flight
5113 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5114 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005116 vkDestroyImage(m_device->device(), image, NULL);
5117 m_errorMonitor->VerifyFound();
5118 // Wait for queue to complete so we can safely destroy image and other objects
5119 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005120 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5121 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005122 vkDestroyImage(m_device->device(), image, NULL);
5123 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5124 vkDestroyImageView(m_device->device(), view, nullptr);
5125 vkFreeMemory(m_device->device(), image_memory, nullptr);
5126}
5127
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005128TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5129 TEST_DESCRIPTION("Delete in-use renderPass.");
5130
5131 ASSERT_NO_FATAL_FAILURE(InitState());
5132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5133
5134 // Create simple renderpass
5135 VkAttachmentReference attach = {};
5136 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5137 VkSubpassDescription subpass = {};
5138 subpass.pColorAttachments = &attach;
5139 VkRenderPassCreateInfo rpci = {};
5140 rpci.subpassCount = 1;
5141 rpci.pSubpasses = &subpass;
5142 rpci.attachmentCount = 1;
5143 VkAttachmentDescription attach_desc = {};
5144 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5145 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5146 rpci.pAttachments = &attach_desc;
5147 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5148 VkRenderPass rp;
5149 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5150 ASSERT_VK_SUCCESS(err);
5151
5152 // Create a pipeline that uses the given renderpass
5153 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5154 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5155
5156 VkPipelineLayout pipeline_layout;
5157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5158 ASSERT_VK_SUCCESS(err);
5159
5160 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5161 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5162 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005163 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005164 vp_state_ci.pViewports = &vp;
5165 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005166 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005167 vp_state_ci.pScissors = &scissors;
5168
5169 VkPipelineShaderStageCreateInfo shaderStages[2];
5170 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5171
5172 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005173 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 -06005174 // but add it to be able to run on more devices
5175 shaderStages[0] = vs.GetStageCreateInfo();
5176 shaderStages[1] = fs.GetStageCreateInfo();
5177
5178 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5179 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5180
5181 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5182 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5183 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5184
5185 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5186 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5187 rs_ci.rasterizerDiscardEnable = true;
5188 rs_ci.lineWidth = 1.0f;
5189
5190 VkPipelineColorBlendAttachmentState att = {};
5191 att.blendEnable = VK_FALSE;
5192 att.colorWriteMask = 0xf;
5193
5194 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5195 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5196 cb_ci.attachmentCount = 1;
5197 cb_ci.pAttachments = &att;
5198
5199 VkGraphicsPipelineCreateInfo gp_ci = {};
5200 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5201 gp_ci.stageCount = 2;
5202 gp_ci.pStages = shaderStages;
5203 gp_ci.pVertexInputState = &vi_ci;
5204 gp_ci.pInputAssemblyState = &ia_ci;
5205 gp_ci.pViewportState = &vp_state_ci;
5206 gp_ci.pRasterizationState = &rs_ci;
5207 gp_ci.pColorBlendState = &cb_ci;
5208 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5209 gp_ci.layout = pipeline_layout;
5210 gp_ci.renderPass = rp;
5211
5212 VkPipelineCacheCreateInfo pc_ci = {};
5213 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5214
5215 VkPipeline pipeline;
5216 VkPipelineCache pipe_cache;
5217 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5218 ASSERT_VK_SUCCESS(err);
5219
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005220 m_errorMonitor->SetUnexpectedError(
5221 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5222 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005223 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5224 ASSERT_VK_SUCCESS(err);
5225 // Bind pipeline to cmd buffer, will also bind renderpass
5226 m_commandBuffer->BeginCommandBuffer();
5227 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5228 m_commandBuffer->EndCommandBuffer();
5229
5230 VkSubmitInfo submit_info = {};
5231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5232 submit_info.commandBufferCount = 1;
5233 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5234 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5235
5236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5237 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5238 m_errorMonitor->VerifyFound();
5239
5240 // Wait for queue to complete so we can safely destroy everything
5241 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005242 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5243 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005244 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5245 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5246 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5247 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5248}
5249
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005250TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005251 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005252 ASSERT_NO_FATAL_FAILURE(InitState());
5253
5254 VkImage image;
5255 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5256 VkImageCreateInfo image_create_info = {};
5257 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5258 image_create_info.pNext = NULL;
5259 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5260 image_create_info.format = tex_format;
5261 image_create_info.extent.width = 32;
5262 image_create_info.extent.height = 32;
5263 image_create_info.extent.depth = 1;
5264 image_create_info.mipLevels = 1;
5265 image_create_info.arrayLayers = 1;
5266 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5267 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005268 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005269 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005270 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005271 ASSERT_VK_SUCCESS(err);
5272 // Have to bind memory to image before recording cmd in cmd buffer using it
5273 VkMemoryRequirements mem_reqs;
5274 VkDeviceMemory image_mem;
5275 bool pass;
5276 VkMemoryAllocateInfo mem_alloc = {};
5277 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5278 mem_alloc.pNext = NULL;
5279 mem_alloc.memoryTypeIndex = 0;
5280 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5281 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005282 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005283 ASSERT_TRUE(pass);
5284 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5285 ASSERT_VK_SUCCESS(err);
5286
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005287 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005289 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005290
5291 m_commandBuffer->BeginCommandBuffer();
5292 VkClearColorValue ccv;
5293 ccv.float32[0] = 1.0f;
5294 ccv.float32[1] = 1.0f;
5295 ccv.float32[2] = 1.0f;
5296 ccv.float32[3] = 1.0f;
5297 VkImageSubresourceRange isr = {};
5298 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5299 isr.baseArrayLayer = 0;
5300 isr.baseMipLevel = 0;
5301 isr.layerCount = 1;
5302 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005303 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005304 m_commandBuffer->EndCommandBuffer();
5305
5306 m_errorMonitor->VerifyFound();
5307 vkDestroyImage(m_device->device(), image, NULL);
5308 vkFreeMemory(m_device->device(), image_mem, nullptr);
5309}
5310
5311TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005312 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005313 ASSERT_NO_FATAL_FAILURE(InitState());
5314
5315 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005316 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 -06005317 VK_IMAGE_TILING_OPTIMAL, 0);
5318 ASSERT_TRUE(image.initialized());
5319
5320 VkBuffer buffer;
5321 VkDeviceMemory mem;
5322 VkMemoryRequirements mem_reqs;
5323
5324 VkBufferCreateInfo buf_info = {};
5325 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005326 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005327 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005328 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5329 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5330 ASSERT_VK_SUCCESS(err);
5331
5332 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5333
5334 VkMemoryAllocateInfo alloc_info = {};
5335 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005336 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005337 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005338 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 -06005339 if (!pass) {
5340 vkDestroyBuffer(m_device->device(), buffer, NULL);
5341 return;
5342 }
5343 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5344 ASSERT_VK_SUCCESS(err);
5345
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005346 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005348 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005349 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005350 region.bufferRowLength = 16;
5351 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005352 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5353
5354 region.imageSubresource.layerCount = 1;
5355 region.imageExtent.height = 4;
5356 region.imageExtent.width = 4;
5357 region.imageExtent.depth = 1;
5358 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005359 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5360 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005361 m_commandBuffer->EndCommandBuffer();
5362
5363 m_errorMonitor->VerifyFound();
5364
5365 vkDestroyBuffer(m_device->device(), buffer, NULL);
5366 vkFreeMemory(m_device->handle(), mem, NULL);
5367}
5368
Tobin Ehlis85940f52016-07-07 16:57:21 -06005369TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005370 TEST_DESCRIPTION(
5371 "Attempt to draw with a command buffer that is invalid "
5372 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005373 ASSERT_NO_FATAL_FAILURE(InitState());
5374
5375 VkEvent event;
5376 VkEventCreateInfo evci = {};
5377 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5378 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5379 ASSERT_VK_SUCCESS(result);
5380
5381 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005382 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005383 m_commandBuffer->EndCommandBuffer();
5384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005386 // Destroy event dependency prior to submit to cause ERROR
5387 vkDestroyEvent(m_device->device(), event, NULL);
5388
5389 VkSubmitInfo submit_info = {};
5390 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5391 submit_info.commandBufferCount = 1;
5392 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005393 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted event");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005394 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5395
5396 m_errorMonitor->VerifyFound();
5397}
5398
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005399TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005400 TEST_DESCRIPTION(
5401 "Attempt to draw with a command buffer that is invalid "
5402 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005403 ASSERT_NO_FATAL_FAILURE(InitState());
5404
5405 VkQueryPool query_pool;
5406 VkQueryPoolCreateInfo qpci{};
5407 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5408 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5409 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005410 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005411 ASSERT_VK_SUCCESS(result);
5412
5413 m_commandBuffer->BeginCommandBuffer();
5414 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5415 m_commandBuffer->EndCommandBuffer();
5416
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005418 // Destroy query pool dependency prior to submit to cause ERROR
5419 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5420
5421 VkSubmitInfo submit_info = {};
5422 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5423 submit_info.commandBufferCount = 1;
5424 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005425 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted query pool");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005426 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5427
5428 m_errorMonitor->VerifyFound();
5429}
5430
Tobin Ehlis24130d92016-07-08 15:50:53 -06005431TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005432 TEST_DESCRIPTION(
5433 "Attempt to draw with a command buffer that is invalid "
5434 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005435 ASSERT_NO_FATAL_FAILURE(InitState());
5436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5437
5438 VkResult err;
5439
5440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5442
5443 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005444 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005445 ASSERT_VK_SUCCESS(err);
5446
5447 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5448 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5449 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005450 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005451 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005452 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005453 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005454 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005455
5456 VkPipelineShaderStageCreateInfo shaderStages[2];
5457 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005459 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005460 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 -06005461 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005462 shaderStages[0] = vs.GetStageCreateInfo();
5463 shaderStages[1] = fs.GetStageCreateInfo();
5464
5465 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5466 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5467
5468 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5469 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5470 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5471
5472 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5473 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005474 rs_ci.rasterizerDiscardEnable = true;
5475 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005476
5477 VkPipelineColorBlendAttachmentState att = {};
5478 att.blendEnable = VK_FALSE;
5479 att.colorWriteMask = 0xf;
5480
5481 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5482 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5483 cb_ci.attachmentCount = 1;
5484 cb_ci.pAttachments = &att;
5485
5486 VkGraphicsPipelineCreateInfo gp_ci = {};
5487 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5488 gp_ci.stageCount = 2;
5489 gp_ci.pStages = shaderStages;
5490 gp_ci.pVertexInputState = &vi_ci;
5491 gp_ci.pInputAssemblyState = &ia_ci;
5492 gp_ci.pViewportState = &vp_state_ci;
5493 gp_ci.pRasterizationState = &rs_ci;
5494 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005495 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5496 gp_ci.layout = pipeline_layout;
5497 gp_ci.renderPass = renderPass();
5498
5499 VkPipelineCacheCreateInfo pc_ci = {};
5500 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5501
5502 VkPipeline pipeline;
5503 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005504 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005505 ASSERT_VK_SUCCESS(err);
5506
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005507 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005508 ASSERT_VK_SUCCESS(err);
5509
5510 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005511 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005512 m_commandBuffer->EndCommandBuffer();
5513 // Now destroy pipeline in order to cause error when submitting
5514 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5515
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005516 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005517
5518 VkSubmitInfo submit_info = {};
5519 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5520 submit_info.commandBufferCount = 1;
5521 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005522 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted pipeline");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005523 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5524
5525 m_errorMonitor->VerifyFound();
5526 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5527 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5528}
5529
Tobin Ehlis31289162016-08-17 14:57:58 -06005530TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005531 TEST_DESCRIPTION(
5532 "Attempt to draw with a command buffer that is invalid "
5533 "due to a bound descriptor set with a buffer dependency "
5534 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005535 ASSERT_NO_FATAL_FAILURE(InitState());
5536 ASSERT_NO_FATAL_FAILURE(InitViewport());
5537 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5538
5539 VkDescriptorPoolSize ds_type_count = {};
5540 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5541 ds_type_count.descriptorCount = 1;
5542
5543 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5544 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5545 ds_pool_ci.pNext = NULL;
5546 ds_pool_ci.maxSets = 1;
5547 ds_pool_ci.poolSizeCount = 1;
5548 ds_pool_ci.pPoolSizes = &ds_type_count;
5549
5550 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005551 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005552 ASSERT_VK_SUCCESS(err);
5553
5554 VkDescriptorSetLayoutBinding dsl_binding = {};
5555 dsl_binding.binding = 0;
5556 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5557 dsl_binding.descriptorCount = 1;
5558 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5559 dsl_binding.pImmutableSamplers = NULL;
5560
5561 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5562 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5563 ds_layout_ci.pNext = NULL;
5564 ds_layout_ci.bindingCount = 1;
5565 ds_layout_ci.pBindings = &dsl_binding;
5566 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005567 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005568 ASSERT_VK_SUCCESS(err);
5569
5570 VkDescriptorSet descriptorSet;
5571 VkDescriptorSetAllocateInfo alloc_info = {};
5572 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5573 alloc_info.descriptorSetCount = 1;
5574 alloc_info.descriptorPool = ds_pool;
5575 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005576 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005577 ASSERT_VK_SUCCESS(err);
5578
5579 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5580 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5581 pipeline_layout_ci.pNext = NULL;
5582 pipeline_layout_ci.setLayoutCount = 1;
5583 pipeline_layout_ci.pSetLayouts = &ds_layout;
5584
5585 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005586 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005587 ASSERT_VK_SUCCESS(err);
5588
5589 // Create a buffer to update the descriptor with
5590 uint32_t qfi = 0;
5591 VkBufferCreateInfo buffCI = {};
5592 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5593 buffCI.size = 1024;
5594 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5595 buffCI.queueFamilyIndexCount = 1;
5596 buffCI.pQueueFamilyIndices = &qfi;
5597
5598 VkBuffer buffer;
5599 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5600 ASSERT_VK_SUCCESS(err);
5601 // Allocate memory and bind to buffer so we can make it to the appropriate
5602 // error
5603 VkMemoryAllocateInfo mem_alloc = {};
5604 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5605 mem_alloc.pNext = NULL;
5606 mem_alloc.allocationSize = 1024;
5607 mem_alloc.memoryTypeIndex = 0;
5608
5609 VkMemoryRequirements memReqs;
5610 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005611 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005612 if (!pass) {
5613 vkDestroyBuffer(m_device->device(), buffer, NULL);
5614 return;
5615 }
5616
5617 VkDeviceMemory mem;
5618 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5619 ASSERT_VK_SUCCESS(err);
5620 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5621 ASSERT_VK_SUCCESS(err);
5622 // Correctly update descriptor to avoid "NOT_UPDATED" error
5623 VkDescriptorBufferInfo buffInfo = {};
5624 buffInfo.buffer = buffer;
5625 buffInfo.offset = 0;
5626 buffInfo.range = 1024;
5627
5628 VkWriteDescriptorSet descriptor_write;
5629 memset(&descriptor_write, 0, sizeof(descriptor_write));
5630 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5631 descriptor_write.dstSet = descriptorSet;
5632 descriptor_write.dstBinding = 0;
5633 descriptor_write.descriptorCount = 1;
5634 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5635 descriptor_write.pBufferInfo = &buffInfo;
5636
5637 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5638
5639 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005640 char const *vsSource =
5641 "#version 450\n"
5642 "\n"
5643 "out gl_PerVertex { \n"
5644 " vec4 gl_Position;\n"
5645 "};\n"
5646 "void main(){\n"
5647 " gl_Position = vec4(1);\n"
5648 "}\n";
5649 char const *fsSource =
5650 "#version 450\n"
5651 "\n"
5652 "layout(location=0) out vec4 x;\n"
5653 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5654 "void main(){\n"
5655 " x = vec4(bar.y);\n"
5656 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005657 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5658 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5659 VkPipelineObj pipe(m_device);
5660 pipe.AddShader(&vs);
5661 pipe.AddShader(&fs);
5662 pipe.AddColorAttachment();
5663 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5664
Tony Barbour552f6c02016-12-21 14:34:07 -07005665 m_commandBuffer->BeginCommandBuffer();
5666 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005667 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5668 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5669 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005670
5671 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5672 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5673
Tobin Ehlis31289162016-08-17 14:57:58 -06005674 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005675 m_commandBuffer->EndRenderPass();
5676 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005678 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5679 vkDestroyBuffer(m_device->device(), buffer, NULL);
5680 // Attempt to submit cmd buffer
5681 VkSubmitInfo submit_info = {};
5682 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5683 submit_info.commandBufferCount = 1;
5684 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005685 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted buffer");
Tobin Ehlis31289162016-08-17 14:57:58 -06005686 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5687 m_errorMonitor->VerifyFound();
5688 // Cleanup
5689 vkFreeMemory(m_device->device(), mem, NULL);
5690
5691 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5692 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5693 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5694}
5695
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005696TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005697 TEST_DESCRIPTION(
5698 "Attempt to draw with a command buffer that is invalid "
5699 "due to a bound descriptor sets with a combined image "
5700 "sampler having their image, sampler, and descriptor set "
5701 "each respectively destroyed and then attempting to "
5702 "submit associated cmd buffers. Attempt to destroy a "
5703 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005704 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005705 ASSERT_NO_FATAL_FAILURE(InitViewport());
5706 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5707
5708 VkDescriptorPoolSize ds_type_count = {};
5709 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5710 ds_type_count.descriptorCount = 1;
5711
5712 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5713 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5714 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005715 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005716 ds_pool_ci.maxSets = 1;
5717 ds_pool_ci.poolSizeCount = 1;
5718 ds_pool_ci.pPoolSizes = &ds_type_count;
5719
5720 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005721 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005722 ASSERT_VK_SUCCESS(err);
5723
5724 VkDescriptorSetLayoutBinding dsl_binding = {};
5725 dsl_binding.binding = 0;
5726 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5727 dsl_binding.descriptorCount = 1;
5728 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5729 dsl_binding.pImmutableSamplers = NULL;
5730
5731 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5732 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5733 ds_layout_ci.pNext = NULL;
5734 ds_layout_ci.bindingCount = 1;
5735 ds_layout_ci.pBindings = &dsl_binding;
5736 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005737 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005738 ASSERT_VK_SUCCESS(err);
5739
5740 VkDescriptorSet descriptorSet;
5741 VkDescriptorSetAllocateInfo alloc_info = {};
5742 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5743 alloc_info.descriptorSetCount = 1;
5744 alloc_info.descriptorPool = ds_pool;
5745 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005746 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005747 ASSERT_VK_SUCCESS(err);
5748
5749 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5750 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5751 pipeline_layout_ci.pNext = NULL;
5752 pipeline_layout_ci.setLayoutCount = 1;
5753 pipeline_layout_ci.pSetLayouts = &ds_layout;
5754
5755 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005756 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005757 ASSERT_VK_SUCCESS(err);
5758
5759 // Create images to update the descriptor with
5760 VkImage image;
5761 VkImage image2;
5762 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5763 const int32_t tex_width = 32;
5764 const int32_t tex_height = 32;
5765 VkImageCreateInfo image_create_info = {};
5766 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5767 image_create_info.pNext = NULL;
5768 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5769 image_create_info.format = tex_format;
5770 image_create_info.extent.width = tex_width;
5771 image_create_info.extent.height = tex_height;
5772 image_create_info.extent.depth = 1;
5773 image_create_info.mipLevels = 1;
5774 image_create_info.arrayLayers = 1;
5775 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5776 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5777 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5778 image_create_info.flags = 0;
5779 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5780 ASSERT_VK_SUCCESS(err);
5781 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5782 ASSERT_VK_SUCCESS(err);
5783
5784 VkMemoryRequirements memory_reqs;
5785 VkDeviceMemory image_memory;
5786 bool pass;
5787 VkMemoryAllocateInfo memory_info = {};
5788 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5789 memory_info.pNext = NULL;
5790 memory_info.allocationSize = 0;
5791 memory_info.memoryTypeIndex = 0;
5792 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5793 // Allocate enough memory for both images
5794 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005795 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005796 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005797 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005798 ASSERT_VK_SUCCESS(err);
5799 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5800 ASSERT_VK_SUCCESS(err);
5801 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005802 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005803 ASSERT_VK_SUCCESS(err);
5804
5805 VkImageViewCreateInfo image_view_create_info = {};
5806 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5807 image_view_create_info.image = image;
5808 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5809 image_view_create_info.format = tex_format;
5810 image_view_create_info.subresourceRange.layerCount = 1;
5811 image_view_create_info.subresourceRange.baseMipLevel = 0;
5812 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005813 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005814
5815 VkImageView view;
5816 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005817 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005818 ASSERT_VK_SUCCESS(err);
5819 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005820 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005821 ASSERT_VK_SUCCESS(err);
5822 // Create Samplers
5823 VkSamplerCreateInfo sampler_ci = {};
5824 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5825 sampler_ci.pNext = NULL;
5826 sampler_ci.magFilter = VK_FILTER_NEAREST;
5827 sampler_ci.minFilter = VK_FILTER_NEAREST;
5828 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5829 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5830 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5831 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5832 sampler_ci.mipLodBias = 1.0;
5833 sampler_ci.anisotropyEnable = VK_FALSE;
5834 sampler_ci.maxAnisotropy = 1;
5835 sampler_ci.compareEnable = VK_FALSE;
5836 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5837 sampler_ci.minLod = 1.0;
5838 sampler_ci.maxLod = 1.0;
5839 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5840 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5841 VkSampler sampler;
5842 VkSampler sampler2;
5843 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5844 ASSERT_VK_SUCCESS(err);
5845 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5846 ASSERT_VK_SUCCESS(err);
5847 // Update descriptor with image and sampler
5848 VkDescriptorImageInfo img_info = {};
5849 img_info.sampler = sampler;
5850 img_info.imageView = view;
5851 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5852
5853 VkWriteDescriptorSet descriptor_write;
5854 memset(&descriptor_write, 0, sizeof(descriptor_write));
5855 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5856 descriptor_write.dstSet = descriptorSet;
5857 descriptor_write.dstBinding = 0;
5858 descriptor_write.descriptorCount = 1;
5859 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5860 descriptor_write.pImageInfo = &img_info;
5861
5862 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5863
5864 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005865 char const *vsSource =
5866 "#version 450\n"
5867 "\n"
5868 "out gl_PerVertex { \n"
5869 " vec4 gl_Position;\n"
5870 "};\n"
5871 "void main(){\n"
5872 " gl_Position = vec4(1);\n"
5873 "}\n";
5874 char const *fsSource =
5875 "#version 450\n"
5876 "\n"
5877 "layout(set=0, binding=0) uniform sampler2D s;\n"
5878 "layout(location=0) out vec4 x;\n"
5879 "void main(){\n"
5880 " x = texture(s, vec2(1));\n"
5881 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005882 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5883 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5884 VkPipelineObj pipe(m_device);
5885 pipe.AddShader(&vs);
5886 pipe.AddShader(&fs);
5887 pipe.AddColorAttachment();
5888 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5889
5890 // First error case is destroying sampler prior to cmd buffer submission
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005891 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted sampler ");
Tony Barbour552f6c02016-12-21 14:34:07 -07005892 m_commandBuffer->BeginCommandBuffer();
5893 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005894 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5895 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5896 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005897 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5898 VkRect2D scissor = {{0, 0}, {16, 16}};
5899 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5900 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005901 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005902 m_commandBuffer->EndRenderPass();
5903 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005904 // Destroy sampler invalidates the cmd buffer, causing error on submit
5905 vkDestroySampler(m_device->device(), sampler, NULL);
5906 // Attempt to submit cmd buffer
5907 VkSubmitInfo submit_info = {};
5908 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5909 submit_info.commandBufferCount = 1;
5910 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005911 m_errorMonitor->SetUnexpectedError("that is invalid because bound sampler");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005912 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5913 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005914
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005915 // Now re-update descriptor with valid sampler and delete image
5916 img_info.sampler = sampler2;
5917 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005918
5919 VkCommandBufferBeginInfo info = {};
5920 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5921 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5922
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005924 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005925 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005926 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5927 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5928 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005929 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5930 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005931 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005932 m_commandBuffer->EndRenderPass();
5933 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005934 // Destroy image invalidates the cmd buffer, causing error on submit
5935 vkDestroyImage(m_device->device(), image, NULL);
5936 // Attempt to submit cmd buffer
5937 submit_info = {};
5938 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5939 submit_info.commandBufferCount = 1;
5940 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005941 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted image");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005942 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5943 m_errorMonitor->VerifyFound();
5944 // Now update descriptor to be valid, but then free descriptor
5945 img_info.imageView = view2;
5946 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005947 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005948 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005949 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5950 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5951 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005952 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5953 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005954 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005955 m_commandBuffer->EndRenderPass();
5956 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07005957 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07005958
5959 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005960 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005961 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06005962 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005963
5964 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07005965 // 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 -07005966 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005967 m_errorMonitor->SetUnexpectedError(
5968 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
5969 "either be a valid handle or VK_NULL_HANDLE");
5970 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07005971 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
5972
5973 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005974 submit_info = {};
5975 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5976 submit_info.commandBufferCount = 1;
5977 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07005978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005979 m_errorMonitor->SetUnexpectedError("Cannot submit cmd buffer using deleted descriptor set");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005980 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5981 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07005982
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005983 // Cleanup
5984 vkFreeMemory(m_device->device(), image_memory, NULL);
5985 vkDestroySampler(m_device->device(), sampler2, NULL);
5986 vkDestroyImage(m_device->device(), image2, NULL);
5987 vkDestroyImageView(m_device->device(), view, NULL);
5988 vkDestroyImageView(m_device->device(), view2, NULL);
5989 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5990 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5991 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5992}
5993
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06005994TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
5995 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
5996 ASSERT_NO_FATAL_FAILURE(InitState());
5997 ASSERT_NO_FATAL_FAILURE(InitViewport());
5998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5999
6000 VkDescriptorPoolSize ds_type_count = {};
6001 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6002 ds_type_count.descriptorCount = 1;
6003
6004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6006 ds_pool_ci.pNext = NULL;
6007 ds_pool_ci.maxSets = 1;
6008 ds_pool_ci.poolSizeCount = 1;
6009 ds_pool_ci.pPoolSizes = &ds_type_count;
6010
6011 VkDescriptorPool ds_pool;
6012 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6013 ASSERT_VK_SUCCESS(err);
6014
6015 VkDescriptorSetLayoutBinding dsl_binding = {};
6016 dsl_binding.binding = 0;
6017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6018 dsl_binding.descriptorCount = 1;
6019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6020 dsl_binding.pImmutableSamplers = NULL;
6021
6022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6024 ds_layout_ci.pNext = NULL;
6025 ds_layout_ci.bindingCount = 1;
6026 ds_layout_ci.pBindings = &dsl_binding;
6027 VkDescriptorSetLayout ds_layout;
6028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6029 ASSERT_VK_SUCCESS(err);
6030
6031 VkDescriptorSet descriptor_set;
6032 VkDescriptorSetAllocateInfo alloc_info = {};
6033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6034 alloc_info.descriptorSetCount = 1;
6035 alloc_info.descriptorPool = ds_pool;
6036 alloc_info.pSetLayouts = &ds_layout;
6037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6038 ASSERT_VK_SUCCESS(err);
6039
6040 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6041 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6042 pipeline_layout_ci.pNext = NULL;
6043 pipeline_layout_ci.setLayoutCount = 1;
6044 pipeline_layout_ci.pSetLayouts = &ds_layout;
6045
6046 VkPipelineLayout pipeline_layout;
6047 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6048 ASSERT_VK_SUCCESS(err);
6049
6050 // Create image to update the descriptor with
6051 VkImageObj image(m_device);
6052 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6053 ASSERT_TRUE(image.initialized());
6054
6055 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6056 // Create Sampler
6057 VkSamplerCreateInfo sampler_ci = {};
6058 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6059 sampler_ci.pNext = NULL;
6060 sampler_ci.magFilter = VK_FILTER_NEAREST;
6061 sampler_ci.minFilter = VK_FILTER_NEAREST;
6062 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6063 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6064 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6065 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6066 sampler_ci.mipLodBias = 1.0;
6067 sampler_ci.anisotropyEnable = VK_FALSE;
6068 sampler_ci.maxAnisotropy = 1;
6069 sampler_ci.compareEnable = VK_FALSE;
6070 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6071 sampler_ci.minLod = 1.0;
6072 sampler_ci.maxLod = 1.0;
6073 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6074 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6075 VkSampler sampler;
6076 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6077 ASSERT_VK_SUCCESS(err);
6078 // Update descriptor with image and sampler
6079 VkDescriptorImageInfo img_info = {};
6080 img_info.sampler = sampler;
6081 img_info.imageView = view;
6082 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6083
6084 VkWriteDescriptorSet descriptor_write;
6085 memset(&descriptor_write, 0, sizeof(descriptor_write));
6086 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6087 descriptor_write.dstSet = descriptor_set;
6088 descriptor_write.dstBinding = 0;
6089 descriptor_write.descriptorCount = 1;
6090 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6091 descriptor_write.pImageInfo = &img_info;
6092
6093 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6094
6095 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006096 char const *vsSource =
6097 "#version 450\n"
6098 "\n"
6099 "out gl_PerVertex { \n"
6100 " vec4 gl_Position;\n"
6101 "};\n"
6102 "void main(){\n"
6103 " gl_Position = vec4(1);\n"
6104 "}\n";
6105 char const *fsSource =
6106 "#version 450\n"
6107 "\n"
6108 "layout(set=0, binding=0) uniform sampler2D s;\n"
6109 "layout(location=0) out vec4 x;\n"
6110 "void main(){\n"
6111 " x = texture(s, vec2(1));\n"
6112 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006113 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6114 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6115 VkPipelineObj pipe(m_device);
6116 pipe.AddShader(&vs);
6117 pipe.AddShader(&fs);
6118 pipe.AddColorAttachment();
6119 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6120
Tony Barbour552f6c02016-12-21 14:34:07 -07006121 m_commandBuffer->BeginCommandBuffer();
6122 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006123 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6124 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6125 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006126
6127 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6128 VkRect2D scissor = {{0, 0}, {16, 16}};
6129 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6130 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6131
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006132 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006133 m_commandBuffer->EndRenderPass();
6134 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006135 // Submit cmd buffer to put pool in-flight
6136 VkSubmitInfo submit_info = {};
6137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6138 submit_info.commandBufferCount = 1;
6139 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6140 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6141 // Destroy pool while in-flight, causing error
6142 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6143 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6144 m_errorMonitor->VerifyFound();
6145 vkQueueWaitIdle(m_device->m_queue);
6146 // Cleanup
6147 vkDestroySampler(m_device->device(), sampler, NULL);
6148 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6149 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006150 m_errorMonitor->SetUnexpectedError(
6151 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6152 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006153 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006154 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006155}
6156
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006157TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6158 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6159 ASSERT_NO_FATAL_FAILURE(InitState());
6160 ASSERT_NO_FATAL_FAILURE(InitViewport());
6161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6162
6163 VkDescriptorPoolSize ds_type_count = {};
6164 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6165 ds_type_count.descriptorCount = 1;
6166
6167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6169 ds_pool_ci.pNext = NULL;
6170 ds_pool_ci.maxSets = 1;
6171 ds_pool_ci.poolSizeCount = 1;
6172 ds_pool_ci.pPoolSizes = &ds_type_count;
6173
6174 VkDescriptorPool ds_pool;
6175 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6176 ASSERT_VK_SUCCESS(err);
6177
6178 VkDescriptorSetLayoutBinding dsl_binding = {};
6179 dsl_binding.binding = 0;
6180 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6181 dsl_binding.descriptorCount = 1;
6182 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6183 dsl_binding.pImmutableSamplers = NULL;
6184
6185 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6186 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6187 ds_layout_ci.pNext = NULL;
6188 ds_layout_ci.bindingCount = 1;
6189 ds_layout_ci.pBindings = &dsl_binding;
6190 VkDescriptorSetLayout ds_layout;
6191 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6192 ASSERT_VK_SUCCESS(err);
6193
6194 VkDescriptorSet descriptorSet;
6195 VkDescriptorSetAllocateInfo alloc_info = {};
6196 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6197 alloc_info.descriptorSetCount = 1;
6198 alloc_info.descriptorPool = ds_pool;
6199 alloc_info.pSetLayouts = &ds_layout;
6200 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6201 ASSERT_VK_SUCCESS(err);
6202
6203 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6204 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6205 pipeline_layout_ci.pNext = NULL;
6206 pipeline_layout_ci.setLayoutCount = 1;
6207 pipeline_layout_ci.pSetLayouts = &ds_layout;
6208
6209 VkPipelineLayout pipeline_layout;
6210 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6211 ASSERT_VK_SUCCESS(err);
6212
6213 // Create images to update the descriptor with
6214 VkImage image;
6215 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6216 const int32_t tex_width = 32;
6217 const int32_t tex_height = 32;
6218 VkImageCreateInfo image_create_info = {};
6219 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6220 image_create_info.pNext = NULL;
6221 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6222 image_create_info.format = tex_format;
6223 image_create_info.extent.width = tex_width;
6224 image_create_info.extent.height = tex_height;
6225 image_create_info.extent.depth = 1;
6226 image_create_info.mipLevels = 1;
6227 image_create_info.arrayLayers = 1;
6228 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6229 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6230 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6231 image_create_info.flags = 0;
6232 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6233 ASSERT_VK_SUCCESS(err);
6234 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6235 VkMemoryRequirements memory_reqs;
6236 VkDeviceMemory image_memory;
6237 bool pass;
6238 VkMemoryAllocateInfo memory_info = {};
6239 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6240 memory_info.pNext = NULL;
6241 memory_info.allocationSize = 0;
6242 memory_info.memoryTypeIndex = 0;
6243 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6244 // Allocate enough memory for image
6245 memory_info.allocationSize = memory_reqs.size;
6246 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6247 ASSERT_TRUE(pass);
6248 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6249 ASSERT_VK_SUCCESS(err);
6250 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6251 ASSERT_VK_SUCCESS(err);
6252
6253 VkImageViewCreateInfo image_view_create_info = {};
6254 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6255 image_view_create_info.image = image;
6256 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6257 image_view_create_info.format = tex_format;
6258 image_view_create_info.subresourceRange.layerCount = 1;
6259 image_view_create_info.subresourceRange.baseMipLevel = 0;
6260 image_view_create_info.subresourceRange.levelCount = 1;
6261 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6262
6263 VkImageView view;
6264 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6265 ASSERT_VK_SUCCESS(err);
6266 // Create Samplers
6267 VkSamplerCreateInfo sampler_ci = {};
6268 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6269 sampler_ci.pNext = NULL;
6270 sampler_ci.magFilter = VK_FILTER_NEAREST;
6271 sampler_ci.minFilter = VK_FILTER_NEAREST;
6272 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6273 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6274 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6275 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6276 sampler_ci.mipLodBias = 1.0;
6277 sampler_ci.anisotropyEnable = VK_FALSE;
6278 sampler_ci.maxAnisotropy = 1;
6279 sampler_ci.compareEnable = VK_FALSE;
6280 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6281 sampler_ci.minLod = 1.0;
6282 sampler_ci.maxLod = 1.0;
6283 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6284 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6285 VkSampler sampler;
6286 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6287 ASSERT_VK_SUCCESS(err);
6288 // Update descriptor with image and sampler
6289 VkDescriptorImageInfo img_info = {};
6290 img_info.sampler = sampler;
6291 img_info.imageView = view;
6292 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6293
6294 VkWriteDescriptorSet descriptor_write;
6295 memset(&descriptor_write, 0, sizeof(descriptor_write));
6296 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6297 descriptor_write.dstSet = descriptorSet;
6298 descriptor_write.dstBinding = 0;
6299 descriptor_write.descriptorCount = 1;
6300 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6301 descriptor_write.pImageInfo = &img_info;
6302 // Break memory binding and attempt update
6303 vkFreeMemory(m_device->device(), image_memory, nullptr);
6304 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006305 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6307 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6308 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6309 m_errorMonitor->VerifyFound();
6310 // Cleanup
6311 vkDestroyImage(m_device->device(), image, NULL);
6312 vkDestroySampler(m_device->device(), sampler, NULL);
6313 vkDestroyImageView(m_device->device(), view, NULL);
6314 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6315 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6316 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6317}
6318
Karl Schultz6addd812016-02-02 17:17:23 -07006319TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006320 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6321 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006322 // Create a valid cmd buffer
6323 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006324 uint64_t fake_pipeline_handle = 0xbaad6001;
6325 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006326 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006327 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6328
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006330 m_commandBuffer->BeginCommandBuffer();
6331 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006332 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006333 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006334
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006335 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006336 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 -06006337 Draw(1, 0, 0, 0);
6338 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006339
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006340 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006341 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 -07006342 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006343 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6344 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006345}
6346
Karl Schultz6addd812016-02-02 17:17:23 -07006347TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006348 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006349 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006350
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006351 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006352
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006353 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006354 ASSERT_NO_FATAL_FAILURE(InitViewport());
6355 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006356 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006357 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6358 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006359
6360 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006361 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6362 ds_pool_ci.pNext = NULL;
6363 ds_pool_ci.maxSets = 1;
6364 ds_pool_ci.poolSizeCount = 1;
6365 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006366
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006367 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006368 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006369 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006370
Tony Barboureb254902015-07-15 12:50:33 -06006371 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006372 dsl_binding.binding = 0;
6373 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6374 dsl_binding.descriptorCount = 1;
6375 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6376 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006377
Tony Barboureb254902015-07-15 12:50:33 -06006378 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006379 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6380 ds_layout_ci.pNext = NULL;
6381 ds_layout_ci.bindingCount = 1;
6382 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006383 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006384 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006385 ASSERT_VK_SUCCESS(err);
6386
6387 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006388 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006389 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006390 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006391 alloc_info.descriptorPool = ds_pool;
6392 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006393 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006394 ASSERT_VK_SUCCESS(err);
6395
Tony Barboureb254902015-07-15 12:50:33 -06006396 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006397 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6398 pipeline_layout_ci.pNext = NULL;
6399 pipeline_layout_ci.setLayoutCount = 1;
6400 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006401
6402 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006403 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404 ASSERT_VK_SUCCESS(err);
6405
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006406 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006407 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006408 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006409 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006410
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006411 VkPipelineObj pipe(m_device);
6412 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006413 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006414 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006415 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006416
Tony Barbour552f6c02016-12-21 14:34:07 -07006417 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006418 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6419 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6420 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006421
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006422 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006423
Chia-I Wuf7458c52015-10-26 21:10:41 +08006424 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6425 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6426 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006427}
6428
Karl Schultz6addd812016-02-02 17:17:23 -07006429TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006430 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006431 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006432
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006433 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006434
6435 ASSERT_NO_FATAL_FAILURE(InitState());
6436 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006437 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6438 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006439
6440 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006441 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6442 ds_pool_ci.pNext = NULL;
6443 ds_pool_ci.maxSets = 1;
6444 ds_pool_ci.poolSizeCount = 1;
6445 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006446
6447 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006448 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006449 ASSERT_VK_SUCCESS(err);
6450
6451 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006452 dsl_binding.binding = 0;
6453 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6454 dsl_binding.descriptorCount = 1;
6455 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6456 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006457
6458 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006459 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6460 ds_layout_ci.pNext = NULL;
6461 ds_layout_ci.bindingCount = 1;
6462 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006463 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006464 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006465 ASSERT_VK_SUCCESS(err);
6466
6467 VkDescriptorSet descriptorSet;
6468 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006469 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006470 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006471 alloc_info.descriptorPool = ds_pool;
6472 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006473 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006474 ASSERT_VK_SUCCESS(err);
6475
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006476 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006477 VkWriteDescriptorSet descriptor_write;
6478 memset(&descriptor_write, 0, sizeof(descriptor_write));
6479 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6480 descriptor_write.dstSet = descriptorSet;
6481 descriptor_write.dstBinding = 0;
6482 descriptor_write.descriptorCount = 1;
6483 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6484 descriptor_write.pTexelBufferView = &view;
6485
6486 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6487
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006488 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006489
6490 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6491 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6492}
6493
Mark Youngd339ba32016-05-30 13:28:35 -06006494TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006495 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 -06006496
6497 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006499 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006500
6501 ASSERT_NO_FATAL_FAILURE(InitState());
6502
6503 // Create a buffer with no bound memory and then attempt to create
6504 // a buffer view.
6505 VkBufferCreateInfo buff_ci = {};
6506 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006507 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006508 buff_ci.size = 256;
6509 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6510 VkBuffer buffer;
6511 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6512 ASSERT_VK_SUCCESS(err);
6513
6514 VkBufferViewCreateInfo buff_view_ci = {};
6515 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6516 buff_view_ci.buffer = buffer;
6517 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6518 buff_view_ci.range = VK_WHOLE_SIZE;
6519 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006520 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006521
6522 m_errorMonitor->VerifyFound();
6523 vkDestroyBuffer(m_device->device(), buffer, NULL);
6524 // If last error is success, it still created the view, so delete it.
6525 if (err == VK_SUCCESS) {
6526 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6527 }
6528}
6529
Karl Schultz6addd812016-02-02 17:17:23 -07006530TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6531 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6532 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006533 // 1. No dynamicOffset supplied
6534 // 2. Too many dynamicOffsets supplied
6535 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006536 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6538 " requires 1 dynamicOffsets, but only "
6539 "0 dynamicOffsets are left in "
6540 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006541
6542 ASSERT_NO_FATAL_FAILURE(InitState());
6543 ASSERT_NO_FATAL_FAILURE(InitViewport());
6544 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6545
6546 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006547 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6548 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006549
6550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6552 ds_pool_ci.pNext = NULL;
6553 ds_pool_ci.maxSets = 1;
6554 ds_pool_ci.poolSizeCount = 1;
6555 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006556
6557 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006558 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006559 ASSERT_VK_SUCCESS(err);
6560
6561 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006562 dsl_binding.binding = 0;
6563 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6564 dsl_binding.descriptorCount = 1;
6565 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6566 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006567
6568 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006569 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6570 ds_layout_ci.pNext = NULL;
6571 ds_layout_ci.bindingCount = 1;
6572 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006573 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006574 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006575 ASSERT_VK_SUCCESS(err);
6576
6577 VkDescriptorSet descriptorSet;
6578 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006579 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006580 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006581 alloc_info.descriptorPool = ds_pool;
6582 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006583 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006584 ASSERT_VK_SUCCESS(err);
6585
6586 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006587 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6588 pipeline_layout_ci.pNext = NULL;
6589 pipeline_layout_ci.setLayoutCount = 1;
6590 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006591
6592 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006593 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006594 ASSERT_VK_SUCCESS(err);
6595
6596 // Create a buffer to update the descriptor with
6597 uint32_t qfi = 0;
6598 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006599 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6600 buffCI.size = 1024;
6601 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6602 buffCI.queueFamilyIndexCount = 1;
6603 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006604
6605 VkBuffer dyub;
6606 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6607 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006608 // Allocate memory and bind to buffer so we can make it to the appropriate
6609 // error
6610 VkMemoryAllocateInfo mem_alloc = {};
6611 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6612 mem_alloc.pNext = NULL;
6613 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006614 mem_alloc.memoryTypeIndex = 0;
6615
6616 VkMemoryRequirements memReqs;
6617 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006618 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006619 if (!pass) {
6620 vkDestroyBuffer(m_device->device(), dyub, NULL);
6621 return;
6622 }
6623
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006624 VkDeviceMemory mem;
6625 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6626 ASSERT_VK_SUCCESS(err);
6627 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6628 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006629 // Correctly update descriptor to avoid "NOT_UPDATED" error
6630 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006631 buffInfo.buffer = dyub;
6632 buffInfo.offset = 0;
6633 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006634
6635 VkWriteDescriptorSet descriptor_write;
6636 memset(&descriptor_write, 0, sizeof(descriptor_write));
6637 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6638 descriptor_write.dstSet = descriptorSet;
6639 descriptor_write.dstBinding = 0;
6640 descriptor_write.descriptorCount = 1;
6641 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6642 descriptor_write.pBufferInfo = &buffInfo;
6643
6644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6645
Tony Barbour552f6c02016-12-21 14:34:07 -07006646 m_commandBuffer->BeginCommandBuffer();
6647 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006648 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6649 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006650 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006651 uint32_t pDynOff[2] = {512, 756};
6652 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6654 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6655 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6656 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006657 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006658 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006659 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6660 " dynamic offset 512 combined with "
6661 "offset 0 and range 1024 that "
6662 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006663 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006664 char const *vsSource =
6665 "#version 450\n"
6666 "\n"
6667 "out gl_PerVertex { \n"
6668 " vec4 gl_Position;\n"
6669 "};\n"
6670 "void main(){\n"
6671 " gl_Position = vec4(1);\n"
6672 "}\n";
6673 char const *fsSource =
6674 "#version 450\n"
6675 "\n"
6676 "layout(location=0) out vec4 x;\n"
6677 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6678 "void main(){\n"
6679 " x = vec4(bar.y);\n"
6680 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006681 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6682 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6683 VkPipelineObj pipe(m_device);
6684 pipe.AddShader(&vs);
6685 pipe.AddShader(&fs);
6686 pipe.AddColorAttachment();
6687 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6688
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006689 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6690 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6691 VkRect2D scissor = {{0, 0}, {16, 16}};
6692 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6693
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006694 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006695 // This update should succeed, but offset size of 512 will overstep buffer
6696 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006697 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6698 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006699 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006700 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006701
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006702 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006703 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006704
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006705 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006706 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006707 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6708}
6709
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006710TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006711 TEST_DESCRIPTION(
6712 "Attempt to update a descriptor with a non-sparse buffer "
6713 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006714 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006716 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6718 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006719
6720 ASSERT_NO_FATAL_FAILURE(InitState());
6721 ASSERT_NO_FATAL_FAILURE(InitViewport());
6722 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6723
6724 VkDescriptorPoolSize ds_type_count = {};
6725 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6726 ds_type_count.descriptorCount = 1;
6727
6728 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6729 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6730 ds_pool_ci.pNext = NULL;
6731 ds_pool_ci.maxSets = 1;
6732 ds_pool_ci.poolSizeCount = 1;
6733 ds_pool_ci.pPoolSizes = &ds_type_count;
6734
6735 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006736 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006737 ASSERT_VK_SUCCESS(err);
6738
6739 VkDescriptorSetLayoutBinding dsl_binding = {};
6740 dsl_binding.binding = 0;
6741 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6742 dsl_binding.descriptorCount = 1;
6743 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6744 dsl_binding.pImmutableSamplers = NULL;
6745
6746 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6747 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6748 ds_layout_ci.pNext = NULL;
6749 ds_layout_ci.bindingCount = 1;
6750 ds_layout_ci.pBindings = &dsl_binding;
6751 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006752 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006753 ASSERT_VK_SUCCESS(err);
6754
6755 VkDescriptorSet descriptorSet;
6756 VkDescriptorSetAllocateInfo alloc_info = {};
6757 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6758 alloc_info.descriptorSetCount = 1;
6759 alloc_info.descriptorPool = ds_pool;
6760 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006761 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006762 ASSERT_VK_SUCCESS(err);
6763
6764 // Create a buffer to update the descriptor with
6765 uint32_t qfi = 0;
6766 VkBufferCreateInfo buffCI = {};
6767 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6768 buffCI.size = 1024;
6769 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6770 buffCI.queueFamilyIndexCount = 1;
6771 buffCI.pQueueFamilyIndices = &qfi;
6772
6773 VkBuffer dyub;
6774 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6775 ASSERT_VK_SUCCESS(err);
6776
6777 // Attempt to update descriptor without binding memory to it
6778 VkDescriptorBufferInfo buffInfo = {};
6779 buffInfo.buffer = dyub;
6780 buffInfo.offset = 0;
6781 buffInfo.range = 1024;
6782
6783 VkWriteDescriptorSet descriptor_write;
6784 memset(&descriptor_write, 0, sizeof(descriptor_write));
6785 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6786 descriptor_write.dstSet = descriptorSet;
6787 descriptor_write.dstBinding = 0;
6788 descriptor_write.descriptorCount = 1;
6789 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6790 descriptor_write.pBufferInfo = &buffInfo;
6791
6792 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6793 m_errorMonitor->VerifyFound();
6794
6795 vkDestroyBuffer(m_device->device(), dyub, NULL);
6796 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6797 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6798}
6799
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006800TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006801 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006802 ASSERT_NO_FATAL_FAILURE(InitState());
6803 ASSERT_NO_FATAL_FAILURE(InitViewport());
6804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6805
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006806 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006807 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006808 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6809 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6810 pipeline_layout_ci.pushConstantRangeCount = 1;
6811 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6812
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006813 //
6814 // Check for invalid push constant ranges in pipeline layouts.
6815 //
6816 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006817 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006818 char const *msg;
6819 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006820
Karl Schultzc81037d2016-05-12 08:11:23 -06006821 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6822 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6823 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6824 "vkCreatePipelineLayout() call has push constants index 0 with "
6825 "size 0."},
6826 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6827 "vkCreatePipelineLayout() call has push constants index 0 with "
6828 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006829 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006830 "vkCreatePipelineLayout() call has push constants index 0 with "
6831 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006832 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006833 "vkCreatePipelineLayout() call has push constants index 0 with "
6834 "size 0."},
6835 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6836 "vkCreatePipelineLayout() call has push constants index 0 with "
6837 "offset 1. Offset must"},
6838 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6839 "vkCreatePipelineLayout() call has push constants index 0 "
6840 "with offset "},
6841 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6842 "vkCreatePipelineLayout() call has push constants "
6843 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006844 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006845 "vkCreatePipelineLayout() call has push constants index 0 "
6846 "with offset "},
6847 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6848 "vkCreatePipelineLayout() call has push "
6849 "constants index 0 with offset "},
6850 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6851 "vkCreatePipelineLayout() call has push "
6852 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006853 }};
6854
6855 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006856 for (const auto &iter : range_tests) {
6857 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6859 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006860 m_errorMonitor->VerifyFound();
6861 if (VK_SUCCESS == err) {
6862 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6863 }
6864 }
6865
6866 // Check for invalid stage flag
6867 pc_range.offset = 0;
6868 pc_range.size = 16;
6869 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006870 m_errorMonitor->SetDesiredFailureMsg(
6871 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6872 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006873 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006874 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006875 if (VK_SUCCESS == err) {
6876 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6877 }
6878
6879 // Check for overlapping ranges
Karl Schultzc81037d2016-05-12 08:11:23 -06006880 const uint32_t ranges_per_test = 5;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006881 struct OverlappingRangeTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006882 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006883 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006884 };
6885
Karl Schultzc81037d2016-05-12 08:11:23 -06006886 const std::array<OverlappingRangeTestCase, 5> overlapping_range_tests = {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006887 {{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6888 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6889 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6890 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6891 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006892 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 1:[0, 4)",
6893 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 2:[0, 4)",
6894 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 3:[0, 4)",
6895 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[0, 4), 4:[0, 4)",
6896 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 2:[0, 4)",
6897 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 3:[0, 4)",
6898 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[0, 4), 4:[0, 4)",
6899 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 3:[0, 4)",
6900 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[0, 4), 4:[0, 4)",
6901 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[0, 4), 4:[0, 4)"}},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006902 {
6903 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6904 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6905 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6906 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6907 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006908 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 3:[12, 20), 4:[16, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006909 },
6910 {
6911 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6912 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6913 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6914 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6915 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006916 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 1:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006917 },
6918 {
6919 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6920 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
6921 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
6922 {VK_SHADER_STAGE_VERTEX_BIT, 12, 8},
6923 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006924 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 3:[12, 20)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006925 },
6926 {
6927 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
6928 {VK_SHADER_STAGE_VERTEX_BIT, 32, 4},
6929 {VK_SHADER_STAGE_VERTEX_BIT, 4, 96},
6930 {VK_SHADER_STAGE_VERTEX_BIT, 40, 8},
6931 {VK_SHADER_STAGE_VERTEX_BIT, 52, 4}},
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006932 {"vkCreatePipelineLayout() call has push constants with overlapping ranges: 0:[16, 20), 2:[4, 100)",
6933 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 1:[32, 36), 2:[4, 100)",
6934 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 3:[40, 48)",
6935 "vkCreatePipelineLayout() call has push constants with overlapping ranges: 2:[4, 100), 4:[52, 56)"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006936 }}};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006937
Karl Schultzc81037d2016-05-12 08:11:23 -06006938 for (const auto &iter : overlapping_range_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006939 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006940 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006941 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006942 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006943 m_errorMonitor->VerifyFound();
6944 if (VK_SUCCESS == err) {
6945 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6946 }
6947 }
6948
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006949 //
6950 // CmdPushConstants tests
6951 //
Karl Schultzc81037d2016-05-12 08:11:23 -06006952 const uint8_t dummy_values[100] = {};
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006953
6954 // Check for invalid offset and size and if range is within layout range(s)
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006955 const std::array<PipelineLayoutTestCase, 11> cmd_range_tests = {{
6956 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0}, "vkCmdPushConstants: parameter size must be greater than 0"},
Karl Schultzc81037d2016-05-12 08:11:23 -06006957 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006958 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6959 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006960 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Dave Houlton197211a2016-12-23 15:26:29 -07006961 "vkCmdPushConstants() call has push constants index 0 with size 1. "
6962 "Size must be a multiple of 4."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006963 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006964 "vkCmdPushConstants() call has push constants with offset 1. "
6965 "Offset must be a multiple of 4."},
6966 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6967 "vkCmdPushConstants() call has push constants with offset 1. "
6968 "Offset must be a multiple of 4."},
6969 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
6970 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
6971 "0x1 not within flag-matching ranges in pipeline layout"},
6972 {{VK_SHADER_STAGE_VERTEX_BIT, 60, 8},
6973 "vkCmdPushConstants() Push constant range [60, 68) with stageFlags = "
6974 "0x1 not within flag-matching ranges in pipeline layout"},
6975 {{VK_SHADER_STAGE_VERTEX_BIT, 76, 8},
6976 "vkCmdPushConstants() Push constant range [76, 84) with stageFlags = "
6977 "0x1 not within flag-matching ranges in pipeline layout"},
6978 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 80},
6979 "vkCmdPushConstants() Push constant range [0, 80) with stageFlags = "
6980 "0x1 not within flag-matching ranges in pipeline layout"},
6981 {{VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6982 "vkCmdPushConstants() stageFlags = 0x2 do not match the stageFlags in "
6983 "any of the ranges in pipeline layout"},
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006984 {{VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 16},
Karl Schultzc81037d2016-05-12 08:11:23 -06006985 "vkCmdPushConstants() stageFlags = 0x3 do not match the stageFlags in "
6986 "any of the ranges in pipeline layout"},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006987 }};
6988
Tony Barbour552f6c02016-12-21 14:34:07 -07006989 m_commandBuffer->BeginCommandBuffer();
6990 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006991
6992 // Setup ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006993 const VkPushConstantRange pc_range2[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006994 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006995 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006996 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006997 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006998 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006999 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007000 for (const auto &iter : cmd_range_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7002 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007003 iter.range.size, dummy_values);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007004 m_errorMonitor->VerifyFound();
7005 }
7006
7007 // Check for invalid stage flag
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007009 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007010 m_errorMonitor->VerifyFound();
Karl Schultzc81037d2016-05-12 08:11:23 -06007011 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007012
Karl Schultzc81037d2016-05-12 08:11:23 -06007013 // overlapping range tests with cmd
7014 const std::array<PipelineLayoutTestCase, 3> cmd_overlap_tests = {{
7015 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 20},
7016 "vkCmdPushConstants() Push constant range [0, 20) with stageFlags = "
7017 "0x1 not within flag-matching ranges in pipeline layout"},
7018 {{VK_SHADER_STAGE_VERTEX_BIT, 16, 4},
7019 "vkCmdPushConstants() Push constant range [16, 20) with stageFlags = "
7020 "0x1 not within flag-matching ranges in pipeline layout"},
7021 {{VK_SHADER_STAGE_VERTEX_BIT, 40, 16},
7022 "vkCmdPushConstants() Push constant range [40, 56) with stageFlags = "
7023 "0x1 not within flag-matching ranges in pipeline layout"},
7024 }};
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007025 // Setup ranges: [0,16), [20,36), [36,44), [44,52), [80,92)
Karl Schultzc81037d2016-05-12 08:11:23 -06007026 const VkPushConstantRange pc_range3[] = {
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007027 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
7028 {VK_SHADER_STAGE_VERTEX_BIT, 80, 12}, {VK_SHADER_STAGE_VERTEX_BIT, 36, 8},
Karl Schultzc81037d2016-05-12 08:11:23 -06007029 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007030 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range3) / sizeof(VkPushConstantRange);
Karl Schultzc81037d2016-05-12 08:11:23 -06007031 pipeline_layout_ci.pPushConstantRanges = pc_range3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007032 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzc81037d2016-05-12 08:11:23 -06007033 ASSERT_VK_SUCCESS(err);
Karl Schultzc81037d2016-05-12 08:11:23 -06007034 for (const auto &iter : cmd_overlap_tests) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007035 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
7036 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Karl Schultzc81037d2016-05-12 08:11:23 -06007037 iter.range.size, dummy_values);
7038 m_errorMonitor->VerifyFound();
7039 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007040 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7041
Tony Barbour552f6c02016-12-21 14:34:07 -07007042 m_commandBuffer->EndRenderPass();
7043 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007044}
7045
Karl Schultz6addd812016-02-02 17:17:23 -07007046TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007047 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007048 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007049
7050 ASSERT_NO_FATAL_FAILURE(InitState());
7051 ASSERT_NO_FATAL_FAILURE(InitViewport());
7052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7053
7054 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7055 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007056 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7057 ds_type_count[0].descriptorCount = 10;
7058 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7059 ds_type_count[1].descriptorCount = 2;
7060 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7061 ds_type_count[2].descriptorCount = 2;
7062 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7063 ds_type_count[3].descriptorCount = 5;
7064 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7065 // type
7066 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7067 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7068 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007069
7070 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007071 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7072 ds_pool_ci.pNext = NULL;
7073 ds_pool_ci.maxSets = 5;
7074 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7075 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007076
7077 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007078 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007079 ASSERT_VK_SUCCESS(err);
7080
7081 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7082 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007083 dsl_binding[0].binding = 0;
7084 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7085 dsl_binding[0].descriptorCount = 5;
7086 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7087 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007088
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007089 // Create layout identical to set0 layout but w/ different stageFlags
7090 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007091 dsl_fs_stage_only.binding = 0;
7092 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7093 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007094 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7095 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007096 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007097 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007098 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7099 ds_layout_ci.pNext = NULL;
7100 ds_layout_ci.bindingCount = 1;
7101 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007102 static const uint32_t NUM_LAYOUTS = 4;
7103 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007104 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007105 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7106 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007107 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007108 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007109 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007111 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007112 dsl_binding[0].binding = 0;
7113 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007114 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007115 dsl_binding[1].binding = 1;
7116 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7117 dsl_binding[1].descriptorCount = 2;
7118 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7119 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007120 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007122 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007123 ASSERT_VK_SUCCESS(err);
7124 dsl_binding[0].binding = 0;
7125 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007126 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007128 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007129 ASSERT_VK_SUCCESS(err);
7130 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007131 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007132 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007133 ASSERT_VK_SUCCESS(err);
7134
7135 static const uint32_t NUM_SETS = 4;
7136 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7137 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007138 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007139 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007140 alloc_info.descriptorPool = ds_pool;
7141 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007142 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007143 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007144 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007145 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007147 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007148 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007149
7150 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007151 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7152 pipeline_layout_ci.pNext = NULL;
7153 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7154 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007155
7156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007157 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007158 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007159 // Create pipelineLayout with only one setLayout
7160 pipeline_layout_ci.setLayoutCount = 1;
7161 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007162 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007163 ASSERT_VK_SUCCESS(err);
7164 // Create pipelineLayout with 2 descriptor setLayout at index 0
7165 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7166 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007167 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007168 ASSERT_VK_SUCCESS(err);
7169 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7170 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7171 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007172 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007173 ASSERT_VK_SUCCESS(err);
7174 // Create pipelineLayout with UB type, but stageFlags for FS only
7175 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7176 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007177 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007178 ASSERT_VK_SUCCESS(err);
7179 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7180 VkDescriptorSetLayout pl_bad_s0[2] = {};
7181 pl_bad_s0[0] = ds_layout_fs_only;
7182 pl_bad_s0[1] = ds_layout[1];
7183 pipeline_layout_ci.setLayoutCount = 2;
7184 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7185 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007186 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007187 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007188
Tobin Ehlis88452832015-12-03 09:40:56 -07007189 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007190 char const *vsSource =
7191 "#version 450\n"
7192 "\n"
7193 "out gl_PerVertex {\n"
7194 " vec4 gl_Position;\n"
7195 "};\n"
7196 "void main(){\n"
7197 " gl_Position = vec4(1);\n"
7198 "}\n";
7199 char const *fsSource =
7200 "#version 450\n"
7201 "\n"
7202 "layout(location=0) out vec4 x;\n"
7203 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7204 "void main(){\n"
7205 " x = vec4(bar.y);\n"
7206 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007207 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7208 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007209 VkPipelineObj pipe(m_device);
7210 pipe.AddShader(&vs);
7211 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007212 pipe.AddColorAttachment();
7213 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007214
Tony Barbour552f6c02016-12-21 14:34:07 -07007215 m_commandBuffer->BeginCommandBuffer();
7216 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007217
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007218 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007219 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7220 // of PSO
7221 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7222 // cmd_pipeline.c
7223 // due to the fact that cmd_alloc_dset_data() has not been called in
7224 // cmd_bind_graphics_pipeline()
7225 // TODO : Want to cause various binding incompatibility issues here to test
7226 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007227 // First cause various verify_layout_compatibility() fails
7228 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007229 // verify_set_layout_compatibility fail cases:
7230 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007232 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7233 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007234 m_errorMonitor->VerifyFound();
7235
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007236 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7238 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7239 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007240 m_errorMonitor->VerifyFound();
7241
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007242 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007243 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7244 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7246 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7247 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007248 m_errorMonitor->VerifyFound();
7249
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007250 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7251 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007252 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7253 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7254 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007255 m_errorMonitor->VerifyFound();
7256
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007257 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7258 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7260 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7261 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7262 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007263 m_errorMonitor->VerifyFound();
7264
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007265 // Cause INFO messages due to disturbing previously bound Sets
7266 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007267 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7268 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007269 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7271 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7272 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007273 m_errorMonitor->VerifyFound();
7274
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007275 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7276 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007277 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7279 " newly bound as set #0 so set #1 and "
7280 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007281 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7282 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007283 m_errorMonitor->VerifyFound();
7284
Tobin Ehlis10fad692016-07-07 12:00:36 -06007285 // Now that we're done actively using the pipelineLayout that gfx pipeline
7286 // was created with, we should be able to delete it. Do that now to verify
7287 // that validation obeys pipelineLayout lifetime
7288 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7289
Tobin Ehlis88452832015-12-03 09:40:56 -07007290 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007291 // 1. Error due to not binding required set (we actually use same code as
7292 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007293 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7294 &descriptorSet[0], 0, NULL);
7295 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7296 &descriptorSet[1], 0, NULL);
7297 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 -07007298
7299 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7300 VkRect2D scissor = {{0, 0}, {16, 16}};
7301 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7302 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7303
Tobin Ehlis88452832015-12-03 09:40:56 -07007304 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007305 m_errorMonitor->VerifyFound();
7306
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007307 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007308 // 2. Error due to bound set not being compatible with PSO's
7309 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007310 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7311 &descriptorSet[0], 0, NULL);
7312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007313 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007314 m_errorMonitor->VerifyFound();
7315
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007316 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007317 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7319 }
7320 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007321 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7322 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7323}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007324
Karl Schultz6addd812016-02-02 17:17:23 -07007325TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7327 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007328
7329 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007330 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007331 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007332 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007333
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007334 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007335}
7336
Karl Schultz6addd812016-02-02 17:17:23 -07007337TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7338 VkResult err;
7339 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007340
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007341 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007342
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007343 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007344
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007345 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007346 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007347 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007348 cmd.commandPool = m_commandPool;
7349 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007350 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007351
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007352 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007353 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007354
7355 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007356 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007357 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7358
7359 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007360 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007361 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007362 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 -07007363 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007364
7365 // The error should be caught by validation of the BeginCommandBuffer call
7366 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7367
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007368 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007369 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007370}
7371
Karl Schultz6addd812016-02-02 17:17:23 -07007372TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007373 // Cause error due to Begin while recording CB
7374 // Then cause 2 errors for attempting to reset CB w/o having
7375 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7376 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007378
7379 ASSERT_NO_FATAL_FAILURE(InitState());
7380
7381 // Calls AllocateCommandBuffers
7382 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7383
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007384 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007385 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007386 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7387 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007388 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7389 cmd_buf_info.pNext = NULL;
7390 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007391 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007392
7393 // Begin CB to transition to recording state
7394 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7395 // Can't re-begin. This should trigger error
7396 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007397 m_errorMonitor->VerifyFound();
7398
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007400 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007401 // Reset attempt will trigger error due to incorrect CommandPool state
7402 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007403 m_errorMonitor->VerifyFound();
7404
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007406 // Transition CB to RECORDED state
7407 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7408 // Now attempting to Begin will implicitly reset, which triggers error
7409 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007410 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007411}
7412
Karl Schultz6addd812016-02-02 17:17:23 -07007413TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007414 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007415 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007416
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7418 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007419
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007420 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007422
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007423 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007424 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7425 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007426
7427 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007428 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7429 ds_pool_ci.pNext = NULL;
7430 ds_pool_ci.maxSets = 1;
7431 ds_pool_ci.poolSizeCount = 1;
7432 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007433
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007434 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007435 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007436 ASSERT_VK_SUCCESS(err);
7437
Tony Barboureb254902015-07-15 12:50:33 -06007438 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007439 dsl_binding.binding = 0;
7440 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7441 dsl_binding.descriptorCount = 1;
7442 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7443 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007444
Tony Barboureb254902015-07-15 12:50:33 -06007445 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007446 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7447 ds_layout_ci.pNext = NULL;
7448 ds_layout_ci.bindingCount = 1;
7449 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007450
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007451 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007452 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007453 ASSERT_VK_SUCCESS(err);
7454
7455 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007456 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007457 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007458 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007459 alloc_info.descriptorPool = ds_pool;
7460 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007461 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007462 ASSERT_VK_SUCCESS(err);
7463
Tony Barboureb254902015-07-15 12:50:33 -06007464 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007465 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7466 pipeline_layout_ci.setLayoutCount = 1;
7467 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007468
7469 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007470 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007471 ASSERT_VK_SUCCESS(err);
7472
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007473 VkViewport vp = {}; // Just need dummy vp to point to
7474 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007475
7476 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007477 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7478 vp_state_ci.scissorCount = 1;
7479 vp_state_ci.pScissors = &sc;
7480 vp_state_ci.viewportCount = 1;
7481 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007482
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007483 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7484 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7485 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7486 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7487 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7488 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007489 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007490 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007491 rs_state_ci.lineWidth = 1.0f;
7492
7493 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7494 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7495 vi_ci.pNext = nullptr;
7496 vi_ci.vertexBindingDescriptionCount = 0;
7497 vi_ci.pVertexBindingDescriptions = nullptr;
7498 vi_ci.vertexAttributeDescriptionCount = 0;
7499 vi_ci.pVertexAttributeDescriptions = nullptr;
7500
7501 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7502 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7503 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7504
7505 VkPipelineShaderStageCreateInfo shaderStages[2];
7506 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7507
7508 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7509 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007510 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007511 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007512
Tony Barboureb254902015-07-15 12:50:33 -06007513 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007514 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7515 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007516 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007517 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7518 gp_ci.layout = pipeline_layout;
7519 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007520 gp_ci.pVertexInputState = &vi_ci;
7521 gp_ci.pInputAssemblyState = &ia_ci;
7522
7523 gp_ci.stageCount = 1;
7524 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007525
7526 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007527 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7528 pc_ci.initialDataSize = 0;
7529 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007530
7531 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007532 VkPipelineCache pipelineCache;
7533
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007535 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007536 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007537 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007538
Chia-I Wuf7458c52015-10-26 21:10:41 +08007539 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7540 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7541 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7542 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007543}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007544
Tobin Ehlis912df022015-09-17 08:46:18 -06007545/*// TODO : This test should be good, but needs Tess support in compiler to run
7546TEST_F(VkLayerTest, InvalidPatchControlPoints)
7547{
7548 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007549 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007550
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007552 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7553primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007554
Tobin Ehlis912df022015-09-17 08:46:18 -06007555 ASSERT_NO_FATAL_FAILURE(InitState());
7556 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007557
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007558 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007559 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007560 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007561
7562 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7563 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7564 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007565 ds_pool_ci.poolSizeCount = 1;
7566 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007567
7568 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007569 err = vkCreateDescriptorPool(m_device->device(),
7570VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007571 ASSERT_VK_SUCCESS(err);
7572
7573 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007574 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007575 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007576 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007577 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7578 dsl_binding.pImmutableSamplers = NULL;
7579
7580 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007581 ds_layout_ci.sType =
7582VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007583 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007584 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007585 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007586
7587 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007588 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7589&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007590 ASSERT_VK_SUCCESS(err);
7591
7592 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007593 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7594VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007595 ASSERT_VK_SUCCESS(err);
7596
7597 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007598 pipeline_layout_ci.sType =
7599VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007600 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007601 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007602 pipeline_layout_ci.pSetLayouts = &ds_layout;
7603
7604 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007605 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7606&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007607 ASSERT_VK_SUCCESS(err);
7608
7609 VkPipelineShaderStageCreateInfo shaderStages[3];
7610 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7611
Karl Schultz6addd812016-02-02 17:17:23 -07007612 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7613this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007614 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007615 VkShaderObj
7616tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7617this);
7618 VkShaderObj
7619te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7620this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007621
Karl Schultz6addd812016-02-02 17:17:23 -07007622 shaderStages[0].sType =
7623VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007624 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007625 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007626 shaderStages[1].sType =
7627VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007628 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007629 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007630 shaderStages[2].sType =
7631VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007632 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007633 shaderStages[2].shader = te.handle();
7634
7635 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007636 iaCI.sType =
7637VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007638 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007639
7640 VkPipelineTessellationStateCreateInfo tsCI = {};
7641 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7642 tsCI.patchControlPoints = 0; // This will cause an error
7643
7644 VkGraphicsPipelineCreateInfo gp_ci = {};
7645 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7646 gp_ci.pNext = NULL;
7647 gp_ci.stageCount = 3;
7648 gp_ci.pStages = shaderStages;
7649 gp_ci.pVertexInputState = NULL;
7650 gp_ci.pInputAssemblyState = &iaCI;
7651 gp_ci.pTessellationState = &tsCI;
7652 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007653 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007654 gp_ci.pMultisampleState = NULL;
7655 gp_ci.pDepthStencilState = NULL;
7656 gp_ci.pColorBlendState = NULL;
7657 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7658 gp_ci.layout = pipeline_layout;
7659 gp_ci.renderPass = renderPass();
7660
7661 VkPipelineCacheCreateInfo pc_ci = {};
7662 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7663 pc_ci.pNext = NULL;
7664 pc_ci.initialSize = 0;
7665 pc_ci.initialData = 0;
7666 pc_ci.maxSize = 0;
7667
7668 VkPipeline pipeline;
7669 VkPipelineCache pipelineCache;
7670
Karl Schultz6addd812016-02-02 17:17:23 -07007671 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7672&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007673 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007674 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7675&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007676
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007677 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007678
Chia-I Wuf7458c52015-10-26 21:10:41 +08007679 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7680 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7681 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7682 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007683}
7684*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007685
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007686TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007687 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007688
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007689 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007690
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691 ASSERT_NO_FATAL_FAILURE(InitState());
7692 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007693
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007694 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007695 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7696 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007697
7698 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007699 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7700 ds_pool_ci.maxSets = 1;
7701 ds_pool_ci.poolSizeCount = 1;
7702 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007703
7704 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007705 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007706 ASSERT_VK_SUCCESS(err);
7707
7708 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007709 dsl_binding.binding = 0;
7710 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7711 dsl_binding.descriptorCount = 1;
7712 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007713
7714 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007715 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7716 ds_layout_ci.bindingCount = 1;
7717 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007718
7719 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007720 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007721 ASSERT_VK_SUCCESS(err);
7722
7723 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007724 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007725 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007726 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007727 alloc_info.descriptorPool = ds_pool;
7728 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007729 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007730 ASSERT_VK_SUCCESS(err);
7731
7732 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007733 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7734 pipeline_layout_ci.setLayoutCount = 1;
7735 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007736
7737 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007738 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007739 ASSERT_VK_SUCCESS(err);
7740
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007741 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007742 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007743 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007744 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007745 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007746 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007747
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007748 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7749 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7750 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7751 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7752 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7753 rs_state_ci.depthClampEnable = VK_FALSE;
7754 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7755 rs_state_ci.depthBiasEnable = VK_FALSE;
7756
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007757 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7758 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7759 vi_ci.pNext = nullptr;
7760 vi_ci.vertexBindingDescriptionCount = 0;
7761 vi_ci.pVertexBindingDescriptions = nullptr;
7762 vi_ci.vertexAttributeDescriptionCount = 0;
7763 vi_ci.pVertexAttributeDescriptions = nullptr;
7764
7765 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7766 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7767 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7768
7769 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7770 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7771 pipe_ms_state_ci.pNext = NULL;
7772 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7773 pipe_ms_state_ci.sampleShadingEnable = 0;
7774 pipe_ms_state_ci.minSampleShading = 1.0;
7775 pipe_ms_state_ci.pSampleMask = NULL;
7776
Cody Northropeb3a6c12015-10-05 14:44:45 -06007777 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007778 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007779
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007780 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007781 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007782 shaderStages[0] = vs.GetStageCreateInfo();
7783 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007784
7785 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007786 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7787 gp_ci.stageCount = 2;
7788 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007789 gp_ci.pVertexInputState = &vi_ci;
7790 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007791 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007792 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007793 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007794 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7795 gp_ci.layout = pipeline_layout;
7796 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007797
7798 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007799 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007800
7801 VkPipeline pipeline;
7802 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007803 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007804 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007805
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007806 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007807 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007808
7809 // Check case where multiViewport is disabled and viewport count is not 1
7810 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7811 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7813 vp_state_ci.scissorCount = 0;
7814 vp_state_ci.viewportCount = 0;
7815 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7816 m_errorMonitor->VerifyFound();
7817 } else {
7818 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007819 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007820 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007821 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007822
7823 // Check is that viewportcount and scissorcount match
7824 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7825 vp_state_ci.scissorCount = 1;
7826 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7827 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7828 m_errorMonitor->VerifyFound();
7829
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007830 // Check case where multiViewport is enabled and viewport count is greater than max
7831 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7834 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7835 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7836 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7837 m_errorMonitor->VerifyFound();
7838 }
7839 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007840
Chia-I Wuf7458c52015-10-26 21:10:41 +08007841 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7842 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7843 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7844 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007845}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007846
7847// 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
7848// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007849TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007850 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007851
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007852 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7853
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007854 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007855
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856 ASSERT_NO_FATAL_FAILURE(InitState());
7857 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007858
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007859 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007860 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7861 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007862
7863 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007864 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7865 ds_pool_ci.maxSets = 1;
7866 ds_pool_ci.poolSizeCount = 1;
7867 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007868
7869 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007870 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871 ASSERT_VK_SUCCESS(err);
7872
7873 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007874 dsl_binding.binding = 0;
7875 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7876 dsl_binding.descriptorCount = 1;
7877 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007878
7879 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007880 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7881 ds_layout_ci.bindingCount = 1;
7882 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007883
7884 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007885 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007886 ASSERT_VK_SUCCESS(err);
7887
7888 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007889 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007890 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007891 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007892 alloc_info.descriptorPool = ds_pool;
7893 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007894 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007895 ASSERT_VK_SUCCESS(err);
7896
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007897 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7898 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7899 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7900
7901 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7902 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7903 vi_ci.pNext = nullptr;
7904 vi_ci.vertexBindingDescriptionCount = 0;
7905 vi_ci.pVertexBindingDescriptions = nullptr;
7906 vi_ci.vertexAttributeDescriptionCount = 0;
7907 vi_ci.pVertexAttributeDescriptions = nullptr;
7908
7909 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7910 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7911 pipe_ms_state_ci.pNext = NULL;
7912 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7913 pipe_ms_state_ci.sampleShadingEnable = 0;
7914 pipe_ms_state_ci.minSampleShading = 1.0;
7915 pipe_ms_state_ci.pSampleMask = NULL;
7916
Tobin Ehlise68360f2015-10-01 11:15:13 -06007917 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007918 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7919 pipeline_layout_ci.setLayoutCount = 1;
7920 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007921
7922 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007923 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007924 ASSERT_VK_SUCCESS(err);
7925
7926 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7927 // Set scissor as dynamic to avoid second error
7928 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007929 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7930 dyn_state_ci.dynamicStateCount = 1;
7931 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007932
Cody Northropeb3a6c12015-10-05 14:44:45 -06007933 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007934 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007935
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007936 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007937 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7938 // 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 +08007939 shaderStages[0] = vs.GetStageCreateInfo();
7940 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007941
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007942 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7943 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7944 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7945 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7946 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7947 rs_state_ci.depthClampEnable = VK_FALSE;
7948 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7949 rs_state_ci.depthBiasEnable = VK_FALSE;
7950
Tobin Ehlise68360f2015-10-01 11:15:13 -06007951 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007952 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7953 gp_ci.stageCount = 2;
7954 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007955 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007956 // Not setting VP state w/o dynamic vp state should cause validation error
7957 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007958 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007959 gp_ci.pVertexInputState = &vi_ci;
7960 gp_ci.pInputAssemblyState = &ia_ci;
7961 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007962 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7963 gp_ci.layout = pipeline_layout;
7964 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007965
7966 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007967 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007968
7969 VkPipeline pipeline;
7970 VkPipelineCache pipelineCache;
7971
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007973 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007974 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007976 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007977
Chia-I Wuf7458c52015-10-26 21:10:41 +08007978 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7979 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7980 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7981 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007982}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007983
7984// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7985// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007986TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7987 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007988
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007990
Tobin Ehlise68360f2015-10-01 11:15:13 -06007991 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007992
7993 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007994 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007995 return;
7996 }
7997
Tobin Ehlise68360f2015-10-01 11:15:13 -06007998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007999
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008000 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008001 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8002 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008003
8004 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008005 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8006 ds_pool_ci.maxSets = 1;
8007 ds_pool_ci.poolSizeCount = 1;
8008 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008009
8010 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008011 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012 ASSERT_VK_SUCCESS(err);
8013
8014 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008015 dsl_binding.binding = 0;
8016 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8017 dsl_binding.descriptorCount = 1;
8018 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008019
8020 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008021 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8022 ds_layout_ci.bindingCount = 1;
8023 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008024
8025 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008026 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008027 ASSERT_VK_SUCCESS(err);
8028
8029 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008030 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008031 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008032 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008033 alloc_info.descriptorPool = ds_pool;
8034 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008035 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008036 ASSERT_VK_SUCCESS(err);
8037
8038 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008039 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8040 pipeline_layout_ci.setLayoutCount = 1;
8041 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008042
8043 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008044 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008045 ASSERT_VK_SUCCESS(err);
8046
8047 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008048 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8049 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008050 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008051 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008052 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008053
8054 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8055 // Set scissor as dynamic to avoid that error
8056 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008057 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8058 dyn_state_ci.dynamicStateCount = 1;
8059 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008060
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008061 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8062 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8063 pipe_ms_state_ci.pNext = NULL;
8064 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8065 pipe_ms_state_ci.sampleShadingEnable = 0;
8066 pipe_ms_state_ci.minSampleShading = 1.0;
8067 pipe_ms_state_ci.pSampleMask = NULL;
8068
Cody Northropeb3a6c12015-10-05 14:44:45 -06008069 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008070 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008071
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008072 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008073 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8074 // 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 +08008075 shaderStages[0] = vs.GetStageCreateInfo();
8076 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008077
Cody Northropf6622dc2015-10-06 10:33:21 -06008078 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8079 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8080 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008081 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008082 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008083 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008084 vi_ci.pVertexAttributeDescriptions = nullptr;
8085
8086 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8087 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8088 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8089
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008090 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008091 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008092 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008093 rs_ci.pNext = nullptr;
8094
Mark Youngc89c6312016-03-31 16:03:20 -06008095 VkPipelineColorBlendAttachmentState att = {};
8096 att.blendEnable = VK_FALSE;
8097 att.colorWriteMask = 0xf;
8098
Cody Northropf6622dc2015-10-06 10:33:21 -06008099 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8100 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8101 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008102 cb_ci.attachmentCount = 1;
8103 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008104
Tobin Ehlise68360f2015-10-01 11:15:13 -06008105 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008106 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8107 gp_ci.stageCount = 2;
8108 gp_ci.pStages = shaderStages;
8109 gp_ci.pVertexInputState = &vi_ci;
8110 gp_ci.pInputAssemblyState = &ia_ci;
8111 gp_ci.pViewportState = &vp_state_ci;
8112 gp_ci.pRasterizationState = &rs_ci;
8113 gp_ci.pColorBlendState = &cb_ci;
8114 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008115 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008116 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8117 gp_ci.layout = pipeline_layout;
8118 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008119
8120 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008121 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008122
8123 VkPipeline pipeline;
8124 VkPipelineCache pipelineCache;
8125
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008127 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008128 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008129
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008130 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008131
Tobin Ehlisd332f282015-10-02 11:00:56 -06008132 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008133 // First need to successfully create the PSO from above by setting
8134 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008135 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 -07008136
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008137 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008138 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008139 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008140 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008141 m_commandBuffer->BeginCommandBuffer();
8142 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008143 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008144 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008145 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008146 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008147 Draw(1, 0, 0, 0);
8148
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008149 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008150
8151 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8154 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008155 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008156}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008157
8158// 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 -07008159// viewportCount
8160TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8161 VkResult err;
8162
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008164
8165 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008166
8167 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008168 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008169 return;
8170 }
8171
Karl Schultz6addd812016-02-02 17:17:23 -07008172 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8173
8174 VkDescriptorPoolSize ds_type_count = {};
8175 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8176 ds_type_count.descriptorCount = 1;
8177
8178 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8179 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8180 ds_pool_ci.maxSets = 1;
8181 ds_pool_ci.poolSizeCount = 1;
8182 ds_pool_ci.pPoolSizes = &ds_type_count;
8183
8184 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008185 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008186 ASSERT_VK_SUCCESS(err);
8187
8188 VkDescriptorSetLayoutBinding dsl_binding = {};
8189 dsl_binding.binding = 0;
8190 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8191 dsl_binding.descriptorCount = 1;
8192 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8193
8194 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8195 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8196 ds_layout_ci.bindingCount = 1;
8197 ds_layout_ci.pBindings = &dsl_binding;
8198
8199 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008200 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008201 ASSERT_VK_SUCCESS(err);
8202
8203 VkDescriptorSet descriptorSet;
8204 VkDescriptorSetAllocateInfo alloc_info = {};
8205 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8206 alloc_info.descriptorSetCount = 1;
8207 alloc_info.descriptorPool = ds_pool;
8208 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008209 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008210 ASSERT_VK_SUCCESS(err);
8211
8212 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8213 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8214 pipeline_layout_ci.setLayoutCount = 1;
8215 pipeline_layout_ci.pSetLayouts = &ds_layout;
8216
8217 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008219 ASSERT_VK_SUCCESS(err);
8220
8221 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8222 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8223 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008224 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008225 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008226 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008227
8228 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8229 // Set scissor as dynamic to avoid that error
8230 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8231 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8232 dyn_state_ci.dynamicStateCount = 1;
8233 dyn_state_ci.pDynamicStates = &vp_state;
8234
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008235 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8236 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8237 pipe_ms_state_ci.pNext = NULL;
8238 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8239 pipe_ms_state_ci.sampleShadingEnable = 0;
8240 pipe_ms_state_ci.minSampleShading = 1.0;
8241 pipe_ms_state_ci.pSampleMask = NULL;
8242
Karl Schultz6addd812016-02-02 17:17:23 -07008243 VkPipelineShaderStageCreateInfo shaderStages[2];
8244 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8245
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008246 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008247 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8248 // 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 -07008249 shaderStages[0] = vs.GetStageCreateInfo();
8250 shaderStages[1] = fs.GetStageCreateInfo();
8251
8252 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8253 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8254 vi_ci.pNext = nullptr;
8255 vi_ci.vertexBindingDescriptionCount = 0;
8256 vi_ci.pVertexBindingDescriptions = nullptr;
8257 vi_ci.vertexAttributeDescriptionCount = 0;
8258 vi_ci.pVertexAttributeDescriptions = nullptr;
8259
8260 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8261 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8262 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8263
8264 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8265 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008266 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008267 rs_ci.pNext = nullptr;
8268
Mark Youngc89c6312016-03-31 16:03:20 -06008269 VkPipelineColorBlendAttachmentState att = {};
8270 att.blendEnable = VK_FALSE;
8271 att.colorWriteMask = 0xf;
8272
Karl Schultz6addd812016-02-02 17:17:23 -07008273 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8274 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8275 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008276 cb_ci.attachmentCount = 1;
8277 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008278
8279 VkGraphicsPipelineCreateInfo gp_ci = {};
8280 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8281 gp_ci.stageCount = 2;
8282 gp_ci.pStages = shaderStages;
8283 gp_ci.pVertexInputState = &vi_ci;
8284 gp_ci.pInputAssemblyState = &ia_ci;
8285 gp_ci.pViewportState = &vp_state_ci;
8286 gp_ci.pRasterizationState = &rs_ci;
8287 gp_ci.pColorBlendState = &cb_ci;
8288 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008289 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008290 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8291 gp_ci.layout = pipeline_layout;
8292 gp_ci.renderPass = renderPass();
8293
8294 VkPipelineCacheCreateInfo pc_ci = {};
8295 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8296
8297 VkPipeline pipeline;
8298 VkPipelineCache pipelineCache;
8299
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008301 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008303
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008304 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008305
8306 // Now hit second fail case where we set scissor w/ different count than PSO
8307 // First need to successfully create the PSO from above by setting
8308 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008309 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8310 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008311
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008312 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008313 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008314 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008315 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008316 m_commandBuffer->BeginCommandBuffer();
8317 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008318 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008319 VkViewport viewports[1] = {};
8320 viewports[0].width = 8;
8321 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008322 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008323 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008324 Draw(1, 0, 0, 0);
8325
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008326 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008327
Chia-I Wuf7458c52015-10-26 21:10:41 +08008328 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8329 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8330 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8331 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008332 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008333}
8334
Mark Young7394fdd2016-03-31 14:56:43 -06008335TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8336 VkResult err;
8337
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008338 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008339
8340 ASSERT_NO_FATAL_FAILURE(InitState());
8341 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8342
8343 VkDescriptorPoolSize ds_type_count = {};
8344 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8345 ds_type_count.descriptorCount = 1;
8346
8347 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8348 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8349 ds_pool_ci.maxSets = 1;
8350 ds_pool_ci.poolSizeCount = 1;
8351 ds_pool_ci.pPoolSizes = &ds_type_count;
8352
8353 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008354 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008355 ASSERT_VK_SUCCESS(err);
8356
8357 VkDescriptorSetLayoutBinding dsl_binding = {};
8358 dsl_binding.binding = 0;
8359 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8360 dsl_binding.descriptorCount = 1;
8361 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8362
8363 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8364 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8365 ds_layout_ci.bindingCount = 1;
8366 ds_layout_ci.pBindings = &dsl_binding;
8367
8368 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008369 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008370 ASSERT_VK_SUCCESS(err);
8371
8372 VkDescriptorSet descriptorSet;
8373 VkDescriptorSetAllocateInfo alloc_info = {};
8374 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8375 alloc_info.descriptorSetCount = 1;
8376 alloc_info.descriptorPool = ds_pool;
8377 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008378 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008379 ASSERT_VK_SUCCESS(err);
8380
8381 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8382 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8383 pipeline_layout_ci.setLayoutCount = 1;
8384 pipeline_layout_ci.pSetLayouts = &ds_layout;
8385
8386 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008387 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008388 ASSERT_VK_SUCCESS(err);
8389
8390 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8391 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8392 vp_state_ci.scissorCount = 1;
8393 vp_state_ci.pScissors = NULL;
8394 vp_state_ci.viewportCount = 1;
8395 vp_state_ci.pViewports = NULL;
8396
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008397 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008398 // Set scissor as dynamic to avoid that error
8399 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8400 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8401 dyn_state_ci.dynamicStateCount = 2;
8402 dyn_state_ci.pDynamicStates = dynamic_states;
8403
8404 VkPipelineShaderStageCreateInfo shaderStages[2];
8405 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8406
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008407 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8408 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008409 this); // TODO - We shouldn't need a fragment shader
8410 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008411 shaderStages[0] = vs.GetStageCreateInfo();
8412 shaderStages[1] = fs.GetStageCreateInfo();
8413
8414 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8415 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8416 vi_ci.pNext = nullptr;
8417 vi_ci.vertexBindingDescriptionCount = 0;
8418 vi_ci.pVertexBindingDescriptions = nullptr;
8419 vi_ci.vertexAttributeDescriptionCount = 0;
8420 vi_ci.pVertexAttributeDescriptions = nullptr;
8421
8422 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8423 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8424 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8425
8426 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8427 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8428 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008429 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008430
Mark Young47107952016-05-02 15:59:55 -06008431 // Check too low (line width of -1.0f).
8432 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008433
8434 VkPipelineColorBlendAttachmentState att = {};
8435 att.blendEnable = VK_FALSE;
8436 att.colorWriteMask = 0xf;
8437
8438 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8439 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8440 cb_ci.pNext = nullptr;
8441 cb_ci.attachmentCount = 1;
8442 cb_ci.pAttachments = &att;
8443
8444 VkGraphicsPipelineCreateInfo gp_ci = {};
8445 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8446 gp_ci.stageCount = 2;
8447 gp_ci.pStages = shaderStages;
8448 gp_ci.pVertexInputState = &vi_ci;
8449 gp_ci.pInputAssemblyState = &ia_ci;
8450 gp_ci.pViewportState = &vp_state_ci;
8451 gp_ci.pRasterizationState = &rs_ci;
8452 gp_ci.pColorBlendState = &cb_ci;
8453 gp_ci.pDynamicState = &dyn_state_ci;
8454 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8455 gp_ci.layout = pipeline_layout;
8456 gp_ci.renderPass = renderPass();
8457
8458 VkPipelineCacheCreateInfo pc_ci = {};
8459 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8460
8461 VkPipeline pipeline;
8462 VkPipelineCache pipelineCache;
8463
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008465 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008467
8468 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008469 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008472
8473 // Check too high (line width of 65536.0f).
8474 rs_ci.lineWidth = 65536.0f;
8475
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008477 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008478 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008479
8480 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008481 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008482
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008484
8485 dyn_state_ci.dynamicStateCount = 3;
8486
8487 rs_ci.lineWidth = 1.0f;
8488
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008490 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008492 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008493 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008494
8495 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008496 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008497 m_errorMonitor->VerifyFound();
8498
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008500
8501 // Check too high with dynamic setting.
8502 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8503 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008504 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008505
8506 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8507 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8508 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8509 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008510 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008511}
8512
Karl Schultz6addd812016-02-02 17:17:23 -07008513TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008514 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008515 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008516 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008517
8518 ASSERT_NO_FATAL_FAILURE(InitState());
8519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008520
Tony Barbour552f6c02016-12-21 14:34:07 -07008521 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008522 // Don't care about RenderPass handle b/c error should be flagged before
8523 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008524 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008525
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008526 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008527}
8528
Karl Schultz6addd812016-02-02 17:17:23 -07008529TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008530 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008531 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8532 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008533
8534 ASSERT_NO_FATAL_FAILURE(InitState());
8535 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008536
Tony Barbour552f6c02016-12-21 14:34:07 -07008537 m_commandBuffer->BeginCommandBuffer();
8538 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008539 // Just create a dummy Renderpass that's non-NULL so we can get to the
8540 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008541 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008542
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008543 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008544}
8545
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008546TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008547 TEST_DESCRIPTION(
8548 "Begin a renderPass where clearValueCount is less than"
8549 "the number of renderPass attachments that use loadOp"
8550 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008551
8552 ASSERT_NO_FATAL_FAILURE(InitState());
8553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8554
8555 // Create a renderPass with a single attachment that uses loadOp CLEAR
8556 VkAttachmentReference attach = {};
8557 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8558 VkSubpassDescription subpass = {};
8559 subpass.inputAttachmentCount = 1;
8560 subpass.pInputAttachments = &attach;
8561 VkRenderPassCreateInfo rpci = {};
8562 rpci.subpassCount = 1;
8563 rpci.pSubpasses = &subpass;
8564 rpci.attachmentCount = 1;
8565 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008566 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008567 // Set loadOp to CLEAR
8568 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8569 rpci.pAttachments = &attach_desc;
8570 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8571 VkRenderPass rp;
8572 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8573
8574 VkCommandBufferInheritanceInfo hinfo = {};
8575 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8576 hinfo.renderPass = VK_NULL_HANDLE;
8577 hinfo.subpass = 0;
8578 hinfo.framebuffer = VK_NULL_HANDLE;
8579 hinfo.occlusionQueryEnable = VK_FALSE;
8580 hinfo.queryFlags = 0;
8581 hinfo.pipelineStatistics = 0;
8582 VkCommandBufferBeginInfo info = {};
8583 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8584 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8585 info.pInheritanceInfo = &hinfo;
8586
8587 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8588 VkRenderPassBeginInfo rp_begin = {};
8589 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8590 rp_begin.pNext = NULL;
8591 rp_begin.renderPass = renderPass();
8592 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008593 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008594
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008596
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008597 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008598
8599 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008600
8601 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008602}
8603
Slawomir Cygan0808f392016-11-28 17:53:23 +01008604TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008605 TEST_DESCRIPTION(
8606 "Begin a renderPass where clearValueCount is greater than"
8607 "the number of renderPass attachments that use loadOp"
8608 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008609
8610 ASSERT_NO_FATAL_FAILURE(InitState());
8611 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8612
8613 // Create a renderPass with a single attachment that uses loadOp CLEAR
8614 VkAttachmentReference attach = {};
8615 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8616 VkSubpassDescription subpass = {};
8617 subpass.inputAttachmentCount = 1;
8618 subpass.pInputAttachments = &attach;
8619 VkRenderPassCreateInfo rpci = {};
8620 rpci.subpassCount = 1;
8621 rpci.pSubpasses = &subpass;
8622 rpci.attachmentCount = 1;
8623 VkAttachmentDescription attach_desc = {};
8624 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8625 // Set loadOp to CLEAR
8626 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8627 rpci.pAttachments = &attach_desc;
8628 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8629 VkRenderPass rp;
8630 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8631
8632 VkCommandBufferBeginInfo info = {};
8633 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8634 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8635
8636 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8637 VkRenderPassBeginInfo rp_begin = {};
8638 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8639 rp_begin.pNext = NULL;
8640 rp_begin.renderPass = renderPass();
8641 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008642 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008643
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8645 " has a clearValueCount of"
8646 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008647
8648 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8649
8650 m_errorMonitor->VerifyFound();
8651
8652 vkDestroyRenderPass(m_device->device(), rp, NULL);
8653}
8654
Cody Northrop3bb4d962016-05-09 16:15:57 -06008655TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008656 TEST_DESCRIPTION("End a command buffer with an active render pass");
8657
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8659 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008660
8661 ASSERT_NO_FATAL_FAILURE(InitState());
8662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8663
Tony Barbour552f6c02016-12-21 14:34:07 -07008664 m_commandBuffer->BeginCommandBuffer();
8665 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8666 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008667
8668 m_errorMonitor->VerifyFound();
8669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008670 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8671 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008672}
8673
Karl Schultz6addd812016-02-02 17:17:23 -07008674TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008675 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8677 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008678
8679 ASSERT_NO_FATAL_FAILURE(InitState());
8680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008681
Tony Barbour552f6c02016-12-21 14:34:07 -07008682 m_commandBuffer->BeginCommandBuffer();
8683 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008684
8685 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008686 vk_testing::Buffer dstBuffer;
8687 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008688
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008689 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008691 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008692}
8693
Karl Schultz6addd812016-02-02 17:17:23 -07008694TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008695 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8697 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008698
8699 ASSERT_NO_FATAL_FAILURE(InitState());
8700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008701
Tony Barbour552f6c02016-12-21 14:34:07 -07008702 m_commandBuffer->BeginCommandBuffer();
8703 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008704
8705 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008706 vk_testing::Buffer dstBuffer;
8707 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008708
Karl Schultz6addd812016-02-02 17:17:23 -07008709 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008710 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8711 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8712 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008713
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008714 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008715}
8716
Karl Schultz6addd812016-02-02 17:17:23 -07008717TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008718 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8720 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008721
8722 ASSERT_NO_FATAL_FAILURE(InitState());
8723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008724
Tony Barbour552f6c02016-12-21 14:34:07 -07008725 m_commandBuffer->BeginCommandBuffer();
8726 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008727
Michael Lentine0a369f62016-02-03 16:51:46 -06008728 VkClearColorValue clear_color;
8729 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008730 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8731 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8732 const int32_t tex_width = 32;
8733 const int32_t tex_height = 32;
8734 VkImageCreateInfo image_create_info = {};
8735 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8736 image_create_info.pNext = NULL;
8737 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8738 image_create_info.format = tex_format;
8739 image_create_info.extent.width = tex_width;
8740 image_create_info.extent.height = tex_height;
8741 image_create_info.extent.depth = 1;
8742 image_create_info.mipLevels = 1;
8743 image_create_info.arrayLayers = 1;
8744 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8745 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
8746 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008747
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008748 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008751 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008752
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07008753 m_errorMonitor->SetUnexpectedError("image must have been created with VK_IMAGE_USAGE_TRANSFER_DST_BIT usage flag");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008754 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008755
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008756 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757}
8758
Karl Schultz6addd812016-02-02 17:17:23 -07008759TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8762 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763
8764 ASSERT_NO_FATAL_FAILURE(InitState());
8765 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008766
Tony Barbour552f6c02016-12-21 14:34:07 -07008767 m_commandBuffer->BeginCommandBuffer();
8768 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008769
8770 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008771 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008772 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8773 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8774 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
8775 image_create_info.extent.width = 64;
8776 image_create_info.extent.height = 64;
8777 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8778 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008779
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008780 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008781 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008783 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008784
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008785 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8786 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008788 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008789}
8790
Karl Schultz6addd812016-02-02 17:17:23 -07008791TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008792 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008793 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008794
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008795 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8796 "vkCmdClearAttachments(): This call "
8797 "must be issued inside an active "
8798 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008799
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008800 ASSERT_NO_FATAL_FAILURE(InitState());
8801 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008802
8803 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008804 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008805 ASSERT_VK_SUCCESS(err);
8806
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008807 VkClearAttachment color_attachment;
8808 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8809 color_attachment.clearValue.color.float32[0] = 0;
8810 color_attachment.clearValue.color.float32[1] = 0;
8811 color_attachment.clearValue.color.float32[2] = 0;
8812 color_attachment.clearValue.color.float32[3] = 0;
8813 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008814 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008815 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008816
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008817 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008818}
8819
Chris Forbes3b97e932016-09-07 11:29:24 +12008820TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008821 TEST_DESCRIPTION(
8822 "Test that an error is produced when CmdNextSubpass is "
8823 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008824
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8826 "vkCmdNextSubpass(): Attempted to advance "
8827 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008828
8829 ASSERT_NO_FATAL_FAILURE(InitState());
8830 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8831
Tony Barbour552f6c02016-12-21 14:34:07 -07008832 m_commandBuffer->BeginCommandBuffer();
8833 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008834
8835 // error here.
8836 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8837 m_errorMonitor->VerifyFound();
8838
Tony Barbour552f6c02016-12-21 14:34:07 -07008839 m_commandBuffer->EndRenderPass();
8840 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008841}
8842
Chris Forbes6d624702016-09-07 13:57:05 +12008843TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008844 TEST_DESCRIPTION(
8845 "Test that an error is produced when CmdEndRenderPass is "
8846 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008847
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008848 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8849 "vkCmdEndRenderPass(): Called before reaching "
8850 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008851
8852 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008853 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8854 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008857
8858 VkRenderPass rp;
8859 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8860 ASSERT_VK_SUCCESS(err);
8861
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008862 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008863
8864 VkFramebuffer fb;
8865 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8866 ASSERT_VK_SUCCESS(err);
8867
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008868 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008869
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008870 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 +12008871
8872 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8873
8874 // Error here.
8875 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8876 m_errorMonitor->VerifyFound();
8877
8878 // Clean up.
8879 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8880 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8881}
8882
Karl Schultz9e66a292016-04-21 15:57:51 -06008883TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8884 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008885 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8886 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008887
8888 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008889 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008890
8891 VkBufferMemoryBarrier buf_barrier = {};
8892 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8893 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8894 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8895 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8896 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8897 buf_barrier.buffer = VK_NULL_HANDLE;
8898 buf_barrier.offset = 0;
8899 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008900 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8901 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008902
8903 m_errorMonitor->VerifyFound();
8904}
8905
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008906TEST_F(VkLayerTest, InvalidBarriers) {
8907 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8908
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008910
8911 ASSERT_NO_FATAL_FAILURE(InitState());
8912 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8913
8914 VkMemoryBarrier mem_barrier = {};
8915 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8916 mem_barrier.pNext = NULL;
8917 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8918 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008919 m_commandBuffer->BeginCommandBuffer();
8920 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008921 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008922 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008923 &mem_barrier, 0, nullptr, 0, nullptr);
8924 m_errorMonitor->VerifyFound();
8925
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008926 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008927 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008928 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 -06008929 ASSERT_TRUE(image.initialized());
8930 VkImageMemoryBarrier img_barrier = {};
8931 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8932 img_barrier.pNext = NULL;
8933 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8934 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8935 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8936 // New layout can't be UNDEFINED
8937 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8938 img_barrier.image = image.handle();
8939 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8940 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8941 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8942 img_barrier.subresourceRange.baseArrayLayer = 0;
8943 img_barrier.subresourceRange.baseMipLevel = 0;
8944 img_barrier.subresourceRange.layerCount = 1;
8945 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008946 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8947 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008948 m_errorMonitor->VerifyFound();
8949 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8950
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8952 "Subresource must have the sum of the "
8953 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008954 // baseArrayLayer + layerCount must be <= image's arrayLayers
8955 img_barrier.subresourceRange.baseArrayLayer = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008956 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8957 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008958 m_errorMonitor->VerifyFound();
8959 img_barrier.subresourceRange.baseArrayLayer = 0;
8960
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008962 // baseMipLevel + levelCount must be <= image's mipLevels
8963 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008964 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8965 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008966 m_errorMonitor->VerifyFound();
8967 img_barrier.subresourceRange.baseMipLevel = 0;
8968
Mike Weiblen7053aa32017-01-25 15:21:10 -07008969 // levelCount must be non-zero.
8970 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8971 img_barrier.subresourceRange.levelCount = 0;
8972 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8973 nullptr, 0, nullptr, 1, &img_barrier);
8974 m_errorMonitor->VerifyFound();
8975 img_barrier.subresourceRange.levelCount = 1;
8976
8977 // layerCount must be non-zero.
8978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8979 img_barrier.subresourceRange.layerCount = 0;
8980 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8981 nullptr, 0, nullptr, 1, &img_barrier);
8982 m_errorMonitor->VerifyFound();
8983 img_barrier.subresourceRange.layerCount = 1;
8984
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008985 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 -06008986 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008987 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8988 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008989 VkBufferMemoryBarrier buf_barrier = {};
8990 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8991 buf_barrier.pNext = NULL;
8992 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8993 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8994 buf_barrier.buffer = buffer.handle();
8995 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8996 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8997 buf_barrier.offset = 0;
8998 buf_barrier.size = VK_WHOLE_SIZE;
8999 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009000 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9001 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009002 m_errorMonitor->VerifyFound();
9003 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9004
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009006 buf_barrier.offset = 257;
9007 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009008 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9009 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009010 m_errorMonitor->VerifyFound();
9011 buf_barrier.offset = 0;
9012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009014 buf_barrier.size = 257;
9015 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009016 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9017 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009018 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009019
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009020 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009021 m_errorMonitor->SetDesiredFailureMsg(
9022 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009023 "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 -06009024 VkDepthStencilObj ds_image(m_device);
9025 ds_image.Init(m_device, 128, 128, VK_FORMAT_D24_UNORM_S8_UINT);
9026 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009027 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9028 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009029 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009030
9031 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009032 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009033 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9034 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009035 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009036
9037 // Having anything other than DEPTH or STENCIL is an error
9038 m_errorMonitor->SetDesiredFailureMsg(
9039 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9040 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9041 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9042 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9043 nullptr, 0, nullptr, 1, &img_barrier);
9044 m_errorMonitor->VerifyFound();
9045
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009046 // Now test depth-only
9047 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009048 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9049 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009050 VkDepthStencilObj d_image(m_device);
9051 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9052 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009053 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009054 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009055 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009056
9057 // DEPTH bit must be set
9058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9059 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009060 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009061 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9062 0, nullptr, 0, nullptr, 1, &img_barrier);
9063 m_errorMonitor->VerifyFound();
9064
9065 // No bits other than DEPTH may be set
9066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9067 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9068 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009069 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9070 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009071 m_errorMonitor->VerifyFound();
9072 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009073
9074 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009075 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9076 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009077 VkDepthStencilObj s_image(m_device);
9078 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9079 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009080 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009081 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009082 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009083 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9085 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009086 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009087 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9088 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009089 m_errorMonitor->VerifyFound();
9090 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009091
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009092 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009093 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009094 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 -06009095 ASSERT_TRUE(c_image.initialized());
9096 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9097 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9098 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009099
9100 // COLOR bit must be set
9101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9102 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009103 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009104 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9105 nullptr, 0, nullptr, 1, &img_barrier);
9106 m_errorMonitor->VerifyFound();
9107
9108 // No bits other than COLOR may be set
9109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9110 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9111 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009112 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9113 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009114 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009115
9116 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9117
9118 // Create command pool with incompatible queueflags
9119 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9120 uint32_t queue_family_index = UINT32_MAX;
9121 for (uint32_t i = 0; i < queue_props.size(); i++) {
9122 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9123 queue_family_index = i;
9124 break;
9125 }
9126 }
9127 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009128 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009129 return;
9130 }
9131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9132
9133 VkCommandPool command_pool;
9134 VkCommandPoolCreateInfo pool_create_info{};
9135 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9136 pool_create_info.queueFamilyIndex = queue_family_index;
9137 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9138 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9139
9140 // Allocate a command buffer
9141 VkCommandBuffer bad_command_buffer;
9142 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9143 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9144 command_buffer_allocate_info.commandPool = command_pool;
9145 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9146 command_buffer_allocate_info.commandBufferCount = 1;
9147 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9148
9149 VkCommandBufferBeginInfo cbbi = {};
9150 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9151 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9152 buf_barrier.offset = 0;
9153 buf_barrier.size = VK_WHOLE_SIZE;
9154 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9155 &buf_barrier, 0, nullptr);
9156 m_errorMonitor->VerifyFound();
9157
9158 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9159 vkEndCommandBuffer(bad_command_buffer);
9160 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009161 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009162 return;
9163 }
9164 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9165 VkEvent event;
9166 VkEventCreateInfo event_create_info{};
9167 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9168 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9169 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9170 nullptr, 0, nullptr);
9171 m_errorMonitor->VerifyFound();
9172
9173 vkEndCommandBuffer(bad_command_buffer);
9174 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009175}
9176
Tony Barbour18ba25c2016-09-29 13:42:40 -06009177TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9178 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9179
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009181 ASSERT_NO_FATAL_FAILURE(InitState());
9182 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009183 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 -06009184 ASSERT_TRUE(image.initialized());
9185
9186 VkImageMemoryBarrier barrier = {};
9187 VkImageSubresourceRange range;
9188 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9189 barrier.srcAccessMask = 0;
9190 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9191 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9192 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9193 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9194 barrier.image = image.handle();
9195 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9196 range.baseMipLevel = 0;
9197 range.levelCount = 1;
9198 range.baseArrayLayer = 0;
9199 range.layerCount = 1;
9200 barrier.subresourceRange = range;
9201 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9202 cmdbuf.BeginCommandBuffer();
9203 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9204 &barrier);
9205 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9206 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9207 barrier.srcAccessMask = 0;
9208 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9209 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9210 &barrier);
9211
9212 m_errorMonitor->VerifyFound();
9213}
9214
Karl Schultz6addd812016-02-02 17:17:23 -07009215TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009216 // Bind a BeginRenderPass within an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07009217 VkResult err;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009218
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009220
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009221 ASSERT_NO_FATAL_FAILURE(InitState());
9222 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009223 uint32_t qfi = 0;
9224 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07009225 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9226 buffCI.size = 1024;
9227 buffCI.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9228 buffCI.queueFamilyIndexCount = 1;
9229 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009230
9231 VkBuffer ib;
Chia-I Wuf7458c52015-10-26 21:10:41 +08009232 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009233 ASSERT_VK_SUCCESS(err);
9234
Tony Barbour552f6c02016-12-21 14:34:07 -07009235 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009236 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07009237 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9238 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009239 // Should error before calling to driver so don't care about actual data
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009240 m_errorMonitor->SetUnexpectedError(
9241 "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 -06009242 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), ib, 7, VK_INDEX_TYPE_UINT16);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009244 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009245
Chia-I Wuf7458c52015-10-26 21:10:41 +08009246 vkDestroyBuffer(m_device->device(), ib, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009247}
9248
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009249TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9250 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9252 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9253 "of the indices specified when the device was created, via the "
9254 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009255
9256 ASSERT_NO_FATAL_FAILURE(InitState());
9257 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9258 VkBufferCreateInfo buffCI = {};
9259 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9260 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009261 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009262 buffCI.queueFamilyIndexCount = 1;
9263 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009264 uint32_t qfi[2];
9265 qfi[0] = 777;
9266
9267 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009268 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009269
9270 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009271 m_errorMonitor->SetUnexpectedError(
9272 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009273 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9274
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009275 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009276
9277 if (m_device->queue_props.size() > 2) {
9278 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9279
9280 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9281 buffCI.queueFamilyIndexCount = 2;
9282 qfi[0] = 1;
9283 qfi[1] = 2;
9284 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9285 VkDeviceMemory mem;
9286 VkMemoryRequirements mem_reqs;
9287 vkGetBufferMemoryRequirements(m_device->device(), ib, &mem_reqs);
9288
9289 VkMemoryAllocateInfo alloc_info = {};
9290 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9291 alloc_info.allocationSize = 1024;
9292 bool pass = false;
9293 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9294 if (!pass) {
9295 vkDestroyBuffer(m_device->device(), ib, NULL);
9296 return;
9297 }
9298 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
9299 vkBindBufferMemory(m_device->device(), ib, mem, 0);
9300
9301 m_commandBuffer->begin();
9302 vkCmdFillBuffer(m_commandBuffer->handle(), ib, 0, 16, 5);
9303 m_commandBuffer->end();
9304 QueueCommandBuffer(false);
9305 m_errorMonitor->VerifyFound();
9306 }
9307
Tony Barbourdf4c0042016-06-01 15:55:43 -06009308 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009309}
9310
Karl Schultz6addd812016-02-02 17:17:23 -07009311TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009312 TEST_DESCRIPTION(
9313 "Attempt vkCmdExecuteCommands with a primary command buffer"
9314 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009315
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009316 ASSERT_NO_FATAL_FAILURE(InitState());
9317 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009318
Chris Forbesf29a84f2016-10-06 18:39:28 +13009319 // An empty primary command buffer
9320 VkCommandBufferObj cb(m_device, m_commandPool);
9321 cb.BeginCommandBuffer();
9322 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009323
Chris Forbesf29a84f2016-10-06 18:39:28 +13009324 m_commandBuffer->BeginCommandBuffer();
9325 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9326 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009327
Chris Forbesf29a84f2016-10-06 18:39:28 +13009328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9329 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009330 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009331
9332 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009333}
9334
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009335TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009336 TEST_DESCRIPTION(
9337 "Attempt to update descriptor sets for images and buffers "
9338 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009339 VkResult err;
9340
9341 ASSERT_NO_FATAL_FAILURE(InitState());
9342 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9343 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9344 ds_type_count[i].type = VkDescriptorType(i);
9345 ds_type_count[i].descriptorCount = 1;
9346 }
9347 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9348 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9349 ds_pool_ci.pNext = NULL;
9350 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9351 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9352 ds_pool_ci.pPoolSizes = ds_type_count;
9353
9354 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009355 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009356 ASSERT_VK_SUCCESS(err);
9357
9358 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009359 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009360 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9361 dsl_binding[i].binding = 0;
9362 dsl_binding[i].descriptorType = VkDescriptorType(i);
9363 dsl_binding[i].descriptorCount = 1;
9364 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9365 dsl_binding[i].pImmutableSamplers = NULL;
9366 }
9367
9368 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9369 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9370 ds_layout_ci.pNext = NULL;
9371 ds_layout_ci.bindingCount = 1;
9372 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9373 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9374 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009375 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009376 ASSERT_VK_SUCCESS(err);
9377 }
9378 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9379 VkDescriptorSetAllocateInfo alloc_info = {};
9380 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9381 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9382 alloc_info.descriptorPool = ds_pool;
9383 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009384 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009385 ASSERT_VK_SUCCESS(err);
9386
9387 // Create a buffer & bufferView to be used for invalid updates
9388 VkBufferCreateInfo buff_ci = {};
9389 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009390 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009391 buff_ci.size = 256;
9392 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009393 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009394 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9395 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009396
9397 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9398 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9399 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9400 ASSERT_VK_SUCCESS(err);
9401
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009402 VkMemoryRequirements mem_reqs;
9403 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9404 VkMemoryAllocateInfo mem_alloc_info = {};
9405 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9406 mem_alloc_info.pNext = NULL;
9407 mem_alloc_info.memoryTypeIndex = 0;
9408 mem_alloc_info.allocationSize = mem_reqs.size;
9409 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9410 if (!pass) {
9411 vkDestroyBuffer(m_device->device(), buffer, NULL);
9412 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9413 return;
9414 }
9415 VkDeviceMemory mem;
9416 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9417 ASSERT_VK_SUCCESS(err);
9418 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9419 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009420
9421 VkBufferViewCreateInfo buff_view_ci = {};
9422 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9423 buff_view_ci.buffer = buffer;
9424 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9425 buff_view_ci.range = VK_WHOLE_SIZE;
9426 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009427 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009428 ASSERT_VK_SUCCESS(err);
9429
Tony Barbour415497c2017-01-24 10:06:09 -07009430 // Now get resources / view for storage_texel_buffer
9431 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9432 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9433 if (!pass) {
9434 vkDestroyBuffer(m_device->device(), buffer, NULL);
9435 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9436 vkFreeMemory(m_device->device(), mem, NULL);
9437 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9438 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9439 return;
9440 }
9441 VkDeviceMemory storage_texel_buffer_mem;
9442 VkBufferView storage_texel_buffer_view;
9443 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9444 ASSERT_VK_SUCCESS(err);
9445 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9446 ASSERT_VK_SUCCESS(err);
9447 buff_view_ci.buffer = storage_texel_buffer;
9448 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9449 ASSERT_VK_SUCCESS(err);
9450
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009451 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009452 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009453 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009454 image_ci.format = VK_FORMAT_UNDEFINED;
9455 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9456 VkFormat format = static_cast<VkFormat>(f);
9457 VkFormatProperties fProps = m_device->format_properties(format);
9458 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9459 image_ci.format = format;
9460 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9461 break;
9462 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9463 image_ci.format = format;
9464 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9465 break;
9466 }
9467 }
9468 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9469 return;
9470 }
9471
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009472 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9473 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009474 image_ci.extent.width = 64;
9475 image_ci.extent.height = 64;
9476 image_ci.extent.depth = 1;
9477 image_ci.mipLevels = 1;
9478 image_ci.arrayLayers = 1;
9479 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009480 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009481 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009482 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9483 VkImage image;
9484 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9485 ASSERT_VK_SUCCESS(err);
9486 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009487 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009488
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009489 VkMemoryAllocateInfo mem_alloc = {};
9490 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9491 mem_alloc.pNext = NULL;
9492 mem_alloc.allocationSize = 0;
9493 mem_alloc.memoryTypeIndex = 0;
9494 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9495 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009496 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009497 ASSERT_TRUE(pass);
9498 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9499 ASSERT_VK_SUCCESS(err);
9500 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9501 ASSERT_VK_SUCCESS(err);
9502 // Now create view for image
9503 VkImageViewCreateInfo image_view_ci = {};
9504 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9505 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009506 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009507 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9508 image_view_ci.subresourceRange.layerCount = 1;
9509 image_view_ci.subresourceRange.baseArrayLayer = 0;
9510 image_view_ci.subresourceRange.levelCount = 1;
9511 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9512 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009513 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009514 ASSERT_VK_SUCCESS(err);
9515
9516 VkDescriptorBufferInfo buff_info = {};
9517 buff_info.buffer = buffer;
9518 VkDescriptorImageInfo img_info = {};
9519 img_info.imageView = image_view;
9520 VkWriteDescriptorSet descriptor_write = {};
9521 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9522 descriptor_write.dstBinding = 0;
9523 descriptor_write.descriptorCount = 1;
9524 descriptor_write.pTexelBufferView = &buff_view;
9525 descriptor_write.pBufferInfo = &buff_info;
9526 descriptor_write.pImageInfo = &img_info;
9527
9528 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009529 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009530 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9531 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9532 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9533 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9534 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9535 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9536 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9537 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9538 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9539 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9540 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009541 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009542 // Start loop at 1 as SAMPLER desc type has no usage bit error
9543 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009544 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9545 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9546 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9547 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009548 descriptor_write.descriptorType = VkDescriptorType(i);
9549 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009551
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009552 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009553
9554 m_errorMonitor->VerifyFound();
9555 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009556 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9557 descriptor_write.pTexelBufferView = &buff_view;
9558 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009559 }
Tony Barbour415497c2017-01-24 10:06:09 -07009560
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009561 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9562 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009563 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009564 vkDestroyImageView(m_device->device(), image_view, NULL);
9565 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009566 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009567 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009568 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009569 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009570 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009571 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9572}
9573
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009574TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009575 TEST_DESCRIPTION(
9576 "Attempt to update buffer descriptor set that has incorrect "
9577 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9578 "1. offset value greater than buffer size\n"
9579 "2. range value of 0\n"
9580 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009581 VkResult err;
9582
9583 ASSERT_NO_FATAL_FAILURE(InitState());
9584 VkDescriptorPoolSize ds_type_count = {};
9585 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9586 ds_type_count.descriptorCount = 1;
9587
9588 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9589 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9590 ds_pool_ci.pNext = NULL;
9591 ds_pool_ci.maxSets = 1;
9592 ds_pool_ci.poolSizeCount = 1;
9593 ds_pool_ci.pPoolSizes = &ds_type_count;
9594
9595 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009596 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009597 ASSERT_VK_SUCCESS(err);
9598
9599 // Create layout with single uniform buffer descriptor
9600 VkDescriptorSetLayoutBinding dsl_binding = {};
9601 dsl_binding.binding = 0;
9602 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9603 dsl_binding.descriptorCount = 1;
9604 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9605 dsl_binding.pImmutableSamplers = NULL;
9606
9607 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9608 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9609 ds_layout_ci.pNext = NULL;
9610 ds_layout_ci.bindingCount = 1;
9611 ds_layout_ci.pBindings = &dsl_binding;
9612 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009613 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009614 ASSERT_VK_SUCCESS(err);
9615
9616 VkDescriptorSet descriptor_set = {};
9617 VkDescriptorSetAllocateInfo alloc_info = {};
9618 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9619 alloc_info.descriptorSetCount = 1;
9620 alloc_info.descriptorPool = ds_pool;
9621 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009622 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009623 ASSERT_VK_SUCCESS(err);
9624
9625 // Create a buffer to be used for invalid updates
9626 VkBufferCreateInfo buff_ci = {};
9627 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9628 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9629 buff_ci.size = 256;
9630 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9631 VkBuffer buffer;
9632 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9633 ASSERT_VK_SUCCESS(err);
9634 // Have to bind memory to buffer before descriptor update
9635 VkMemoryAllocateInfo mem_alloc = {};
9636 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9637 mem_alloc.pNext = NULL;
9638 mem_alloc.allocationSize = 256;
9639 mem_alloc.memoryTypeIndex = 0;
9640
9641 VkMemoryRequirements mem_reqs;
9642 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009643 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009644 if (!pass) {
9645 vkDestroyBuffer(m_device->device(), buffer, NULL);
9646 return;
9647 }
9648
9649 VkDeviceMemory mem;
9650 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9651 ASSERT_VK_SUCCESS(err);
9652 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9653 ASSERT_VK_SUCCESS(err);
9654
9655 VkDescriptorBufferInfo buff_info = {};
9656 buff_info.buffer = buffer;
9657 // First make offset 1 larger than buffer size
9658 buff_info.offset = 257;
9659 buff_info.range = VK_WHOLE_SIZE;
9660 VkWriteDescriptorSet descriptor_write = {};
9661 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9662 descriptor_write.dstBinding = 0;
9663 descriptor_write.descriptorCount = 1;
9664 descriptor_write.pTexelBufferView = nullptr;
9665 descriptor_write.pBufferInfo = &buff_info;
9666 descriptor_write.pImageInfo = nullptr;
9667
9668 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9669 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009671
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009672 m_errorMonitor->SetUnexpectedError(
9673 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9674 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009675 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9676
9677 m_errorMonitor->VerifyFound();
9678 // Now cause error due to range of 0
9679 buff_info.offset = 0;
9680 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009682
9683 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9684
9685 m_errorMonitor->VerifyFound();
9686 // Now cause error due to range exceeding buffer size - offset
9687 buff_info.offset = 128;
9688 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009690
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009691 m_errorMonitor->SetUnexpectedError(
9692 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9693 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009694 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9695
9696 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009697 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009698 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9699 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009700 m_errorMonitor->SetUnexpectedError(
9701 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009702 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9703 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9704}
9705
Tobin Ehlis845887e2017-02-02 19:01:44 -07009706TEST_F(VkLayerTest, DSBufferLimitErrors) {
9707 TEST_DESCRIPTION(
9708 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9709 "Test cases include:\n"
9710 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9711 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9712 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9713 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9714 VkResult err;
9715
9716 ASSERT_NO_FATAL_FAILURE(InitState());
9717 VkDescriptorPoolSize ds_type_count[2] = {};
9718 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9719 ds_type_count[0].descriptorCount = 1;
9720 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9721 ds_type_count[1].descriptorCount = 1;
9722
9723 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9724 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9725 ds_pool_ci.pNext = NULL;
9726 ds_pool_ci.maxSets = 1;
9727 ds_pool_ci.poolSizeCount = 2;
9728 ds_pool_ci.pPoolSizes = ds_type_count;
9729
9730 VkDescriptorPool ds_pool;
9731 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9732 ASSERT_VK_SUCCESS(err);
9733
9734 // Create layout with single uniform buffer & single storage buffer descriptor
9735 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9736 dsl_binding[0].binding = 0;
9737 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9738 dsl_binding[0].descriptorCount = 1;
9739 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9740 dsl_binding[0].pImmutableSamplers = NULL;
9741 dsl_binding[1].binding = 1;
9742 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9743 dsl_binding[1].descriptorCount = 1;
9744 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9745 dsl_binding[1].pImmutableSamplers = NULL;
9746
9747 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9748 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9749 ds_layout_ci.pNext = NULL;
9750 ds_layout_ci.bindingCount = 2;
9751 ds_layout_ci.pBindings = dsl_binding;
9752 VkDescriptorSetLayout ds_layout;
9753 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9754 ASSERT_VK_SUCCESS(err);
9755
9756 VkDescriptorSet descriptor_set = {};
9757 VkDescriptorSetAllocateInfo alloc_info = {};
9758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9759 alloc_info.descriptorSetCount = 1;
9760 alloc_info.descriptorPool = ds_pool;
9761 alloc_info.pSetLayouts = &ds_layout;
9762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9763 ASSERT_VK_SUCCESS(err);
9764
9765 // Create a buffer to be used for invalid updates
9766 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9767 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9768 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9769 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9770 VkBufferCreateInfo ub_ci = {};
9771 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9772 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9773 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9774 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9775 VkBuffer uniform_buffer;
9776 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9777 ASSERT_VK_SUCCESS(err);
9778 VkBufferCreateInfo sb_ci = {};
9779 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9780 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9781 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9782 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9783 VkBuffer storage_buffer;
9784 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9785 ASSERT_VK_SUCCESS(err);
9786 // Have to bind memory to buffer before descriptor update
9787 VkMemoryAllocateInfo mem_alloc = {};
9788 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9789 mem_alloc.pNext = NULL;
9790 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9791 mem_alloc.memoryTypeIndex = 0;
9792
9793 VkMemoryRequirements mem_reqs;
9794 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &mem_reqs);
9795 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9796 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &mem_reqs);
9797 pass &= m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
9798 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009799 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009800 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009801 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9802 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009803 return;
9804 }
9805
9806 VkDeviceMemory mem;
9807 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009808 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009809 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009810 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9811 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9812 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9813 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9814 return;
9815 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009816 ASSERT_VK_SUCCESS(err);
9817 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9818 ASSERT_VK_SUCCESS(err);
9819 auto sb_offset = ub_ci.size + 1024;
9820 // Verify offset alignment, I know there's a bit trick to do this but it escapes me
9821 sb_offset = (sb_offset % mem_reqs.alignment) ? sb_offset - (sb_offset % mem_reqs.alignment) : sb_offset;
9822 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9823 ASSERT_VK_SUCCESS(err);
9824
9825 VkDescriptorBufferInfo buff_info = {};
9826 buff_info.buffer = uniform_buffer;
9827 buff_info.range = ub_ci.size; // This will exceed limit
9828 VkWriteDescriptorSet descriptor_write = {};
9829 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9830 descriptor_write.dstBinding = 0;
9831 descriptor_write.descriptorCount = 1;
9832 descriptor_write.pTexelBufferView = nullptr;
9833 descriptor_write.pBufferInfo = &buff_info;
9834 descriptor_write.pImageInfo = nullptr;
9835
9836 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9837 descriptor_write.dstSet = descriptor_set;
9838 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9839 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9840 m_errorMonitor->VerifyFound();
9841
9842 // Reduce size of range to acceptable limit & cause offset error
9843 buff_info.range = max_ub_range;
9844 buff_info.offset = min_ub_align - 1;
9845 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9847 m_errorMonitor->VerifyFound();
9848
9849 // Now break storage updates
9850 buff_info.buffer = storage_buffer;
9851 buff_info.range = sb_ci.size; // This will exceed limit
9852 buff_info.offset = 0; // Reset offset for this update
9853
9854 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9855 descriptor_write.dstBinding = 1;
9856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9857 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9858 m_errorMonitor->VerifyFound();
9859
9860 // Reduce size of range to acceptable limit & cause offset error
9861 buff_info.range = max_sb_range;
9862 buff_info.offset = min_sb_align - 1;
9863 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9864 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9865 m_errorMonitor->VerifyFound();
9866
9867 vkFreeMemory(m_device->device(), mem, NULL);
9868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9869 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9870 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9871 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9872}
9873
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009874TEST_F(VkLayerTest, DSAspectBitsErrors) {
9875 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9876 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009877 TEST_DESCRIPTION(
9878 "Attempt to update descriptor sets for images "
9879 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009880 VkResult err;
9881
9882 ASSERT_NO_FATAL_FAILURE(InitState());
9883 VkDescriptorPoolSize ds_type_count = {};
9884 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9885 ds_type_count.descriptorCount = 1;
9886
9887 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9888 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9889 ds_pool_ci.pNext = NULL;
9890 ds_pool_ci.maxSets = 5;
9891 ds_pool_ci.poolSizeCount = 1;
9892 ds_pool_ci.pPoolSizes = &ds_type_count;
9893
9894 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009895 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009896 ASSERT_VK_SUCCESS(err);
9897
9898 VkDescriptorSetLayoutBinding dsl_binding = {};
9899 dsl_binding.binding = 0;
9900 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9901 dsl_binding.descriptorCount = 1;
9902 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9903 dsl_binding.pImmutableSamplers = NULL;
9904
9905 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9906 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9907 ds_layout_ci.pNext = NULL;
9908 ds_layout_ci.bindingCount = 1;
9909 ds_layout_ci.pBindings = &dsl_binding;
9910 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009911 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009912 ASSERT_VK_SUCCESS(err);
9913
9914 VkDescriptorSet descriptor_set = {};
9915 VkDescriptorSetAllocateInfo alloc_info = {};
9916 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9917 alloc_info.descriptorSetCount = 1;
9918 alloc_info.descriptorPool = ds_pool;
9919 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009920 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009921 ASSERT_VK_SUCCESS(err);
9922
9923 // Create an image to be used for invalid updates
9924 VkImageCreateInfo image_ci = {};
9925 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9926 image_ci.imageType = VK_IMAGE_TYPE_2D;
9927 image_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9928 image_ci.extent.width = 64;
9929 image_ci.extent.height = 64;
9930 image_ci.extent.depth = 1;
9931 image_ci.mipLevels = 1;
9932 image_ci.arrayLayers = 1;
9933 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
9934 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9935 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9936 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9937 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9938 VkImage image;
9939 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9940 ASSERT_VK_SUCCESS(err);
9941 // Bind memory to image
9942 VkMemoryRequirements mem_reqs;
9943 VkDeviceMemory image_mem;
9944 bool pass;
9945 VkMemoryAllocateInfo mem_alloc = {};
9946 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9947 mem_alloc.pNext = NULL;
9948 mem_alloc.allocationSize = 0;
9949 mem_alloc.memoryTypeIndex = 0;
9950 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9951 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009952 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009953 ASSERT_TRUE(pass);
9954 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9955 ASSERT_VK_SUCCESS(err);
9956 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9957 ASSERT_VK_SUCCESS(err);
9958 // Now create view for image
9959 VkImageViewCreateInfo image_view_ci = {};
9960 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9961 image_view_ci.image = image;
9962 image_view_ci.format = VK_FORMAT_D24_UNORM_S8_UINT;
9963 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9964 image_view_ci.subresourceRange.layerCount = 1;
9965 image_view_ci.subresourceRange.baseArrayLayer = 0;
9966 image_view_ci.subresourceRange.levelCount = 1;
9967 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009968 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009969
9970 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009971 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009972 ASSERT_VK_SUCCESS(err);
9973
9974 VkDescriptorImageInfo img_info = {};
9975 img_info.imageView = image_view;
9976 VkWriteDescriptorSet descriptor_write = {};
9977 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9978 descriptor_write.dstBinding = 0;
9979 descriptor_write.descriptorCount = 1;
9980 descriptor_write.pTexelBufferView = NULL;
9981 descriptor_write.pBufferInfo = NULL;
9982 descriptor_write.pImageInfo = &img_info;
9983 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9984 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009985 const char *error_msg =
9986 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
9987 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009989
9990 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9991
9992 m_errorMonitor->VerifyFound();
9993 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9994 vkDestroyImage(m_device->device(), image, NULL);
9995 vkFreeMemory(m_device->device(), image_mem, NULL);
9996 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009997 m_errorMonitor->SetUnexpectedError(
9998 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009999 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10000 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10001}
10002
Karl Schultz6addd812016-02-02 17:17:23 -070010003TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010004 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010005 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010006
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10008 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10009 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010010
Tobin Ehlis3b780662015-05-28 12:11:26 -060010011 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010012 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010013 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010014 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10015 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010016
10017 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010018 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10019 ds_pool_ci.pNext = NULL;
10020 ds_pool_ci.maxSets = 1;
10021 ds_pool_ci.poolSizeCount = 1;
10022 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010023
Tobin Ehlis3b780662015-05-28 12:11:26 -060010024 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010025 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010026 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010027 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010028 dsl_binding.binding = 0;
10029 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10030 dsl_binding.descriptorCount = 1;
10031 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10032 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010033
Tony Barboureb254902015-07-15 12:50:33 -060010034 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010035 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10036 ds_layout_ci.pNext = NULL;
10037 ds_layout_ci.bindingCount = 1;
10038 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010039
Tobin Ehlis3b780662015-05-28 12:11:26 -060010040 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010041 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010042 ASSERT_VK_SUCCESS(err);
10043
10044 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010045 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010046 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010047 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010048 alloc_info.descriptorPool = ds_pool;
10049 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010050 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010051 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010052
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010053 VkSamplerCreateInfo sampler_ci = {};
10054 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10055 sampler_ci.pNext = NULL;
10056 sampler_ci.magFilter = VK_FILTER_NEAREST;
10057 sampler_ci.minFilter = VK_FILTER_NEAREST;
10058 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10059 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10060 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10061 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10062 sampler_ci.mipLodBias = 1.0;
10063 sampler_ci.anisotropyEnable = VK_FALSE;
10064 sampler_ci.maxAnisotropy = 1;
10065 sampler_ci.compareEnable = VK_FALSE;
10066 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10067 sampler_ci.minLod = 1.0;
10068 sampler_ci.maxLod = 1.0;
10069 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10070 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10071 VkSampler sampler;
10072 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10073 ASSERT_VK_SUCCESS(err);
10074
10075 VkDescriptorImageInfo info = {};
10076 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010077
10078 VkWriteDescriptorSet descriptor_write;
10079 memset(&descriptor_write, 0, sizeof(descriptor_write));
10080 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010081 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010082 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010083 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010084 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010085 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010086
10087 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10088
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010089 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010090
Chia-I Wuf7458c52015-10-26 21:10:41 +080010091 vkDestroySampler(m_device->device(), sampler, NULL);
10092 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10093 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010094}
10095
Karl Schultz6addd812016-02-02 17:17:23 -070010096TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010097 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010098 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010099
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010100 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010101
Tobin Ehlis3b780662015-05-28 12:11:26 -060010102 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010103 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010104 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010105 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10106 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010107
10108 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010109 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10110 ds_pool_ci.pNext = NULL;
10111 ds_pool_ci.maxSets = 1;
10112 ds_pool_ci.poolSizeCount = 1;
10113 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010114
Tobin Ehlis3b780662015-05-28 12:11:26 -060010115 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010116 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010117 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010118
Tony Barboureb254902015-07-15 12:50:33 -060010119 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010120 dsl_binding.binding = 0;
10121 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10122 dsl_binding.descriptorCount = 1;
10123 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10124 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010125
10126 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010127 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10128 ds_layout_ci.pNext = NULL;
10129 ds_layout_ci.bindingCount = 1;
10130 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010131
Tobin Ehlis3b780662015-05-28 12:11:26 -060010132 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010133 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010134 ASSERT_VK_SUCCESS(err);
10135
10136 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010137 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010138 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010139 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010140 alloc_info.descriptorPool = ds_pool;
10141 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010142 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010143 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010144
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010145 // Correctly update descriptor to avoid "NOT_UPDATED" error
10146 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010147 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010148 buff_info.offset = 0;
10149 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010150
10151 VkWriteDescriptorSet descriptor_write;
10152 memset(&descriptor_write, 0, sizeof(descriptor_write));
10153 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010154 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010155 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010156 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010157 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10158 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010159
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010160 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010161 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10162
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010163 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010164
Chia-I Wuf7458c52015-10-26 21:10:41 +080010165 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10166 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010167}
10168
Karl Schultz6addd812016-02-02 17:17:23 -070010169TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010170 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010171 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010172
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010174
Tobin Ehlis3b780662015-05-28 12:11:26 -060010175 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010176 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010177 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010178 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10179 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010180
10181 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010182 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10183 ds_pool_ci.pNext = NULL;
10184 ds_pool_ci.maxSets = 1;
10185 ds_pool_ci.poolSizeCount = 1;
10186 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010187
Tobin Ehlis3b780662015-05-28 12:11:26 -060010188 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010189 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010190 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191
Tony Barboureb254902015-07-15 12:50:33 -060010192 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010193 dsl_binding.binding = 0;
10194 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10195 dsl_binding.descriptorCount = 1;
10196 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10197 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010198
10199 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010200 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10201 ds_layout_ci.pNext = NULL;
10202 ds_layout_ci.bindingCount = 1;
10203 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010204 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010205 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010206 ASSERT_VK_SUCCESS(err);
10207
10208 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010209 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010210 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010211 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010212 alloc_info.descriptorPool = ds_pool;
10213 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010214 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010215 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010216
Tony Barboureb254902015-07-15 12:50:33 -060010217 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010218 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10219 sampler_ci.pNext = NULL;
10220 sampler_ci.magFilter = VK_FILTER_NEAREST;
10221 sampler_ci.minFilter = VK_FILTER_NEAREST;
10222 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10223 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10224 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10225 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10226 sampler_ci.mipLodBias = 1.0;
10227 sampler_ci.anisotropyEnable = VK_FALSE;
10228 sampler_ci.maxAnisotropy = 1;
10229 sampler_ci.compareEnable = VK_FALSE;
10230 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10231 sampler_ci.minLod = 1.0;
10232 sampler_ci.maxLod = 1.0;
10233 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10234 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010235
Tobin Ehlis3b780662015-05-28 12:11:26 -060010236 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010237 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010238 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010239
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010240 VkDescriptorImageInfo info = {};
10241 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010242
10243 VkWriteDescriptorSet descriptor_write;
10244 memset(&descriptor_write, 0, sizeof(descriptor_write));
10245 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010246 descriptor_write.dstSet = descriptorSet;
10247 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010248 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010249 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010250 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010251 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010252
10253 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10254
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010255 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010256
Chia-I Wuf7458c52015-10-26 21:10:41 +080010257 vkDestroySampler(m_device->device(), sampler, NULL);
10258 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10259 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010260}
10261
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010262TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10263 // Create layout w/ empty binding and attempt to update it
10264 VkResult err;
10265
10266 ASSERT_NO_FATAL_FAILURE(InitState());
10267
10268 VkDescriptorPoolSize ds_type_count = {};
10269 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10270 ds_type_count.descriptorCount = 1;
10271
10272 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10273 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10274 ds_pool_ci.pNext = NULL;
10275 ds_pool_ci.maxSets = 1;
10276 ds_pool_ci.poolSizeCount = 1;
10277 ds_pool_ci.pPoolSizes = &ds_type_count;
10278
10279 VkDescriptorPool ds_pool;
10280 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10281 ASSERT_VK_SUCCESS(err);
10282
10283 VkDescriptorSetLayoutBinding dsl_binding = {};
10284 dsl_binding.binding = 0;
10285 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10286 dsl_binding.descriptorCount = 0;
10287 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10288 dsl_binding.pImmutableSamplers = NULL;
10289
10290 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10291 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10292 ds_layout_ci.pNext = NULL;
10293 ds_layout_ci.bindingCount = 1;
10294 ds_layout_ci.pBindings = &dsl_binding;
10295 VkDescriptorSetLayout ds_layout;
10296 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10297 ASSERT_VK_SUCCESS(err);
10298
10299 VkDescriptorSet descriptor_set;
10300 VkDescriptorSetAllocateInfo alloc_info = {};
10301 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10302 alloc_info.descriptorSetCount = 1;
10303 alloc_info.descriptorPool = ds_pool;
10304 alloc_info.pSetLayouts = &ds_layout;
10305 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10306 ASSERT_VK_SUCCESS(err);
10307
10308 VkSamplerCreateInfo sampler_ci = {};
10309 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10310 sampler_ci.magFilter = VK_FILTER_NEAREST;
10311 sampler_ci.minFilter = VK_FILTER_NEAREST;
10312 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10313 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10314 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10315 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10316 sampler_ci.mipLodBias = 1.0;
10317 sampler_ci.maxAnisotropy = 1;
10318 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10319 sampler_ci.minLod = 1.0;
10320 sampler_ci.maxLod = 1.0;
10321 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10322
10323 VkSampler sampler;
10324 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10325 ASSERT_VK_SUCCESS(err);
10326
10327 VkDescriptorImageInfo info = {};
10328 info.sampler = sampler;
10329
10330 VkWriteDescriptorSet descriptor_write;
10331 memset(&descriptor_write, 0, sizeof(descriptor_write));
10332 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10333 descriptor_write.dstSet = descriptor_set;
10334 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010335 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010336 // This is the wrong type, but empty binding error will be flagged first
10337 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10338 descriptor_write.pImageInfo = &info;
10339
10340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10341 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10342 m_errorMonitor->VerifyFound();
10343
10344 vkDestroySampler(m_device->device(), sampler, NULL);
10345 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10346 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10347}
10348
Karl Schultz6addd812016-02-02 17:17:23 -070010349TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10350 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10351 // types
10352 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010353
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010354 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 -060010355
Tobin Ehlis3b780662015-05-28 12:11:26 -060010356 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010357
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010358 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010359 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10360 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010361
10362 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010363 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10364 ds_pool_ci.pNext = NULL;
10365 ds_pool_ci.maxSets = 1;
10366 ds_pool_ci.poolSizeCount = 1;
10367 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010368
Tobin Ehlis3b780662015-05-28 12:11:26 -060010369 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010370 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010371 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010372 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010373 dsl_binding.binding = 0;
10374 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10375 dsl_binding.descriptorCount = 1;
10376 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10377 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010378
Tony Barboureb254902015-07-15 12:50:33 -060010379 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010380 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10381 ds_layout_ci.pNext = NULL;
10382 ds_layout_ci.bindingCount = 1;
10383 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010384
Tobin Ehlis3b780662015-05-28 12:11:26 -060010385 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010387 ASSERT_VK_SUCCESS(err);
10388
10389 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010390 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010391 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010392 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010393 alloc_info.descriptorPool = ds_pool;
10394 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010395 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010396 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010397
Tony Barboureb254902015-07-15 12:50:33 -060010398 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010399 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10400 sampler_ci.pNext = NULL;
10401 sampler_ci.magFilter = VK_FILTER_NEAREST;
10402 sampler_ci.minFilter = VK_FILTER_NEAREST;
10403 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10404 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10405 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10406 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10407 sampler_ci.mipLodBias = 1.0;
10408 sampler_ci.anisotropyEnable = VK_FALSE;
10409 sampler_ci.maxAnisotropy = 1;
10410 sampler_ci.compareEnable = VK_FALSE;
10411 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10412 sampler_ci.minLod = 1.0;
10413 sampler_ci.maxLod = 1.0;
10414 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10415 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010416 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010417 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010418 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010419
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010420 VkDescriptorImageInfo info = {};
10421 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010422
10423 VkWriteDescriptorSet descriptor_write;
10424 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010425 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010426 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010427 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010428 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010429 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010430 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010431
10432 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10433
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010434 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010435
Chia-I Wuf7458c52015-10-26 21:10:41 +080010436 vkDestroySampler(m_device->device(), sampler, NULL);
10437 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10438 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010439}
10440
Karl Schultz6addd812016-02-02 17:17:23 -070010441TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010442 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010443 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010444
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010446
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010447 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010448 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10449 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010450 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010451 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10452 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010453
10454 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010455 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10456 ds_pool_ci.pNext = NULL;
10457 ds_pool_ci.maxSets = 1;
10458 ds_pool_ci.poolSizeCount = 1;
10459 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010460
10461 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010462 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010463 ASSERT_VK_SUCCESS(err);
10464
10465 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010466 dsl_binding.binding = 0;
10467 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10468 dsl_binding.descriptorCount = 1;
10469 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10470 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010471
10472 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010473 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10474 ds_layout_ci.pNext = NULL;
10475 ds_layout_ci.bindingCount = 1;
10476 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010477 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010478 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010479 ASSERT_VK_SUCCESS(err);
10480
10481 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010482 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010483 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010484 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010485 alloc_info.descriptorPool = ds_pool;
10486 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010487 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010488 ASSERT_VK_SUCCESS(err);
10489
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010490 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010491
10492 VkDescriptorImageInfo descriptor_info;
10493 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10494 descriptor_info.sampler = sampler;
10495
10496 VkWriteDescriptorSet descriptor_write;
10497 memset(&descriptor_write, 0, sizeof(descriptor_write));
10498 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010499 descriptor_write.dstSet = descriptorSet;
10500 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010501 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010502 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10503 descriptor_write.pImageInfo = &descriptor_info;
10504
10505 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10506
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010507 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010508
Chia-I Wuf7458c52015-10-26 21:10:41 +080010509 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10510 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010511}
10512
Karl Schultz6addd812016-02-02 17:17:23 -070010513TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10514 // Create a single combined Image/Sampler descriptor and send it an invalid
10515 // imageView
10516 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010517
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010518 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010519
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010520 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010521 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010522 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10523 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010524
10525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10527 ds_pool_ci.pNext = NULL;
10528 ds_pool_ci.maxSets = 1;
10529 ds_pool_ci.poolSizeCount = 1;
10530 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010531
10532 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010533 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010534 ASSERT_VK_SUCCESS(err);
10535
10536 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010537 dsl_binding.binding = 0;
10538 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10539 dsl_binding.descriptorCount = 1;
10540 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10541 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010542
10543 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010544 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10545 ds_layout_ci.pNext = NULL;
10546 ds_layout_ci.bindingCount = 1;
10547 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010548 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010549 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010550 ASSERT_VK_SUCCESS(err);
10551
10552 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010553 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010554 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010555 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010556 alloc_info.descriptorPool = ds_pool;
10557 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010558 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010559 ASSERT_VK_SUCCESS(err);
10560
10561 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010562 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10563 sampler_ci.pNext = NULL;
10564 sampler_ci.magFilter = VK_FILTER_NEAREST;
10565 sampler_ci.minFilter = VK_FILTER_NEAREST;
10566 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10567 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10568 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10569 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10570 sampler_ci.mipLodBias = 1.0;
10571 sampler_ci.anisotropyEnable = VK_FALSE;
10572 sampler_ci.maxAnisotropy = 1;
10573 sampler_ci.compareEnable = VK_FALSE;
10574 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10575 sampler_ci.minLod = 1.0;
10576 sampler_ci.maxLod = 1.0;
10577 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10578 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010579
10580 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010581 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010582 ASSERT_VK_SUCCESS(err);
10583
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010584 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010585
10586 VkDescriptorImageInfo descriptor_info;
10587 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10588 descriptor_info.sampler = sampler;
10589 descriptor_info.imageView = view;
10590
10591 VkWriteDescriptorSet descriptor_write;
10592 memset(&descriptor_write, 0, sizeof(descriptor_write));
10593 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010594 descriptor_write.dstSet = descriptorSet;
10595 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010596 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010597 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10598 descriptor_write.pImageInfo = &descriptor_info;
10599
10600 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10601
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010602 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010603
Chia-I Wuf7458c52015-10-26 21:10:41 +080010604 vkDestroySampler(m_device->device(), sampler, NULL);
10605 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10606 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010607}
10608
Karl Schultz6addd812016-02-02 17:17:23 -070010609TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10610 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10611 // into the other
10612 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010613
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10615 " binding #1 with type "
10616 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10617 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010618
Tobin Ehlis04356f92015-10-27 16:35:27 -060010619 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010620 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010621 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010622 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10623 ds_type_count[0].descriptorCount = 1;
10624 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10625 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010626
10627 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010628 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10629 ds_pool_ci.pNext = NULL;
10630 ds_pool_ci.maxSets = 1;
10631 ds_pool_ci.poolSizeCount = 2;
10632 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010633
10634 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010635 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010636 ASSERT_VK_SUCCESS(err);
10637 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010638 dsl_binding[0].binding = 0;
10639 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10640 dsl_binding[0].descriptorCount = 1;
10641 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10642 dsl_binding[0].pImmutableSamplers = NULL;
10643 dsl_binding[1].binding = 1;
10644 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10645 dsl_binding[1].descriptorCount = 1;
10646 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10647 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010648
10649 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010650 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10651 ds_layout_ci.pNext = NULL;
10652 ds_layout_ci.bindingCount = 2;
10653 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010654
10655 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010656 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010657 ASSERT_VK_SUCCESS(err);
10658
10659 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010660 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010662 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010663 alloc_info.descriptorPool = ds_pool;
10664 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010666 ASSERT_VK_SUCCESS(err);
10667
10668 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010669 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10670 sampler_ci.pNext = NULL;
10671 sampler_ci.magFilter = VK_FILTER_NEAREST;
10672 sampler_ci.minFilter = VK_FILTER_NEAREST;
10673 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10674 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10675 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10676 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10677 sampler_ci.mipLodBias = 1.0;
10678 sampler_ci.anisotropyEnable = VK_FALSE;
10679 sampler_ci.maxAnisotropy = 1;
10680 sampler_ci.compareEnable = VK_FALSE;
10681 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10682 sampler_ci.minLod = 1.0;
10683 sampler_ci.maxLod = 1.0;
10684 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10685 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010686
10687 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010688 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010689 ASSERT_VK_SUCCESS(err);
10690
10691 VkDescriptorImageInfo info = {};
10692 info.sampler = sampler;
10693
10694 VkWriteDescriptorSet descriptor_write;
10695 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10696 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010697 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010698 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010699 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010700 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10701 descriptor_write.pImageInfo = &info;
10702 // This write update should succeed
10703 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10704 // Now perform a copy update that fails due to type mismatch
10705 VkCopyDescriptorSet copy_ds_update;
10706 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10707 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10708 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010709 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010710 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010711 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10712 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010713 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10714
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010715 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010716 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010717 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 -060010718 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10719 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10720 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010721 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010722 copy_ds_update.dstSet = descriptorSet;
10723 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010724 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010725 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10726
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010727 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010728
Tobin Ehlis04356f92015-10-27 16:35:27 -060010729 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10731 " binding#1 with offset index of 1 plus "
10732 "update array offset of 0 and update of "
10733 "5 descriptors oversteps total number "
10734 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010735
Tobin Ehlis04356f92015-10-27 16:35:27 -060010736 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10737 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10738 copy_ds_update.srcSet = descriptorSet;
10739 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010740 copy_ds_update.dstSet = descriptorSet;
10741 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010742 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010743 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10744
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010745 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010746
Chia-I Wuf7458c52015-10-26 21:10:41 +080010747 vkDestroySampler(m_device->device(), sampler, NULL);
10748 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10749 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010750}
10751
Karl Schultz6addd812016-02-02 17:17:23 -070010752TEST_F(VkLayerTest, NumSamplesMismatch) {
10753 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10754 // sampleCount
10755 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010756
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010758
Tobin Ehlis3b780662015-05-28 12:11:26 -060010759 ASSERT_NO_FATAL_FAILURE(InitState());
10760 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010761 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010762 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010763 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010764
10765 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010766 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10767 ds_pool_ci.pNext = NULL;
10768 ds_pool_ci.maxSets = 1;
10769 ds_pool_ci.poolSizeCount = 1;
10770 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010771
Tobin Ehlis3b780662015-05-28 12:11:26 -060010772 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010773 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010774 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010775
Tony Barboureb254902015-07-15 12:50:33 -060010776 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010777 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010778 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010779 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010780 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10781 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010782
Tony Barboureb254902015-07-15 12:50:33 -060010783 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10784 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10785 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010786 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010787 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010788
Tobin Ehlis3b780662015-05-28 12:11:26 -060010789 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010790 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010791 ASSERT_VK_SUCCESS(err);
10792
10793 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010794 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010795 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010796 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010797 alloc_info.descriptorPool = ds_pool;
10798 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010799 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010800 ASSERT_VK_SUCCESS(err);
10801
Tony Barboureb254902015-07-15 12:50:33 -060010802 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010803 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010804 pipe_ms_state_ci.pNext = NULL;
10805 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10806 pipe_ms_state_ci.sampleShadingEnable = 0;
10807 pipe_ms_state_ci.minSampleShading = 1.0;
10808 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010809
Tony Barboureb254902015-07-15 12:50:33 -060010810 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010811 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10812 pipeline_layout_ci.pNext = NULL;
10813 pipeline_layout_ci.setLayoutCount = 1;
10814 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010815
10816 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010817 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010818 ASSERT_VK_SUCCESS(err);
10819
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010820 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010821 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 -060010822 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010823 VkPipelineObj pipe(m_device);
10824 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010825 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010826 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010827 pipe.SetMSAA(&pipe_ms_state_ci);
10828 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010829
Tony Barbour552f6c02016-12-21 14:34:07 -070010830 m_commandBuffer->BeginCommandBuffer();
10831 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010832 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010833
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010834 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10835 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10836 VkRect2D scissor = {{0, 0}, {16, 16}};
10837 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10838
Mark Young29927482016-05-04 14:38:51 -060010839 // Render triangle (the error should trigger on the attempt to draw).
10840 Draw(3, 1, 0, 0);
10841
10842 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010843 m_commandBuffer->EndRenderPass();
10844 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010845
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010846 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010847
Chia-I Wuf7458c52015-10-26 21:10:41 +080010848 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10849 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10850 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010851}
Mark Young29927482016-05-04 14:38:51 -060010852
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010853TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010854 TEST_DESCRIPTION(
10855 "Hit RenderPass incompatible cases. "
10856 "Initial case is drawing with an active renderpass that's "
10857 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010858 VkResult err;
10859
10860 ASSERT_NO_FATAL_FAILURE(InitState());
10861 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10862
10863 VkDescriptorSetLayoutBinding dsl_binding = {};
10864 dsl_binding.binding = 0;
10865 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10866 dsl_binding.descriptorCount = 1;
10867 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10868 dsl_binding.pImmutableSamplers = NULL;
10869
10870 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10871 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10872 ds_layout_ci.pNext = NULL;
10873 ds_layout_ci.bindingCount = 1;
10874 ds_layout_ci.pBindings = &dsl_binding;
10875
10876 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010877 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010878 ASSERT_VK_SUCCESS(err);
10879
10880 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10881 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10882 pipeline_layout_ci.pNext = NULL;
10883 pipeline_layout_ci.setLayoutCount = 1;
10884 pipeline_layout_ci.pSetLayouts = &ds_layout;
10885
10886 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010887 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010888 ASSERT_VK_SUCCESS(err);
10889
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010890 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010891 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 -060010892 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010893 // Create a renderpass that will be incompatible with default renderpass
10894 VkAttachmentReference attach = {};
10895 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10896 VkAttachmentReference color_att = {};
10897 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10898 VkSubpassDescription subpass = {};
10899 subpass.inputAttachmentCount = 1;
10900 subpass.pInputAttachments = &attach;
10901 subpass.colorAttachmentCount = 1;
10902 subpass.pColorAttachments = &color_att;
10903 VkRenderPassCreateInfo rpci = {};
10904 rpci.subpassCount = 1;
10905 rpci.pSubpasses = &subpass;
10906 rpci.attachmentCount = 1;
10907 VkAttachmentDescription attach_desc = {};
10908 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010909 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10910 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010911 rpci.pAttachments = &attach_desc;
10912 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10913 VkRenderPass rp;
10914 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10915 VkPipelineObj pipe(m_device);
10916 pipe.AddShader(&vs);
10917 pipe.AddShader(&fs);
10918 pipe.AddColorAttachment();
10919 VkViewport view_port = {};
10920 m_viewports.push_back(view_port);
10921 pipe.SetViewport(m_viewports);
10922 VkRect2D rect = {};
10923 m_scissors.push_back(rect);
10924 pipe.SetScissor(m_scissors);
10925 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10926
10927 VkCommandBufferInheritanceInfo cbii = {};
10928 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10929 cbii.renderPass = rp;
10930 cbii.subpass = 0;
10931 VkCommandBufferBeginInfo cbbi = {};
10932 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10933 cbbi.pInheritanceInfo = &cbii;
10934 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10935 VkRenderPassBeginInfo rpbi = {};
10936 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10937 rpbi.framebuffer = m_framebuffer;
10938 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010939 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10940 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010941
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010943 // Render triangle (the error should trigger on the attempt to draw).
10944 Draw(3, 1, 0, 0);
10945
10946 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010947 m_commandBuffer->EndRenderPass();
10948 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010949
10950 m_errorMonitor->VerifyFound();
10951
10952 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10953 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10954 vkDestroyRenderPass(m_device->device(), rp, NULL);
10955}
10956
Mark Youngc89c6312016-03-31 16:03:20 -060010957TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10958 // Create Pipeline where the number of blend attachments doesn't match the
10959 // number of color attachments. In this case, we don't add any color
10960 // blend attachments even though we have a color attachment.
10961 VkResult err;
10962
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010964
10965 ASSERT_NO_FATAL_FAILURE(InitState());
10966 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10967 VkDescriptorPoolSize ds_type_count = {};
10968 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10969 ds_type_count.descriptorCount = 1;
10970
10971 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10972 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10973 ds_pool_ci.pNext = NULL;
10974 ds_pool_ci.maxSets = 1;
10975 ds_pool_ci.poolSizeCount = 1;
10976 ds_pool_ci.pPoolSizes = &ds_type_count;
10977
10978 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010979 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010980 ASSERT_VK_SUCCESS(err);
10981
10982 VkDescriptorSetLayoutBinding dsl_binding = {};
10983 dsl_binding.binding = 0;
10984 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10985 dsl_binding.descriptorCount = 1;
10986 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10987 dsl_binding.pImmutableSamplers = NULL;
10988
10989 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10990 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10991 ds_layout_ci.pNext = NULL;
10992 ds_layout_ci.bindingCount = 1;
10993 ds_layout_ci.pBindings = &dsl_binding;
10994
10995 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010996 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060010997 ASSERT_VK_SUCCESS(err);
10998
10999 VkDescriptorSet descriptorSet;
11000 VkDescriptorSetAllocateInfo alloc_info = {};
11001 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11002 alloc_info.descriptorSetCount = 1;
11003 alloc_info.descriptorPool = ds_pool;
11004 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011005 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011006 ASSERT_VK_SUCCESS(err);
11007
11008 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011009 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011010 pipe_ms_state_ci.pNext = NULL;
11011 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11012 pipe_ms_state_ci.sampleShadingEnable = 0;
11013 pipe_ms_state_ci.minSampleShading = 1.0;
11014 pipe_ms_state_ci.pSampleMask = NULL;
11015
11016 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11017 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11018 pipeline_layout_ci.pNext = NULL;
11019 pipeline_layout_ci.setLayoutCount = 1;
11020 pipeline_layout_ci.pSetLayouts = &ds_layout;
11021
11022 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011023 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011024 ASSERT_VK_SUCCESS(err);
11025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011026 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011027 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 -060011028 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011029 VkPipelineObj pipe(m_device);
11030 pipe.AddShader(&vs);
11031 pipe.AddShader(&fs);
11032 pipe.SetMSAA(&pipe_ms_state_ci);
11033 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011034 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011035
11036 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11037 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11038 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11039}
Mark Young29927482016-05-04 14:38:51 -060011040
Mark Muellerd4914412016-06-13 17:52:06 -060011041TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011042 TEST_DESCRIPTION(
11043 "Points to a wrong colorAttachment index in a VkClearAttachment "
11044 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011045 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011047
11048 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11049 m_errorMonitor->VerifyFound();
11050}
11051
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011052TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011053 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11054 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011055
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011056 ASSERT_NO_FATAL_FAILURE(InitState());
11057 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011058
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011059 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011060 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11061 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011062
11063 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011064 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11065 ds_pool_ci.pNext = NULL;
11066 ds_pool_ci.maxSets = 1;
11067 ds_pool_ci.poolSizeCount = 1;
11068 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011069
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011070 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011071 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011072 ASSERT_VK_SUCCESS(err);
11073
Tony Barboureb254902015-07-15 12:50:33 -060011074 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011075 dsl_binding.binding = 0;
11076 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11077 dsl_binding.descriptorCount = 1;
11078 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11079 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011080
Tony Barboureb254902015-07-15 12:50:33 -060011081 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011082 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11083 ds_layout_ci.pNext = NULL;
11084 ds_layout_ci.bindingCount = 1;
11085 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011086
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011087 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011088 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011089 ASSERT_VK_SUCCESS(err);
11090
11091 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011092 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011093 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011094 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011095 alloc_info.descriptorPool = ds_pool;
11096 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011097 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011098 ASSERT_VK_SUCCESS(err);
11099
Tony Barboureb254902015-07-15 12:50:33 -060011100 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011101 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011102 pipe_ms_state_ci.pNext = NULL;
11103 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11104 pipe_ms_state_ci.sampleShadingEnable = 0;
11105 pipe_ms_state_ci.minSampleShading = 1.0;
11106 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011107
Tony Barboureb254902015-07-15 12:50:33 -060011108 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011109 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11110 pipeline_layout_ci.pNext = NULL;
11111 pipeline_layout_ci.setLayoutCount = 1;
11112 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011113
11114 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011115 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011116 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011118 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011119 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011120 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011122
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011123 VkPipelineObj pipe(m_device);
11124 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011125 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011126 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011127 m_errorMonitor->SetUnexpectedError(
11128 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11129 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011130 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011131
Tony Barbour552f6c02016-12-21 14:34:07 -070011132 m_commandBuffer->BeginCommandBuffer();
11133 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011134
Karl Schultz6addd812016-02-02 17:17:23 -070011135 // Main thing we care about for this test is that the VkImage obj we're
11136 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011137 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011138 VkClearAttachment color_attachment;
11139 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11140 color_attachment.clearValue.color.float32[0] = 1.0;
11141 color_attachment.clearValue.color.float32[1] = 1.0;
11142 color_attachment.clearValue.color.float32[2] = 1.0;
11143 color_attachment.clearValue.color.float32[3] = 1.0;
11144 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011145 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011146
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011147 // Call for full-sized FB Color attachment prior to issuing a Draw
11148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011149 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011150 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011151 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011152
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011153 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11154 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11156 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11157 m_errorMonitor->VerifyFound();
11158
11159 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11160 clear_rect.layerCount = 2;
11161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11162 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011163 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011164
Chia-I Wuf7458c52015-10-26 21:10:41 +080011165 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11166 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11167 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011168}
11169
Karl Schultz6addd812016-02-02 17:17:23 -070011170TEST_F(VkLayerTest, VtxBufferBadIndex) {
11171 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011172
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11174 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011175
Tobin Ehlis502480b2015-06-24 15:53:07 -060011176 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011177 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011178 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011179
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011180 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011181 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11182 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011183
11184 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011185 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11186 ds_pool_ci.pNext = NULL;
11187 ds_pool_ci.maxSets = 1;
11188 ds_pool_ci.poolSizeCount = 1;
11189 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011190
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011191 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011193 ASSERT_VK_SUCCESS(err);
11194
Tony Barboureb254902015-07-15 12:50:33 -060011195 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011196 dsl_binding.binding = 0;
11197 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11198 dsl_binding.descriptorCount = 1;
11199 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11200 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011201
Tony Barboureb254902015-07-15 12:50:33 -060011202 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011203 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11204 ds_layout_ci.pNext = NULL;
11205 ds_layout_ci.bindingCount = 1;
11206 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011207
Tobin Ehlis502480b2015-06-24 15:53:07 -060011208 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011209 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011210 ASSERT_VK_SUCCESS(err);
11211
11212 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011213 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011214 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011215 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011216 alloc_info.descriptorPool = ds_pool;
11217 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011218 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011219 ASSERT_VK_SUCCESS(err);
11220
Tony Barboureb254902015-07-15 12:50:33 -060011221 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011222 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011223 pipe_ms_state_ci.pNext = NULL;
11224 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11225 pipe_ms_state_ci.sampleShadingEnable = 0;
11226 pipe_ms_state_ci.minSampleShading = 1.0;
11227 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011228
Tony Barboureb254902015-07-15 12:50:33 -060011229 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011230 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11231 pipeline_layout_ci.pNext = NULL;
11232 pipeline_layout_ci.setLayoutCount = 1;
11233 pipeline_layout_ci.pSetLayouts = &ds_layout;
11234 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011235
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011236 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011237 ASSERT_VK_SUCCESS(err);
11238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011239 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011240 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 -060011241 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011242 VkPipelineObj pipe(m_device);
11243 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011244 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011245 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011246 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011247 pipe.SetViewport(m_viewports);
11248 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011249 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011250
Tony Barbour552f6c02016-12-21 14:34:07 -070011251 m_commandBuffer->BeginCommandBuffer();
11252 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011253 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011254 // Don't care about actual data, just need to get to draw to flag error
11255 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011256 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011257 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011258 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011260 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011261
Chia-I Wuf7458c52015-10-26 21:10:41 +080011262 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11263 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11264 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011265}
Mark Muellerdfe37552016-07-07 14:47:42 -060011266
Mark Mueller2ee294f2016-08-04 12:59:48 -060011267TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011268 TEST_DESCRIPTION(
11269 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11270 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011271 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011272
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011273 const char *invalid_queueFamilyIndex_message =
11274 "Invalid queue create request in vkCreateDevice(). Invalid "
11275 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011277 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011278
Mark Mueller880fce52016-08-17 15:23:23 -060011279 // The following test fails with recent NVidia drivers.
11280 // By the time core_validation is reached, the NVidia
11281 // driver has sanitized the invalid condition and core_validation
11282 // is not introduced to the failure condition. This is not the case
11283 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011284 // uint32_t count = static_cast<uint32_t>(~0);
11285 // VkPhysicalDevice physical_device;
11286 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11287 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011288
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011290 float queue_priority = 0.0;
11291
11292 VkDeviceQueueCreateInfo queue_create_info = {};
11293 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11294 queue_create_info.queueCount = 1;
11295 queue_create_info.pQueuePriorities = &queue_priority;
11296 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11297
11298 VkPhysicalDeviceFeatures features = m_device->phy().features();
11299 VkDevice testDevice;
11300 VkDeviceCreateInfo device_create_info = {};
11301 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11302 device_create_info.queueCreateInfoCount = 1;
11303 device_create_info.pQueueCreateInfos = &queue_create_info;
11304 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011305 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011306 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11307 m_errorMonitor->VerifyFound();
11308
11309 queue_create_info.queueFamilyIndex = 1;
11310
11311 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11312 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11313 for (unsigned i = 0; i < feature_count; i++) {
11314 if (VK_FALSE == feature_array[i]) {
11315 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011317 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011318 m_errorMonitor->SetUnexpectedError(
11319 "You requested features that are unavailable on this device. You should first query feature availability by "
11320 "calling vkGetPhysicalDeviceFeatures().");
11321 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011322 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11323 m_errorMonitor->VerifyFound();
11324 break;
11325 }
11326 }
11327}
11328
Tobin Ehlis16edf082016-11-21 12:33:49 -070011329TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11330 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11331
11332 ASSERT_NO_FATAL_FAILURE(InitState());
11333
11334 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11335 std::vector<VkDeviceQueueCreateInfo> queue_info;
11336 queue_info.reserve(queue_props.size());
11337 std::vector<std::vector<float>> queue_priorities;
11338 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11339 VkDeviceQueueCreateInfo qi{};
11340 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11341 qi.queueFamilyIndex = i;
11342 qi.queueCount = queue_props[i].queueCount;
11343 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11344 qi.pQueuePriorities = queue_priorities[i].data();
11345 queue_info.push_back(qi);
11346 }
11347
11348 std::vector<const char *> device_extension_names;
11349
11350 VkDevice local_device;
11351 VkDeviceCreateInfo device_create_info = {};
11352 auto features = m_device->phy().features();
11353 // Intentionally disable pipeline stats
11354 features.pipelineStatisticsQuery = VK_FALSE;
11355 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11356 device_create_info.pNext = NULL;
11357 device_create_info.queueCreateInfoCount = queue_info.size();
11358 device_create_info.pQueueCreateInfos = queue_info.data();
11359 device_create_info.enabledLayerCount = 0;
11360 device_create_info.ppEnabledLayerNames = NULL;
11361 device_create_info.pEnabledFeatures = &features;
11362 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11363 ASSERT_VK_SUCCESS(err);
11364
11365 VkQueryPoolCreateInfo qpci{};
11366 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11367 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11368 qpci.queryCount = 1;
11369 VkQueryPool query_pool;
11370
11371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11372 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11373 m_errorMonitor->VerifyFound();
11374
11375 vkDestroyDevice(local_device, nullptr);
11376}
11377
Mark Mueller2ee294f2016-08-04 12:59:48 -060011378TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011379 TEST_DESCRIPTION(
11380 "Use an invalid queue index in a vkCmdWaitEvents call."
11381 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011382
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011383 const char *invalid_queue_index =
11384 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11385 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11386 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011387
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011388 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011391
11392 ASSERT_NO_FATAL_FAILURE(InitState());
11393
11394 VkEvent event;
11395 VkEventCreateInfo event_create_info{};
11396 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11397 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11398
Mark Mueller2ee294f2016-08-04 12:59:48 -060011399 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011400 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011401
Tony Barbour552f6c02016-12-21 14:34:07 -070011402 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011403
11404 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011405 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 -060011406 ASSERT_TRUE(image.initialized());
11407 VkImageMemoryBarrier img_barrier = {};
11408 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11409 img_barrier.pNext = NULL;
11410 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11411 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11412 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11413 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11414 img_barrier.image = image.handle();
11415 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011416
11417 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11418 // that layer validation catches the case when it is not.
11419 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011420 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11421 img_barrier.subresourceRange.baseArrayLayer = 0;
11422 img_barrier.subresourceRange.baseMipLevel = 0;
11423 img_barrier.subresourceRange.layerCount = 1;
11424 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011425 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11426 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011427 m_errorMonitor->VerifyFound();
11428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011430
11431 VkQueryPool query_pool;
11432 VkQueryPoolCreateInfo query_pool_create_info = {};
11433 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11434 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11435 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011436 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011437
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011438 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011439 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11440
11441 vkEndCommandBuffer(m_commandBuffer->handle());
11442 m_errorMonitor->VerifyFound();
11443
11444 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11445 vkDestroyEvent(m_device->device(), event, nullptr);
11446}
11447
Mark Muellerdfe37552016-07-07 14:47:42 -060011448TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011449 TEST_DESCRIPTION(
11450 "Submit a command buffer using deleted vertex buffer, "
11451 "delete a buffer twice, use an invalid offset for each "
11452 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011453
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011454 const char *deleted_buffer_in_command_buffer =
11455 "Cannot submit cmd buffer "
11456 "using deleted buffer ";
11457 const char *invalid_offset_message =
11458 "vkBindBufferMemory(): "
11459 "memoryOffset is 0x";
11460 const char *invalid_storage_buffer_offset_message =
11461 "vkBindBufferMemory(): "
11462 "storage memoryOffset "
11463 "is 0x";
11464 const char *invalid_texel_buffer_offset_message =
11465 "vkBindBufferMemory(): "
11466 "texel memoryOffset "
11467 "is 0x";
11468 const char *invalid_uniform_buffer_offset_message =
11469 "vkBindBufferMemory(): "
11470 "uniform memoryOffset "
11471 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011472
11473 ASSERT_NO_FATAL_FAILURE(InitState());
11474 ASSERT_NO_FATAL_FAILURE(InitViewport());
11475 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11476
11477 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011478 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011479 pipe_ms_state_ci.pNext = NULL;
11480 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11481 pipe_ms_state_ci.sampleShadingEnable = 0;
11482 pipe_ms_state_ci.minSampleShading = 1.0;
11483 pipe_ms_state_ci.pSampleMask = nullptr;
11484
11485 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11486 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11487 VkPipelineLayout pipeline_layout;
11488
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011489 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011490 ASSERT_VK_SUCCESS(err);
11491
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011492 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11493 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011494 VkPipelineObj pipe(m_device);
11495 pipe.AddShader(&vs);
11496 pipe.AddShader(&fs);
11497 pipe.AddColorAttachment();
11498 pipe.SetMSAA(&pipe_ms_state_ci);
11499 pipe.SetViewport(m_viewports);
11500 pipe.SetScissor(m_scissors);
11501 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11502
Tony Barbour552f6c02016-12-21 14:34:07 -070011503 m_commandBuffer->BeginCommandBuffer();
11504 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011505 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011506
11507 {
11508 // Create and bind a vertex buffer in a reduced scope, which will cause
11509 // it to be deleted upon leaving this scope
11510 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011511 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011512 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11513 draw_verticies.AddVertexInputToPipe(pipe);
11514 }
11515
11516 Draw(1, 0, 0, 0);
11517
Tony Barbour552f6c02016-12-21 14:34:07 -070011518 m_commandBuffer->EndRenderPass();
11519 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011520
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011521 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011522 QueueCommandBuffer(false);
11523 m_errorMonitor->VerifyFound();
11524
11525 {
11526 // Create and bind a vertex buffer in a reduced scope, and delete it
11527 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011528 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011530 buffer_test.TestDoubleDestroy();
11531 }
11532 m_errorMonitor->VerifyFound();
11533
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011534 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011535 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011536 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011538 m_errorMonitor->SetUnexpectedError(
11539 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11540 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011541 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11542 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011543 m_errorMonitor->VerifyFound();
11544 }
11545
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011546 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11547 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011548 // Create and bind a memory buffer with an invalid offset again,
11549 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011550 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011551 m_errorMonitor->SetUnexpectedError(
11552 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11553 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11555 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011556 m_errorMonitor->VerifyFound();
11557 }
11558
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011559 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011560 // Create and bind a memory buffer with an invalid offset again, but
11561 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011562 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011563 m_errorMonitor->SetUnexpectedError(
11564 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11565 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011566 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11567 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011568 m_errorMonitor->VerifyFound();
11569 }
11570
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011571 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011572 // Create and bind a memory buffer with an invalid offset again, but
11573 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011574 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011575 m_errorMonitor->SetUnexpectedError(
11576 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11577 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011578 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11579 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011580 m_errorMonitor->VerifyFound();
11581 }
11582
11583 {
11584 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011585 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011586 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11587 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011588 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11589 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011590 m_errorMonitor->VerifyFound();
11591 }
11592
11593 {
11594 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011595 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011596 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11597 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011598 }
11599 m_errorMonitor->VerifyFound();
11600
11601 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11602}
11603
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011604// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11605TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011606 TEST_DESCRIPTION(
11607 "Hit all possible validation checks associated with the "
11608 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11609 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011610 // 3 in ValidateCmdBufImageLayouts
11611 // * -1 Attempt to submit cmd buf w/ deleted image
11612 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11613 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011614
11615 ASSERT_NO_FATAL_FAILURE(InitState());
11616 // Create src & dst images to use for copy operations
11617 VkImage src_image;
11618 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011619 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011620
11621 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11622 const int32_t tex_width = 32;
11623 const int32_t tex_height = 32;
11624
11625 VkImageCreateInfo image_create_info = {};
11626 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11627 image_create_info.pNext = NULL;
11628 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11629 image_create_info.format = tex_format;
11630 image_create_info.extent.width = tex_width;
11631 image_create_info.extent.height = tex_height;
11632 image_create_info.extent.depth = 1;
11633 image_create_info.mipLevels = 1;
11634 image_create_info.arrayLayers = 4;
11635 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11636 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11637 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011638 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011639 image_create_info.flags = 0;
11640
11641 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11642 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011643 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011644 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11645 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011646 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11647 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11648 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11649 ASSERT_VK_SUCCESS(err);
11650
11651 // Allocate memory
11652 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011653 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011654 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011655 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11656 mem_alloc.pNext = NULL;
11657 mem_alloc.allocationSize = 0;
11658 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011659
11660 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011661 mem_alloc.allocationSize = img_mem_reqs.size;
11662 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011663 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011664 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011665 ASSERT_VK_SUCCESS(err);
11666
11667 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011668 mem_alloc.allocationSize = img_mem_reqs.size;
11669 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011670 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011671 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011672 ASSERT_VK_SUCCESS(err);
11673
11674 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011675 mem_alloc.allocationSize = img_mem_reqs.size;
11676 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011677 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011678 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011679 ASSERT_VK_SUCCESS(err);
11680
11681 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11682 ASSERT_VK_SUCCESS(err);
11683 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11684 ASSERT_VK_SUCCESS(err);
11685 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11686 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011687
Tony Barbour552f6c02016-12-21 14:34:07 -070011688 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011689 VkImageCopy copy_region;
11690 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11691 copy_region.srcSubresource.mipLevel = 0;
11692 copy_region.srcSubresource.baseArrayLayer = 0;
11693 copy_region.srcSubresource.layerCount = 1;
11694 copy_region.srcOffset.x = 0;
11695 copy_region.srcOffset.y = 0;
11696 copy_region.srcOffset.z = 0;
11697 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11698 copy_region.dstSubresource.mipLevel = 0;
11699 copy_region.dstSubresource.baseArrayLayer = 0;
11700 copy_region.dstSubresource.layerCount = 1;
11701 copy_region.dstOffset.x = 0;
11702 copy_region.dstOffset.y = 0;
11703 copy_region.dstOffset.z = 0;
11704 copy_region.extent.width = 1;
11705 copy_region.extent.height = 1;
11706 copy_region.extent.depth = 1;
11707
11708 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11709 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011710 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011711 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 -060011712 m_errorMonitor->VerifyFound();
11713 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011714 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11715 "Cannot copy from an image whose source layout is "
11716 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11717 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011718 m_errorMonitor->SetUnexpectedError(
11719 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011720 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 -060011721 m_errorMonitor->VerifyFound();
11722 // Final src error is due to bad layout type
11723 m_errorMonitor->SetDesiredFailureMsg(
11724 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11725 "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 -070011726 m_errorMonitor->SetUnexpectedError(
11727 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11728 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011729 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 -060011730 m_errorMonitor->VerifyFound();
11731 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11733 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011734 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011735 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 -060011736 m_errorMonitor->VerifyFound();
11737 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11739 "Cannot copy from an image whose dest layout is "
11740 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11741 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011742 m_errorMonitor->SetUnexpectedError(
11743 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011744 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 -060011745 m_errorMonitor->VerifyFound();
11746 m_errorMonitor->SetDesiredFailureMsg(
11747 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11748 "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 -070011749 m_errorMonitor->SetUnexpectedError(
11750 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11751 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011752 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 -060011753 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011754
Cort3b021012016-12-07 12:00:57 -080011755 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11756 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11757 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11758 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11759 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11760 transfer_dst_image_barrier[0].srcAccessMask = 0;
11761 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11762 transfer_dst_image_barrier[0].image = dst_image;
11763 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11764 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11765 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11766 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11767 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11768 transfer_dst_image_barrier[0].image = depth_image;
11769 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11770 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11771 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11772
11773 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011774 VkClearColorValue color_clear_value = {};
11775 VkImageSubresourceRange clear_range;
11776 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11777 clear_range.baseMipLevel = 0;
11778 clear_range.baseArrayLayer = 0;
11779 clear_range.layerCount = 1;
11780 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011781
Cort3b021012016-12-07 12:00:57 -080011782 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11783 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011786 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011787 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011788 // Fail due to provided layout not matching actual current layout for color clear.
11789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011790 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011791 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011792
Cort530cf382016-12-08 09:59:47 -080011793 VkClearDepthStencilValue depth_clear_value = {};
11794 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011795
11796 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11797 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011800 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011801 m_errorMonitor->VerifyFound();
11802 // Fail due to provided layout not matching actual current layout for depth clear.
11803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011804 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011805 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011806
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011807 // Now cause error due to bad image layout transition in PipelineBarrier
11808 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011809 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011810 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011811 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011812 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011813 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11814 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011815 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11817 "You cannot transition the layout of aspect 1 from "
11818 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11819 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011820 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11821 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011822 m_errorMonitor->VerifyFound();
11823
11824 // Finally some layout errors at RenderPass create time
11825 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11826 VkAttachmentReference attach = {};
11827 // perf warning for GENERAL layout w/ non-DS input attachment
11828 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11829 VkSubpassDescription subpass = {};
11830 subpass.inputAttachmentCount = 1;
11831 subpass.pInputAttachments = &attach;
11832 VkRenderPassCreateInfo rpci = {};
11833 rpci.subpassCount = 1;
11834 rpci.pSubpasses = &subpass;
11835 rpci.attachmentCount = 1;
11836 VkAttachmentDescription attach_desc = {};
11837 attach_desc.format = VK_FORMAT_UNDEFINED;
11838 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011839 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011840 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11842 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011843 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11844 m_errorMonitor->VerifyFound();
11845 // error w/ non-general layout
11846 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11847
11848 m_errorMonitor->SetDesiredFailureMsg(
11849 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11850 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11851 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11852 m_errorMonitor->VerifyFound();
11853 subpass.inputAttachmentCount = 0;
11854 subpass.colorAttachmentCount = 1;
11855 subpass.pColorAttachments = &attach;
11856 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11857 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011858 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11859 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011860 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11861 m_errorMonitor->VerifyFound();
11862 // error w/ non-color opt or GENERAL layout for color attachment
11863 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11864 m_errorMonitor->SetDesiredFailureMsg(
11865 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11866 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11867 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11868 m_errorMonitor->VerifyFound();
11869 subpass.colorAttachmentCount = 0;
11870 subpass.pDepthStencilAttachment = &attach;
11871 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11872 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11874 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011875 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11876 m_errorMonitor->VerifyFound();
11877 // error w/ non-ds opt or GENERAL layout for color attachment
11878 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11880 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11881 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011882 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11883 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011884 // For this error we need a valid renderpass so create default one
11885 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11886 attach.attachment = 0;
11887 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
11888 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11889 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11890 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11891 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11892 // Can't do a CLEAR load on READ_ONLY initialLayout
11893 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11894 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11895 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11897 " with invalid first layout "
11898 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11899 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011900 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11901 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011902
Cort3b021012016-12-07 12:00:57 -080011903 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11904 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11905 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011906 vkDestroyImage(m_device->device(), src_image, NULL);
11907 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011908 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011909}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011910
Tobin Ehlise0936662016-10-11 08:10:51 -060011911TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11912 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11913 VkResult err;
11914
11915 ASSERT_NO_FATAL_FAILURE(InitState());
11916
11917 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11918 VkImageTiling tiling;
11919 VkFormatProperties format_properties;
11920 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11921 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11922 tiling = VK_IMAGE_TILING_LINEAR;
11923 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11924 tiling = VK_IMAGE_TILING_OPTIMAL;
11925 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011926 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011927 return;
11928 }
11929
11930 VkDescriptorPoolSize ds_type = {};
11931 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11932 ds_type.descriptorCount = 1;
11933
11934 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11935 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11936 ds_pool_ci.maxSets = 1;
11937 ds_pool_ci.poolSizeCount = 1;
11938 ds_pool_ci.pPoolSizes = &ds_type;
11939 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11940
11941 VkDescriptorPool ds_pool;
11942 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11943 ASSERT_VK_SUCCESS(err);
11944
11945 VkDescriptorSetLayoutBinding dsl_binding = {};
11946 dsl_binding.binding = 0;
11947 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11948 dsl_binding.descriptorCount = 1;
11949 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11950 dsl_binding.pImmutableSamplers = NULL;
11951
11952 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11953 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11954 ds_layout_ci.pNext = NULL;
11955 ds_layout_ci.bindingCount = 1;
11956 ds_layout_ci.pBindings = &dsl_binding;
11957
11958 VkDescriptorSetLayout ds_layout;
11959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11960 ASSERT_VK_SUCCESS(err);
11961
11962 VkDescriptorSetAllocateInfo alloc_info = {};
11963 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11964 alloc_info.descriptorSetCount = 1;
11965 alloc_info.descriptorPool = ds_pool;
11966 alloc_info.pSetLayouts = &ds_layout;
11967 VkDescriptorSet descriptor_set;
11968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11969 ASSERT_VK_SUCCESS(err);
11970
11971 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11972 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11973 pipeline_layout_ci.pNext = NULL;
11974 pipeline_layout_ci.setLayoutCount = 1;
11975 pipeline_layout_ci.pSetLayouts = &ds_layout;
11976 VkPipelineLayout pipeline_layout;
11977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
11978 ASSERT_VK_SUCCESS(err);
11979
11980 VkImageObj image(m_device);
11981 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
11982 ASSERT_TRUE(image.initialized());
11983 VkImageView view = image.targetView(tex_format);
11984
11985 VkDescriptorImageInfo image_info = {};
11986 image_info.imageView = view;
11987 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11988
11989 VkWriteDescriptorSet descriptor_write = {};
11990 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
11991 descriptor_write.dstSet = descriptor_set;
11992 descriptor_write.dstBinding = 0;
11993 descriptor_write.descriptorCount = 1;
11994 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11995 descriptor_write.pImageInfo = &image_info;
11996
11997 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11998 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
11999 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12000 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12001 m_errorMonitor->VerifyFound();
12002
12003 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12004 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12005 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12006 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12007}
12008
Mark Mueller93b938f2016-08-18 10:27:40 -060012009TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012010 TEST_DESCRIPTION(
12011 "Use vkCmdExecuteCommands with invalid state "
12012 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012013
12014 ASSERT_NO_FATAL_FAILURE(InitState());
12015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12016
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012017 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012018 const char *simultaneous_use_message2 =
12019 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12020 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012021
12022 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012023 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012024 command_buffer_allocate_info.commandPool = m_commandPool;
12025 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12026 command_buffer_allocate_info.commandBufferCount = 1;
12027
12028 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012029 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012030 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12031 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012032 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012033 command_buffer_inheritance_info.renderPass = m_renderPass;
12034 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012035
Mark Mueller93b938f2016-08-18 10:27:40 -060012036 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012037 command_buffer_begin_info.flags =
12038 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012039 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12040
12041 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12042 vkEndCommandBuffer(secondary_command_buffer);
12043
Mark Mueller93b938f2016-08-18 10:27:40 -060012044 VkSubmitInfo submit_info = {};
12045 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12046 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012047 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012048
Mark Mueller4042b652016-09-05 22:52:21 -060012049 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012050 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12051 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12052 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012053 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012054 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012055 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12056 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012057
Dave Houltonfbf52152017-01-06 12:55:29 -070012058 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012059 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012060 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012061
Mark Mueller4042b652016-09-05 22:52:21 -060012062 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012063 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12064 m_errorMonitor->SetUnexpectedError(
12065 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12066 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012067 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012068 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012070 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12071 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012072 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012073 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12074 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012075
12076 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012077
12078 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012079}
12080
Tony Barbour626994c2017-02-08 15:29:37 -070012081TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12082 TEST_DESCRIPTION(
12083 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12084 "errors");
12085 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12086 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12087 ASSERT_NO_FATAL_FAILURE(InitState());
12088
12089 VkCommandBuffer cmd_bufs[2];
12090 VkCommandBufferAllocateInfo alloc_info;
12091 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12092 alloc_info.pNext = NULL;
12093 alloc_info.commandBufferCount = 2;
12094 alloc_info.commandPool = m_commandPool;
12095 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12096 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12097
12098 VkCommandBufferBeginInfo cb_binfo;
12099 cb_binfo.pNext = NULL;
12100 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12101 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12102 cb_binfo.flags = 0;
12103 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12104 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12105 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12106 vkEndCommandBuffer(cmd_bufs[0]);
12107 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12108
12109 VkSubmitInfo submit_info = {};
12110 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12111 submit_info.commandBufferCount = 2;
12112 submit_info.pCommandBuffers = duplicates;
12113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_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 // Set one time use and now look for one time submit
12119 duplicates[0] = duplicates[1] = cmd_bufs[1];
12120 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12121 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12122 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12123 vkEndCommandBuffer(cmd_bufs[1]);
12124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12125 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12126 m_errorMonitor->VerifyFound();
12127 vkQueueWaitIdle(m_device->m_queue);
12128}
12129
Tobin Ehlisb093da82017-01-19 12:05:27 -070012130TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012131 TEST_DESCRIPTION(
12132 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12133 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012134
12135 ASSERT_NO_FATAL_FAILURE(InitState());
12136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12137
12138 std::vector<const char *> device_extension_names;
12139 auto features = m_device->phy().features();
12140 // Make sure gs & ts are disabled
12141 features.geometryShader = false;
12142 features.tessellationShader = false;
12143 // The sacrificial device object
12144 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12145
12146 VkCommandPoolCreateInfo pool_create_info{};
12147 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12148 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12149
12150 VkCommandPool command_pool;
12151 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12152
12153 VkCommandBufferAllocateInfo cmd = {};
12154 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12155 cmd.pNext = NULL;
12156 cmd.commandPool = command_pool;
12157 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12158 cmd.commandBufferCount = 1;
12159
12160 VkCommandBuffer cmd_buffer;
12161 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12162 ASSERT_VK_SUCCESS(err);
12163
12164 VkEvent event;
12165 VkEventCreateInfo evci = {};
12166 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12167 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12168 ASSERT_VK_SUCCESS(result);
12169
12170 VkCommandBufferBeginInfo cbbi = {};
12171 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12172 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12174 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12175 m_errorMonitor->VerifyFound();
12176
12177 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12178 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12179 m_errorMonitor->VerifyFound();
12180
12181 vkDestroyEvent(test_device.handle(), event, NULL);
12182 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12183}
12184
Mark Mueller917f6bc2016-08-30 10:57:19 -060012185TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012186 TEST_DESCRIPTION(
12187 "Use vkCmdExecuteCommands with invalid state "
12188 "in primary and secondary command buffers. "
12189 "Delete objects that are inuse. Call VkQueueSubmit "
12190 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012191
12192 ASSERT_NO_FATAL_FAILURE(InitState());
12193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12194
Tony Barbour552f6c02016-12-21 14:34:07 -070012195 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012196
12197 VkEvent event;
12198 VkEventCreateInfo event_create_info = {};
12199 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12200 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012201 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012202
Tony Barbour552f6c02016-12-21 14:34:07 -070012203 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012204 vkDestroyEvent(m_device->device(), event, nullptr);
12205
12206 VkSubmitInfo submit_info = {};
12207 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12208 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012209 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Jeremy Hayes1b082d72017-01-27 11:34:28 -070012210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot submit cmd buffer using deleted event 0x");
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012212 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12213 m_errorMonitor->VerifyFound();
12214
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012215 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012216 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12217
12218 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12219
Mark Mueller917f6bc2016-08-30 10:57:19 -060012220 VkSemaphoreCreateInfo semaphore_create_info = {};
12221 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12222 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012223 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012224 VkFenceCreateInfo fence_create_info = {};
12225 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12226 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012227 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012228
12229 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012230 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012231 descriptor_pool_type_count.descriptorCount = 1;
12232
12233 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12234 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12235 descriptor_pool_create_info.maxSets = 1;
12236 descriptor_pool_create_info.poolSizeCount = 1;
12237 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012238 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012239
12240 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012241 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012242
12243 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012244 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012245 descriptorset_layout_binding.descriptorCount = 1;
12246 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12247
12248 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012249 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012250 descriptorset_layout_create_info.bindingCount = 1;
12251 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12252
12253 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012254 ASSERT_VK_SUCCESS(
12255 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012256
12257 VkDescriptorSet descriptorset;
12258 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012259 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012260 descriptorset_allocate_info.descriptorSetCount = 1;
12261 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12262 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012263 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012264
Mark Mueller4042b652016-09-05 22:52:21 -060012265 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12266
12267 VkDescriptorBufferInfo buffer_info = {};
12268 buffer_info.buffer = buffer_test.GetBuffer();
12269 buffer_info.offset = 0;
12270 buffer_info.range = 1024;
12271
12272 VkWriteDescriptorSet write_descriptor_set = {};
12273 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12274 write_descriptor_set.dstSet = descriptorset;
12275 write_descriptor_set.descriptorCount = 1;
12276 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12277 write_descriptor_set.pBufferInfo = &buffer_info;
12278
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012279 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012280
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012281 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12282 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012283
12284 VkPipelineObj pipe(m_device);
12285 pipe.AddColorAttachment();
12286 pipe.AddShader(&vs);
12287 pipe.AddShader(&fs);
12288
12289 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012290 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012291 pipeline_layout_create_info.setLayoutCount = 1;
12292 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12293
12294 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012295 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012296
12297 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12298
Tony Barbour552f6c02016-12-21 14:34:07 -070012299 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012300 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012302 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12303 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12304 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012305
Tony Barbour552f6c02016-12-21 14:34:07 -070012306 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012307
Mark Mueller917f6bc2016-08-30 10:57:19 -060012308 submit_info.signalSemaphoreCount = 1;
12309 submit_info.pSignalSemaphores = &semaphore;
12310 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012311 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012312
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012313 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012314 vkDestroyEvent(m_device->device(), event, nullptr);
12315 m_errorMonitor->VerifyFound();
12316
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012317 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012318 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12319 m_errorMonitor->VerifyFound();
12320
Jeremy Hayes08369882017-02-02 10:31:06 -070012321 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012322 vkDestroyFence(m_device->device(), fence, nullptr);
12323 m_errorMonitor->VerifyFound();
12324
Tobin Ehlis122207b2016-09-01 08:50:06 -070012325 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012326 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12327 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012328 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012329 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12330 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012331 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012332 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12333 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012334 vkDestroyEvent(m_device->device(), event, nullptr);
12335 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012336 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012337 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12338}
12339
Tobin Ehlis2adda372016-09-01 08:51:06 -070012340TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12341 TEST_DESCRIPTION("Delete in-use query pool.");
12342
12343 ASSERT_NO_FATAL_FAILURE(InitState());
12344 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12345
12346 VkQueryPool query_pool;
12347 VkQueryPoolCreateInfo query_pool_ci{};
12348 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12349 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12350 query_pool_ci.queryCount = 1;
12351 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012352 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012353 // Reset query pool to create binding with cmd buffer
12354 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12355
Tony Barbour552f6c02016-12-21 14:34:07 -070012356 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012357
12358 VkSubmitInfo submit_info = {};
12359 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12360 submit_info.commandBufferCount = 1;
12361 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12362 // Submit cmd buffer and then destroy query pool while in-flight
12363 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12364
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012366 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12367 m_errorMonitor->VerifyFound();
12368
12369 vkQueueWaitIdle(m_device->m_queue);
12370 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012371 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12372 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012373 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12374}
12375
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012376TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12377 TEST_DESCRIPTION("Delete in-use pipeline.");
12378
12379 ASSERT_NO_FATAL_FAILURE(InitState());
12380 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12381
12382 // Empty pipeline layout used for binding PSO
12383 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12384 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12385 pipeline_layout_ci.setLayoutCount = 0;
12386 pipeline_layout_ci.pSetLayouts = NULL;
12387
12388 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012389 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012390 ASSERT_VK_SUCCESS(err);
12391
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012392 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012393 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012394 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12395 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012396 // Store pipeline handle so we can actually delete it before test finishes
12397 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012398 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012399 VkPipelineObj pipe(m_device);
12400 pipe.AddShader(&vs);
12401 pipe.AddShader(&fs);
12402 pipe.AddColorAttachment();
12403 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12404 delete_this_pipeline = pipe.handle();
12405
Tony Barbour552f6c02016-12-21 14:34:07 -070012406 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012407 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012408 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012409
Tony Barbour552f6c02016-12-21 14:34:07 -070012410 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012411
12412 VkSubmitInfo submit_info = {};
12413 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12414 submit_info.commandBufferCount = 1;
12415 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12416 // Submit cmd buffer and then pipeline destroyed while in-flight
12417 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012418 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012419 m_errorMonitor->VerifyFound();
12420 // Make sure queue finished and then actually delete pipeline
12421 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012422 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12423 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012424 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12425 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12426}
12427
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012428TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12429 TEST_DESCRIPTION("Delete in-use imageView.");
12430
12431 ASSERT_NO_FATAL_FAILURE(InitState());
12432 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12433
12434 VkDescriptorPoolSize ds_type_count;
12435 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12436 ds_type_count.descriptorCount = 1;
12437
12438 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12439 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12440 ds_pool_ci.maxSets = 1;
12441 ds_pool_ci.poolSizeCount = 1;
12442 ds_pool_ci.pPoolSizes = &ds_type_count;
12443
12444 VkDescriptorPool ds_pool;
12445 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12446 ASSERT_VK_SUCCESS(err);
12447
12448 VkSamplerCreateInfo sampler_ci = {};
12449 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12450 sampler_ci.pNext = NULL;
12451 sampler_ci.magFilter = VK_FILTER_NEAREST;
12452 sampler_ci.minFilter = VK_FILTER_NEAREST;
12453 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12454 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12455 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12456 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12457 sampler_ci.mipLodBias = 1.0;
12458 sampler_ci.anisotropyEnable = VK_FALSE;
12459 sampler_ci.maxAnisotropy = 1;
12460 sampler_ci.compareEnable = VK_FALSE;
12461 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12462 sampler_ci.minLod = 1.0;
12463 sampler_ci.maxLod = 1.0;
12464 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12465 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12466 VkSampler sampler;
12467
12468 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12469 ASSERT_VK_SUCCESS(err);
12470
12471 VkDescriptorSetLayoutBinding layout_binding;
12472 layout_binding.binding = 0;
12473 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12474 layout_binding.descriptorCount = 1;
12475 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12476 layout_binding.pImmutableSamplers = NULL;
12477
12478 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12479 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12480 ds_layout_ci.bindingCount = 1;
12481 ds_layout_ci.pBindings = &layout_binding;
12482 VkDescriptorSetLayout ds_layout;
12483 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12484 ASSERT_VK_SUCCESS(err);
12485
12486 VkDescriptorSetAllocateInfo alloc_info = {};
12487 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12488 alloc_info.descriptorSetCount = 1;
12489 alloc_info.descriptorPool = ds_pool;
12490 alloc_info.pSetLayouts = &ds_layout;
12491 VkDescriptorSet descriptor_set;
12492 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12493 ASSERT_VK_SUCCESS(err);
12494
12495 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12496 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12497 pipeline_layout_ci.pNext = NULL;
12498 pipeline_layout_ci.setLayoutCount = 1;
12499 pipeline_layout_ci.pSetLayouts = &ds_layout;
12500
12501 VkPipelineLayout pipeline_layout;
12502 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12503 ASSERT_VK_SUCCESS(err);
12504
12505 VkImageObj image(m_device);
12506 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12507 ASSERT_TRUE(image.initialized());
12508
12509 VkImageView view;
12510 VkImageViewCreateInfo ivci = {};
12511 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12512 ivci.image = image.handle();
12513 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12514 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12515 ivci.subresourceRange.layerCount = 1;
12516 ivci.subresourceRange.baseMipLevel = 0;
12517 ivci.subresourceRange.levelCount = 1;
12518 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12519
12520 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12521 ASSERT_VK_SUCCESS(err);
12522
12523 VkDescriptorImageInfo image_info{};
12524 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12525 image_info.imageView = view;
12526 image_info.sampler = sampler;
12527
12528 VkWriteDescriptorSet descriptor_write = {};
12529 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12530 descriptor_write.dstSet = descriptor_set;
12531 descriptor_write.dstBinding = 0;
12532 descriptor_write.descriptorCount = 1;
12533 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12534 descriptor_write.pImageInfo = &image_info;
12535
12536 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12537
12538 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012539 char const *vsSource =
12540 "#version 450\n"
12541 "\n"
12542 "out gl_PerVertex { \n"
12543 " vec4 gl_Position;\n"
12544 "};\n"
12545 "void main(){\n"
12546 " gl_Position = vec4(1);\n"
12547 "}\n";
12548 char const *fsSource =
12549 "#version 450\n"
12550 "\n"
12551 "layout(set=0, binding=0) uniform sampler2D s;\n"
12552 "layout(location=0) out vec4 x;\n"
12553 "void main(){\n"
12554 " x = texture(s, vec2(1));\n"
12555 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012556 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12557 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12558 VkPipelineObj pipe(m_device);
12559 pipe.AddShader(&vs);
12560 pipe.AddShader(&fs);
12561 pipe.AddColorAttachment();
12562 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12563
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012564 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012565
Tony Barbour552f6c02016-12-21 14:34:07 -070012566 m_commandBuffer->BeginCommandBuffer();
12567 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012568 // Bind pipeline to cmd buffer
12569 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12570 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12571 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012572
12573 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12574 VkRect2D scissor = {{0, 0}, {16, 16}};
12575 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12576 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12577
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012578 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012579 m_commandBuffer->EndRenderPass();
12580 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012581 // Submit cmd buffer then destroy sampler
12582 VkSubmitInfo submit_info = {};
12583 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12584 submit_info.commandBufferCount = 1;
12585 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12586 // Submit cmd buffer and then destroy imageView while in-flight
12587 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12588
12589 vkDestroyImageView(m_device->device(), view, nullptr);
12590 m_errorMonitor->VerifyFound();
12591 vkQueueWaitIdle(m_device->m_queue);
12592 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012593 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12594 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012595 vkDestroyImageView(m_device->device(), view, NULL);
12596 vkDestroySampler(m_device->device(), sampler, nullptr);
12597 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12598 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12599 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12600}
12601
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012602TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12603 TEST_DESCRIPTION("Delete in-use bufferView.");
12604
12605 ASSERT_NO_FATAL_FAILURE(InitState());
12606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12607
12608 VkDescriptorPoolSize ds_type_count;
12609 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12610 ds_type_count.descriptorCount = 1;
12611
12612 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12613 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12614 ds_pool_ci.maxSets = 1;
12615 ds_pool_ci.poolSizeCount = 1;
12616 ds_pool_ci.pPoolSizes = &ds_type_count;
12617
12618 VkDescriptorPool ds_pool;
12619 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12620 ASSERT_VK_SUCCESS(err);
12621
12622 VkDescriptorSetLayoutBinding layout_binding;
12623 layout_binding.binding = 0;
12624 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12625 layout_binding.descriptorCount = 1;
12626 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12627 layout_binding.pImmutableSamplers = NULL;
12628
12629 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12630 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12631 ds_layout_ci.bindingCount = 1;
12632 ds_layout_ci.pBindings = &layout_binding;
12633 VkDescriptorSetLayout ds_layout;
12634 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12635 ASSERT_VK_SUCCESS(err);
12636
12637 VkDescriptorSetAllocateInfo alloc_info = {};
12638 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12639 alloc_info.descriptorSetCount = 1;
12640 alloc_info.descriptorPool = ds_pool;
12641 alloc_info.pSetLayouts = &ds_layout;
12642 VkDescriptorSet descriptor_set;
12643 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12644 ASSERT_VK_SUCCESS(err);
12645
12646 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12647 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12648 pipeline_layout_ci.pNext = NULL;
12649 pipeline_layout_ci.setLayoutCount = 1;
12650 pipeline_layout_ci.pSetLayouts = &ds_layout;
12651
12652 VkPipelineLayout pipeline_layout;
12653 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12654 ASSERT_VK_SUCCESS(err);
12655
12656 VkBuffer buffer;
12657 uint32_t queue_family_index = 0;
12658 VkBufferCreateInfo buffer_create_info = {};
12659 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12660 buffer_create_info.size = 1024;
12661 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12662 buffer_create_info.queueFamilyIndexCount = 1;
12663 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12664
12665 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12666 ASSERT_VK_SUCCESS(err);
12667
12668 VkMemoryRequirements memory_reqs;
12669 VkDeviceMemory buffer_memory;
12670
12671 VkMemoryAllocateInfo memory_info = {};
12672 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12673 memory_info.allocationSize = 0;
12674 memory_info.memoryTypeIndex = 0;
12675
12676 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12677 memory_info.allocationSize = memory_reqs.size;
12678 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12679 ASSERT_TRUE(pass);
12680
12681 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12682 ASSERT_VK_SUCCESS(err);
12683 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12684 ASSERT_VK_SUCCESS(err);
12685
12686 VkBufferView view;
12687 VkBufferViewCreateInfo bvci = {};
12688 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12689 bvci.buffer = buffer;
12690 bvci.format = VK_FORMAT_R8_UNORM;
12691 bvci.range = VK_WHOLE_SIZE;
12692
12693 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12694 ASSERT_VK_SUCCESS(err);
12695
12696 VkWriteDescriptorSet descriptor_write = {};
12697 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12698 descriptor_write.dstSet = descriptor_set;
12699 descriptor_write.dstBinding = 0;
12700 descriptor_write.descriptorCount = 1;
12701 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12702 descriptor_write.pTexelBufferView = &view;
12703
12704 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012706 char const *vsSource =
12707 "#version 450\n"
12708 "\n"
12709 "out gl_PerVertex { \n"
12710 " vec4 gl_Position;\n"
12711 "};\n"
12712 "void main(){\n"
12713 " gl_Position = vec4(1);\n"
12714 "}\n";
12715 char const *fsSource =
12716 "#version 450\n"
12717 "\n"
12718 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12719 "layout(location=0) out vec4 x;\n"
12720 "void main(){\n"
12721 " x = imageLoad(s, 0);\n"
12722 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012723 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12724 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12725 VkPipelineObj pipe(m_device);
12726 pipe.AddShader(&vs);
12727 pipe.AddShader(&fs);
12728 pipe.AddColorAttachment();
12729 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12730
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012731 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012732
Tony Barbour552f6c02016-12-21 14:34:07 -070012733 m_commandBuffer->BeginCommandBuffer();
12734 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012735 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12736 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12737 VkRect2D scissor = {{0, 0}, {16, 16}};
12738 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12739 // Bind pipeline to cmd buffer
12740 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12741 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12742 &descriptor_set, 0, nullptr);
12743 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012744 m_commandBuffer->EndRenderPass();
12745 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012746
12747 VkSubmitInfo submit_info = {};
12748 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12749 submit_info.commandBufferCount = 1;
12750 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12751 // Submit cmd buffer and then destroy bufferView while in-flight
12752 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12753
12754 vkDestroyBufferView(m_device->device(), view, nullptr);
12755 m_errorMonitor->VerifyFound();
12756 vkQueueWaitIdle(m_device->m_queue);
12757 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012758 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12759 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012760 vkDestroyBufferView(m_device->device(), view, NULL);
12761 vkDestroyBuffer(m_device->device(), buffer, NULL);
12762 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12763 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12764 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12765 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12766}
12767
Tobin Ehlis209532e2016-09-07 13:52:18 -060012768TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12769 TEST_DESCRIPTION("Delete in-use sampler.");
12770
12771 ASSERT_NO_FATAL_FAILURE(InitState());
12772 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12773
12774 VkDescriptorPoolSize ds_type_count;
12775 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12776 ds_type_count.descriptorCount = 1;
12777
12778 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12779 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12780 ds_pool_ci.maxSets = 1;
12781 ds_pool_ci.poolSizeCount = 1;
12782 ds_pool_ci.pPoolSizes = &ds_type_count;
12783
12784 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012785 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012786 ASSERT_VK_SUCCESS(err);
12787
12788 VkSamplerCreateInfo sampler_ci = {};
12789 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12790 sampler_ci.pNext = NULL;
12791 sampler_ci.magFilter = VK_FILTER_NEAREST;
12792 sampler_ci.minFilter = VK_FILTER_NEAREST;
12793 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12794 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12795 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12796 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12797 sampler_ci.mipLodBias = 1.0;
12798 sampler_ci.anisotropyEnable = VK_FALSE;
12799 sampler_ci.maxAnisotropy = 1;
12800 sampler_ci.compareEnable = VK_FALSE;
12801 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12802 sampler_ci.minLod = 1.0;
12803 sampler_ci.maxLod = 1.0;
12804 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12805 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12806 VkSampler sampler;
12807
12808 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12809 ASSERT_VK_SUCCESS(err);
12810
12811 VkDescriptorSetLayoutBinding layout_binding;
12812 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012813 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012814 layout_binding.descriptorCount = 1;
12815 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12816 layout_binding.pImmutableSamplers = NULL;
12817
12818 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12819 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12820 ds_layout_ci.bindingCount = 1;
12821 ds_layout_ci.pBindings = &layout_binding;
12822 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012823 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012824 ASSERT_VK_SUCCESS(err);
12825
12826 VkDescriptorSetAllocateInfo alloc_info = {};
12827 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12828 alloc_info.descriptorSetCount = 1;
12829 alloc_info.descriptorPool = ds_pool;
12830 alloc_info.pSetLayouts = &ds_layout;
12831 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012832 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012833 ASSERT_VK_SUCCESS(err);
12834
12835 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12836 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12837 pipeline_layout_ci.pNext = NULL;
12838 pipeline_layout_ci.setLayoutCount = 1;
12839 pipeline_layout_ci.pSetLayouts = &ds_layout;
12840
12841 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012842 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012843 ASSERT_VK_SUCCESS(err);
12844
12845 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012846 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 -060012847 ASSERT_TRUE(image.initialized());
12848
12849 VkImageView view;
12850 VkImageViewCreateInfo ivci = {};
12851 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12852 ivci.image = image.handle();
12853 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12854 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12855 ivci.subresourceRange.layerCount = 1;
12856 ivci.subresourceRange.baseMipLevel = 0;
12857 ivci.subresourceRange.levelCount = 1;
12858 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12859
12860 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12861 ASSERT_VK_SUCCESS(err);
12862
12863 VkDescriptorImageInfo image_info{};
12864 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12865 image_info.imageView = view;
12866 image_info.sampler = sampler;
12867
12868 VkWriteDescriptorSet descriptor_write = {};
12869 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12870 descriptor_write.dstSet = descriptor_set;
12871 descriptor_write.dstBinding = 0;
12872 descriptor_write.descriptorCount = 1;
12873 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12874 descriptor_write.pImageInfo = &image_info;
12875
12876 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12877
12878 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012879 char const *vsSource =
12880 "#version 450\n"
12881 "\n"
12882 "out gl_PerVertex { \n"
12883 " vec4 gl_Position;\n"
12884 "};\n"
12885 "void main(){\n"
12886 " gl_Position = vec4(1);\n"
12887 "}\n";
12888 char const *fsSource =
12889 "#version 450\n"
12890 "\n"
12891 "layout(set=0, binding=0) uniform sampler2D s;\n"
12892 "layout(location=0) out vec4 x;\n"
12893 "void main(){\n"
12894 " x = texture(s, vec2(1));\n"
12895 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012896 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12897 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12898 VkPipelineObj pipe(m_device);
12899 pipe.AddShader(&vs);
12900 pipe.AddShader(&fs);
12901 pipe.AddColorAttachment();
12902 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12903
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012905
Tony Barbour552f6c02016-12-21 14:34:07 -070012906 m_commandBuffer->BeginCommandBuffer();
12907 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012908 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012909 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12910 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12911 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012912
12913 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12914 VkRect2D scissor = {{0, 0}, {16, 16}};
12915 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12916 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12917
Tobin Ehlis209532e2016-09-07 13:52:18 -060012918 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012919 m_commandBuffer->EndRenderPass();
12920 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012921 // Submit cmd buffer then destroy sampler
12922 VkSubmitInfo submit_info = {};
12923 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12924 submit_info.commandBufferCount = 1;
12925 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12926 // Submit cmd buffer and then destroy sampler while in-flight
12927 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12928
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012929 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012930 m_errorMonitor->VerifyFound();
12931 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012932
Tobin Ehlis209532e2016-09-07 13:52:18 -060012933 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012934 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12935 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012936 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012937 vkDestroyImageView(m_device->device(), view, NULL);
12938 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12939 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12940 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12941}
12942
Mark Mueller1cd9f412016-08-25 13:23:52 -060012943TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012944 TEST_DESCRIPTION(
12945 "Call VkQueueSubmit with a semaphore that is already "
12946 "signaled but not waited on by the queue. Wait on a "
12947 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012948
12949 ASSERT_NO_FATAL_FAILURE(InitState());
12950 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12951
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012952 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 -070012953 const char *invalid_fence_wait_message =
12954 " which has not been submitted on a Queue or during "
12955 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012956
Tony Barbour552f6c02016-12-21 14:34:07 -070012957 m_commandBuffer->BeginCommandBuffer();
12958 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012959
12960 VkSemaphoreCreateInfo semaphore_create_info = {};
12961 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12962 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012963 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012964 VkSubmitInfo submit_info = {};
12965 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12966 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012967 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012968 submit_info.signalSemaphoreCount = 1;
12969 submit_info.pSignalSemaphores = &semaphore;
12970 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012971 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012972 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012973 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012974 m_commandBuffer->BeginCommandBuffer();
12975 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060012977 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12978 m_errorMonitor->VerifyFound();
12979
Mark Mueller1cd9f412016-08-25 13:23:52 -060012980 VkFenceCreateInfo fence_create_info = {};
12981 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12982 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012983 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060012984
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060012986 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
12987 m_errorMonitor->VerifyFound();
12988
Mark Mueller4042b652016-09-05 22:52:21 -060012989 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060012990 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060012991 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12992}
12993
Tobin Ehlis4af23302016-07-19 10:50:30 -060012994TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012995 TEST_DESCRIPTION(
12996 "Bind a secondary command buffer with with a framebuffer "
12997 "that does not match the framebuffer for the active "
12998 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060012999 ASSERT_NO_FATAL_FAILURE(InitState());
13000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13001
13002 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013003 VkAttachmentDescription attachment = {0,
13004 VK_FORMAT_B8G8R8A8_UNORM,
13005 VK_SAMPLE_COUNT_1_BIT,
13006 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13007 VK_ATTACHMENT_STORE_OP_STORE,
13008 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13009 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13010 VK_IMAGE_LAYOUT_UNDEFINED,
13011 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013012
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013013 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013014
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013015 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013016
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013017 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013018
13019 VkRenderPass rp;
13020 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13021 ASSERT_VK_SUCCESS(err);
13022
13023 // A compatible framebuffer.
13024 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013025 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 -060013026 ASSERT_TRUE(image.initialized());
13027
13028 VkImageViewCreateInfo ivci = {
13029 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13030 nullptr,
13031 0,
13032 image.handle(),
13033 VK_IMAGE_VIEW_TYPE_2D,
13034 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013035 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13036 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013037 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13038 };
13039 VkImageView view;
13040 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13041 ASSERT_VK_SUCCESS(err);
13042
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013043 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013044 VkFramebuffer fb;
13045 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13046 ASSERT_VK_SUCCESS(err);
13047
13048 VkCommandBufferAllocateInfo cbai = {};
13049 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13050 cbai.commandPool = m_commandPool;
13051 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13052 cbai.commandBufferCount = 1;
13053
13054 VkCommandBuffer sec_cb;
13055 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13056 ASSERT_VK_SUCCESS(err);
13057 VkCommandBufferBeginInfo cbbi = {};
13058 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013059 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013060 cbii.renderPass = renderPass();
13061 cbii.framebuffer = fb;
13062 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13063 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013064 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 -060013065 cbbi.pInheritanceInfo = &cbii;
13066 vkBeginCommandBuffer(sec_cb, &cbbi);
13067 vkEndCommandBuffer(sec_cb);
13068
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013069 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013070 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13071 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013072
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013073 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013074 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013075 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13076 m_errorMonitor->VerifyFound();
13077 // Cleanup
13078 vkDestroyImageView(m_device->device(), view, NULL);
13079 vkDestroyRenderPass(m_device->device(), rp, NULL);
13080 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13081}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013082
13083TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013084 TEST_DESCRIPTION(
13085 "If logicOp is available on the device, set it to an "
13086 "invalid value. If logicOp is not available, attempt to "
13087 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013088 ASSERT_NO_FATAL_FAILURE(InitState());
13089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13090
13091 auto features = m_device->phy().features();
13092 // Set the expected error depending on whether or not logicOp available
13093 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13095 "If logic operations feature not "
13096 "enabled, logicOpEnable must be "
13097 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013098 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013100 }
13101 // Create a pipeline using logicOp
13102 VkResult err;
13103
13104 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13105 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13106
13107 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013108 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013109 ASSERT_VK_SUCCESS(err);
13110
13111 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13112 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13113 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013114 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013115 vp_state_ci.pViewports = &vp;
13116 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013117 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013118 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013119
13120 VkPipelineShaderStageCreateInfo shaderStages[2];
13121 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13122
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013123 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13124 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013125 shaderStages[0] = vs.GetStageCreateInfo();
13126 shaderStages[1] = fs.GetStageCreateInfo();
13127
13128 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13129 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13130
13131 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13132 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13133 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13134
13135 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13136 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013137 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013138
13139 VkPipelineColorBlendAttachmentState att = {};
13140 att.blendEnable = VK_FALSE;
13141 att.colorWriteMask = 0xf;
13142
13143 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13144 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13145 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13146 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013147 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013148 cb_ci.attachmentCount = 1;
13149 cb_ci.pAttachments = &att;
13150
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013151 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13152 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13153 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13154
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013155 VkGraphicsPipelineCreateInfo gp_ci = {};
13156 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13157 gp_ci.stageCount = 2;
13158 gp_ci.pStages = shaderStages;
13159 gp_ci.pVertexInputState = &vi_ci;
13160 gp_ci.pInputAssemblyState = &ia_ci;
13161 gp_ci.pViewportState = &vp_state_ci;
13162 gp_ci.pRasterizationState = &rs_ci;
13163 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013164 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013165 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13166 gp_ci.layout = pipeline_layout;
13167 gp_ci.renderPass = renderPass();
13168
13169 VkPipelineCacheCreateInfo pc_ci = {};
13170 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13171
13172 VkPipeline pipeline;
13173 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013174 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013175 ASSERT_VK_SUCCESS(err);
13176
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013177 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013178 m_errorMonitor->VerifyFound();
13179 if (VK_SUCCESS == err) {
13180 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13181 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013182 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13183 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13184}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013185
Mike Stroyanaccf7692015-05-12 16:00:45 -060013186#if GTEST_IS_THREADSAFE
13187struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013188 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013189 VkEvent event;
13190 bool bailout;
13191};
13192
Karl Schultz6addd812016-02-02 17:17:23 -070013193extern "C" void *AddToCommandBuffer(void *arg) {
13194 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013195
Mike Stroyana6d14942016-07-13 15:10:05 -060013196 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013197 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013198 if (data->bailout) {
13199 break;
13200 }
13201 }
13202 return NULL;
13203}
13204
Karl Schultz6addd812016-02-02 17:17:23 -070013205TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013206 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013207
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013208 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013209
Mike Stroyanaccf7692015-05-12 16:00:45 -060013210 ASSERT_NO_FATAL_FAILURE(InitState());
13211 ASSERT_NO_FATAL_FAILURE(InitViewport());
13212 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13213
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013214 // Calls AllocateCommandBuffers
13215 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013216
13217 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013218 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013219
13220 VkEventCreateInfo event_info;
13221 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013222 VkResult err;
13223
13224 memset(&event_info, 0, sizeof(event_info));
13225 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13226
Chia-I Wuf7458c52015-10-26 21:10:41 +080013227 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013228 ASSERT_VK_SUCCESS(err);
13229
Mike Stroyanaccf7692015-05-12 16:00:45 -060013230 err = vkResetEvent(device(), event);
13231 ASSERT_VK_SUCCESS(err);
13232
13233 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013234 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013235 data.event = event;
13236 data.bailout = false;
13237 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013238
13239 // First do some correct operations using multiple threads.
13240 // Add many entries to command buffer from another thread.
13241 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13242 // Make non-conflicting calls from this thread at the same time.
13243 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013244 uint32_t count;
13245 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013246 }
13247 test_platform_thread_join(thread, NULL);
13248
13249 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013250 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013251 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013252 // Add many entries to command buffer from this thread at the same time.
13253 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013254
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013255 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013256 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013257
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013258 m_errorMonitor->SetBailout(NULL);
13259
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013260 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013261
Chia-I Wuf7458c52015-10-26 21:10:41 +080013262 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013263}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013264#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013265
Karl Schultz6addd812016-02-02 17:17:23 -070013266TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013267 TEST_DESCRIPTION(
13268 "Test that an error is produced for a spirv module "
13269 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013272
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013273 ASSERT_NO_FATAL_FAILURE(InitState());
13274 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13275
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013276 VkShaderModule module;
13277 VkShaderModuleCreateInfo moduleCreateInfo;
13278 struct icd_spv_header spv;
13279
13280 spv.magic = ICD_SPV_MAGIC;
13281 spv.version = ICD_SPV_VERSION;
13282 spv.gen_magic = 0;
13283
13284 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13285 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013286 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013287 moduleCreateInfo.codeSize = 4;
13288 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013289 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013290
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013291 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013292}
13293
Karl Schultz6addd812016-02-02 17:17:23 -070013294TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013295 TEST_DESCRIPTION(
13296 "Test that an error is produced for a spirv module "
13297 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013298
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013299 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013300
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013301 ASSERT_NO_FATAL_FAILURE(InitState());
13302 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13303
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013304 VkShaderModule module;
13305 VkShaderModuleCreateInfo moduleCreateInfo;
13306 struct icd_spv_header spv;
13307
13308 spv.magic = ~ICD_SPV_MAGIC;
13309 spv.version = ICD_SPV_VERSION;
13310 spv.gen_magic = 0;
13311
13312 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13313 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013314 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013315 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13316 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013317 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013318
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013319 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013320}
13321
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013322#if 0
13323// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013324TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013326 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013327
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013328 ASSERT_NO_FATAL_FAILURE(InitState());
13329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13330
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013331 VkShaderModule module;
13332 VkShaderModuleCreateInfo moduleCreateInfo;
13333 struct icd_spv_header spv;
13334
13335 spv.magic = ICD_SPV_MAGIC;
13336 spv.version = ~ICD_SPV_VERSION;
13337 spv.gen_magic = 0;
13338
13339 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13340 moduleCreateInfo.pNext = NULL;
13341
Karl Schultz6addd812016-02-02 17:17:23 -070013342 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013343 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13344 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013345 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013346
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013347 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013348}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013349#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013350
Karl Schultz6addd812016-02-02 17:17:23 -070013351TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013352 TEST_DESCRIPTION(
13353 "Test that a warning is produced for a vertex output that "
13354 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013356
Chris Forbes9f7ff632015-05-25 11:13:08 +120013357 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013358 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013359
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013360 char const *vsSource =
13361 "#version 450\n"
13362 "\n"
13363 "layout(location=0) out float x;\n"
13364 "out gl_PerVertex {\n"
13365 " vec4 gl_Position;\n"
13366 "};\n"
13367 "void main(){\n"
13368 " gl_Position = vec4(1);\n"
13369 " x = 0;\n"
13370 "}\n";
13371 char const *fsSource =
13372 "#version 450\n"
13373 "\n"
13374 "layout(location=0) out vec4 color;\n"
13375 "void main(){\n"
13376 " color = vec4(1);\n"
13377 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013378
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013379 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13380 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013381
13382 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013383 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013384 pipe.AddShader(&vs);
13385 pipe.AddShader(&fs);
13386
Chris Forbes9f7ff632015-05-25 11:13:08 +120013387 VkDescriptorSetObj descriptorSet(m_device);
13388 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013389 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013390
Tony Barbour5781e8f2015-08-04 16:23:11 -060013391 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013392
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013393 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013394}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013395
Mark Mueller098c9cb2016-09-08 09:01:57 -060013396TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13397 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13398
13399 ASSERT_NO_FATAL_FAILURE(InitState());
13400 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13401
13402 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013403 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013404
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013405 char const *vsSource =
13406 "#version 450\n"
13407 "\n"
13408 "out gl_PerVertex {\n"
13409 " vec4 gl_Position;\n"
13410 "};\n"
13411 "void main(){\n"
13412 " gl_Position = vec4(1);\n"
13413 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013414
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013415 char const *fsSource =
13416 "#version 450\n"
13417 "\n"
13418 "layout (constant_id = 0) const float r = 0.0f;\n"
13419 "layout(location = 0) out vec4 uFragColor;\n"
13420 "void main(){\n"
13421 " uFragColor = vec4(r,1,0,1);\n"
13422 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013423
13424 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13425 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13426
13427 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13428 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13429
13430 VkPipelineLayout pipeline_layout;
13431 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13432
13433 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13434 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13435 vp_state_create_info.viewportCount = 1;
13436 VkViewport viewport = {};
13437 vp_state_create_info.pViewports = &viewport;
13438 vp_state_create_info.scissorCount = 1;
13439 VkRect2D scissors = {};
13440 vp_state_create_info.pScissors = &scissors;
13441
13442 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13443
13444 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13445 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13446 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13447 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13448
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013449 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013450
13451 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13452 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13453
13454 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13455 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13456 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13457
13458 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13459 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13460 rasterization_state_create_info.pNext = nullptr;
13461 rasterization_state_create_info.lineWidth = 1.0f;
13462 rasterization_state_create_info.rasterizerDiscardEnable = true;
13463
13464 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13465 color_blend_attachment_state.blendEnable = VK_FALSE;
13466 color_blend_attachment_state.colorWriteMask = 0xf;
13467
13468 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13469 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13470 color_blend_state_create_info.attachmentCount = 1;
13471 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13472
13473 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13474 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13475 graphicspipe_create_info.stageCount = 2;
13476 graphicspipe_create_info.pStages = shader_stage_create_info;
13477 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13478 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13479 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13480 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13481 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13482 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13483 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13484 graphicspipe_create_info.layout = pipeline_layout;
13485 graphicspipe_create_info.renderPass = renderPass();
13486
13487 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13488 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13489
13490 VkPipelineCache pipelineCache;
13491 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13492
13493 // This structure maps constant ids to data locations.
13494 const VkSpecializationMapEntry entry =
13495 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013496 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013497
13498 uint32_t data = 1;
13499
13500 // Set up the info describing spec map and data
13501 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013502 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013503 };
13504 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13505
13506 VkPipeline pipeline;
13507 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13508 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13509 m_errorMonitor->VerifyFound();
13510
13511 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13512 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13513}
13514
13515TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13516 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13517
13518 ASSERT_NO_FATAL_FAILURE(InitState());
13519 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13520
13521 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13522
13523 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13524 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13525 descriptor_pool_type_count[0].descriptorCount = 1;
13526 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13527 descriptor_pool_type_count[1].descriptorCount = 1;
13528
13529 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13530 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13531 descriptor_pool_create_info.maxSets = 1;
13532 descriptor_pool_create_info.poolSizeCount = 2;
13533 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13534 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13535
13536 VkDescriptorPool descriptorset_pool;
13537 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13538
13539 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13540 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13541 descriptorset_layout_binding.descriptorCount = 1;
13542 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
13543
13544 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13545 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13546 descriptorset_layout_create_info.bindingCount = 1;
13547 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13548
13549 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013550 ASSERT_VK_SUCCESS(
13551 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013552
13553 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13554 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13555 descriptorset_allocate_info.descriptorSetCount = 1;
13556 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13557 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13558 VkDescriptorSet descriptorset;
13559 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13560
13561 // Challenge core_validation with a non uniform buffer type.
13562 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13563
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013564 char const *vsSource =
13565 "#version 450\n"
13566 "\n"
13567 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13568 " mat4 mvp;\n"
13569 "} ubuf;\n"
13570 "out gl_PerVertex {\n"
13571 " vec4 gl_Position;\n"
13572 "};\n"
13573 "void main(){\n"
13574 " gl_Position = ubuf.mvp * vec4(1);\n"
13575 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013576
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013577 char const *fsSource =
13578 "#version 450\n"
13579 "\n"
13580 "layout(location = 0) out vec4 uFragColor;\n"
13581 "void main(){\n"
13582 " uFragColor = vec4(0,1,0,1);\n"
13583 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013584
13585 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13586 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13587
13588 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13589 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13590 pipeline_layout_create_info.setLayoutCount = 1;
13591 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13592
13593 VkPipelineLayout pipeline_layout;
13594 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13595
13596 VkPipelineObj pipe(m_device);
13597 pipe.AddColorAttachment();
13598 pipe.AddShader(&vs);
13599 pipe.AddShader(&fs);
13600
13601 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13602 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13603 m_errorMonitor->VerifyFound();
13604
13605 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13606 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13607 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13608}
13609
13610TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13611 TEST_DESCRIPTION(
13612 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13613
13614 ASSERT_NO_FATAL_FAILURE(InitState());
13615 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13616
13617 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13618
13619 VkDescriptorPoolSize descriptor_pool_type_count = {};
13620 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13621 descriptor_pool_type_count.descriptorCount = 1;
13622
13623 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13624 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13625 descriptor_pool_create_info.maxSets = 1;
13626 descriptor_pool_create_info.poolSizeCount = 1;
13627 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13628 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13629
13630 VkDescriptorPool descriptorset_pool;
13631 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13632
13633 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13634 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13635 descriptorset_layout_binding.descriptorCount = 1;
13636 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13637 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13638
13639 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13640 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13641 descriptorset_layout_create_info.bindingCount = 1;
13642 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13643
13644 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013645 ASSERT_VK_SUCCESS(
13646 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013647
13648 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13649 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13650 descriptorset_allocate_info.descriptorSetCount = 1;
13651 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13652 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13653 VkDescriptorSet descriptorset;
13654 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13655
13656 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13657
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013658 char const *vsSource =
13659 "#version 450\n"
13660 "\n"
13661 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13662 " mat4 mvp;\n"
13663 "} ubuf;\n"
13664 "out gl_PerVertex {\n"
13665 " vec4 gl_Position;\n"
13666 "};\n"
13667 "void main(){\n"
13668 " gl_Position = ubuf.mvp * vec4(1);\n"
13669 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013670
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013671 char const *fsSource =
13672 "#version 450\n"
13673 "\n"
13674 "layout(location = 0) out vec4 uFragColor;\n"
13675 "void main(){\n"
13676 " uFragColor = vec4(0,1,0,1);\n"
13677 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013678
13679 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13680 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13681
13682 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13683 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13684 pipeline_layout_create_info.setLayoutCount = 1;
13685 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13686
13687 VkPipelineLayout pipeline_layout;
13688 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13689
13690 VkPipelineObj pipe(m_device);
13691 pipe.AddColorAttachment();
13692 pipe.AddShader(&vs);
13693 pipe.AddShader(&fs);
13694
13695 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13696 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13697 m_errorMonitor->VerifyFound();
13698
13699 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13700 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13701 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13702}
13703
13704TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013705 TEST_DESCRIPTION(
13706 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13707 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013708
13709 ASSERT_NO_FATAL_FAILURE(InitState());
13710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13711
13712 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013713 "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 -060013714
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013715 char const *vsSource =
13716 "#version 450\n"
13717 "\n"
13718 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13719 "out gl_PerVertex {\n"
13720 " vec4 gl_Position;\n"
13721 "};\n"
13722 "void main(){\n"
13723 " gl_Position = vec4(consts.x);\n"
13724 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013725
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013726 char const *fsSource =
13727 "#version 450\n"
13728 "\n"
13729 "layout(location = 0) out vec4 uFragColor;\n"
13730 "void main(){\n"
13731 " uFragColor = vec4(0,1,0,1);\n"
13732 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013733
13734 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13735 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13736
13737 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13738 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13739
13740 // Set up a push constant range
13741 VkPushConstantRange push_constant_ranges = {};
13742 // Set to the wrong stage to challenge core_validation
13743 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13744 push_constant_ranges.size = 4;
13745
13746 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13747 pipeline_layout_create_info.pushConstantRangeCount = 1;
13748
13749 VkPipelineLayout pipeline_layout;
13750 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13751
13752 VkPipelineObj pipe(m_device);
13753 pipe.AddColorAttachment();
13754 pipe.AddShader(&vs);
13755 pipe.AddShader(&fs);
13756
13757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13758 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13759 m_errorMonitor->VerifyFound();
13760
13761 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13762}
13763
13764TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13765 TEST_DESCRIPTION(
13766 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13767
13768 ASSERT_NO_FATAL_FAILURE(InitState());
13769 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13770
13771 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013772 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013773
13774 // Some awkward steps are required to test with custom device features.
13775 std::vector<const char *> device_extension_names;
13776 auto features = m_device->phy().features();
13777 // Disable support for 64 bit floats
13778 features.shaderFloat64 = false;
13779 // The sacrificial device object
13780 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13781
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013782 char const *vsSource =
13783 "#version 450\n"
13784 "\n"
13785 "out gl_PerVertex {\n"
13786 " vec4 gl_Position;\n"
13787 "};\n"
13788 "void main(){\n"
13789 " gl_Position = vec4(1);\n"
13790 "}\n";
13791 char const *fsSource =
13792 "#version 450\n"
13793 "\n"
13794 "layout(location=0) out vec4 color;\n"
13795 "void main(){\n"
13796 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13797 " color = vec4(green);\n"
13798 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013799
13800 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13801 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13802
13803 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013804
13805 VkPipelineObj pipe(&test_device);
13806 pipe.AddColorAttachment();
13807 pipe.AddShader(&vs);
13808 pipe.AddShader(&fs);
13809
13810 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13811 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13812 VkPipelineLayout pipeline_layout;
13813 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13814
13815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13816 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13817 m_errorMonitor->VerifyFound();
13818
13819 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13820}
13821
13822TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13823 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13824
13825 ASSERT_NO_FATAL_FAILURE(InitState());
13826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13827
13828 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13829
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013830 char const *vsSource =
13831 "#version 450\n"
13832 "\n"
13833 "out gl_PerVertex {\n"
13834 " vec4 gl_Position;\n"
13835 "};\n"
13836 "layout(xfb_buffer = 1) out;"
13837 "void main(){\n"
13838 " gl_Position = vec4(1);\n"
13839 "}\n";
13840 char const *fsSource =
13841 "#version 450\n"
13842 "\n"
13843 "layout(location=0) out vec4 color;\n"
13844 "void main(){\n"
13845 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13846 " color = vec4(green);\n"
13847 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013848
13849 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13850 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13851
13852 VkPipelineObj pipe(m_device);
13853 pipe.AddColorAttachment();
13854 pipe.AddShader(&vs);
13855 pipe.AddShader(&fs);
13856
13857 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13858 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13859 VkPipelineLayout pipeline_layout;
13860 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13861
13862 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13863 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13864 m_errorMonitor->VerifyFound();
13865
13866 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13867}
13868
Karl Schultz6addd812016-02-02 17:17:23 -070013869TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013870 TEST_DESCRIPTION(
13871 "Test that an error is produced for a fragment shader input "
13872 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013873
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013874 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013875
Chris Forbes59cb88d2015-05-25 11:13:13 +120013876 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013877 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013878
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013879 char const *vsSource =
13880 "#version 450\n"
13881 "\n"
13882 "out gl_PerVertex {\n"
13883 " vec4 gl_Position;\n"
13884 "};\n"
13885 "void main(){\n"
13886 " gl_Position = vec4(1);\n"
13887 "}\n";
13888 char const *fsSource =
13889 "#version 450\n"
13890 "\n"
13891 "layout(location=0) in float x;\n"
13892 "layout(location=0) out vec4 color;\n"
13893 "void main(){\n"
13894 " color = vec4(x);\n"
13895 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013896
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013897 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13898 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013899
13900 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013901 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013902 pipe.AddShader(&vs);
13903 pipe.AddShader(&fs);
13904
Chris Forbes59cb88d2015-05-25 11:13:13 +120013905 VkDescriptorSetObj descriptorSet(m_device);
13906 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013907 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013908
Tony Barbour5781e8f2015-08-04 16:23:11 -060013909 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013910
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013911 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013912}
13913
Karl Schultz6addd812016-02-02 17:17:23 -070013914TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013915 TEST_DESCRIPTION(
13916 "Test that an error is produced for a fragment shader input "
13917 "within an interace block, which is not present in the outputs "
13918 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013919 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013920
13921 ASSERT_NO_FATAL_FAILURE(InitState());
13922 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13923
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013924 char const *vsSource =
13925 "#version 450\n"
13926 "\n"
13927 "out gl_PerVertex {\n"
13928 " vec4 gl_Position;\n"
13929 "};\n"
13930 "void main(){\n"
13931 " gl_Position = vec4(1);\n"
13932 "}\n";
13933 char const *fsSource =
13934 "#version 450\n"
13935 "\n"
13936 "in block { layout(location=0) float x; } ins;\n"
13937 "layout(location=0) out vec4 color;\n"
13938 "void main(){\n"
13939 " color = vec4(ins.x);\n"
13940 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013941
13942 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13943 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13944
13945 VkPipelineObj pipe(m_device);
13946 pipe.AddColorAttachment();
13947 pipe.AddShader(&vs);
13948 pipe.AddShader(&fs);
13949
13950 VkDescriptorSetObj descriptorSet(m_device);
13951 descriptorSet.AppendDummy();
13952 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13953
13954 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013956 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013957}
13958
Karl Schultz6addd812016-02-02 17:17:23 -070013959TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013960 TEST_DESCRIPTION(
13961 "Test that an error is produced for mismatched array sizes "
13962 "across the vertex->fragment shader interface");
13963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13964 "Type mismatch on location 0.0: 'ptr to "
13965 "output arr[2] of float32' vs 'ptr to "
13966 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013967
13968 ASSERT_NO_FATAL_FAILURE(InitState());
13969 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13970
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013971 char const *vsSource =
13972 "#version 450\n"
13973 "\n"
13974 "layout(location=0) out float x[2];\n"
13975 "out gl_PerVertex {\n"
13976 " vec4 gl_Position;\n"
13977 "};\n"
13978 "void main(){\n"
13979 " x[0] = 0; x[1] = 0;\n"
13980 " gl_Position = vec4(1);\n"
13981 "}\n";
13982 char const *fsSource =
13983 "#version 450\n"
13984 "\n"
13985 "layout(location=0) in float x[1];\n"
13986 "layout(location=0) out vec4 color;\n"
13987 "void main(){\n"
13988 " color = vec4(x[0]);\n"
13989 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130013990
13991 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13992 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13993
13994 VkPipelineObj pipe(m_device);
13995 pipe.AddColorAttachment();
13996 pipe.AddShader(&vs);
13997 pipe.AddShader(&fs);
13998
13999 VkDescriptorSetObj descriptorSet(m_device);
14000 descriptorSet.AppendDummy();
14001 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14002
14003 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14004
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014005 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014006}
14007
Karl Schultz6addd812016-02-02 17:17:23 -070014008TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014009 TEST_DESCRIPTION(
14010 "Test that an error is produced for mismatched types across "
14011 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014013
Chris Forbesb56af562015-05-25 11:13:17 +120014014 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014015 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014016
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014017 char const *vsSource =
14018 "#version 450\n"
14019 "\n"
14020 "layout(location=0) out int x;\n"
14021 "out gl_PerVertex {\n"
14022 " vec4 gl_Position;\n"
14023 "};\n"
14024 "void main(){\n"
14025 " x = 0;\n"
14026 " gl_Position = vec4(1);\n"
14027 "}\n";
14028 char const *fsSource =
14029 "#version 450\n"
14030 "\n"
14031 "layout(location=0) in float x;\n" /* VS writes int */
14032 "layout(location=0) out vec4 color;\n"
14033 "void main(){\n"
14034 " color = vec4(x);\n"
14035 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014036
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014037 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14038 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014039
14040 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014041 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014042 pipe.AddShader(&vs);
14043 pipe.AddShader(&fs);
14044
Chris Forbesb56af562015-05-25 11:13:17 +120014045 VkDescriptorSetObj descriptorSet(m_device);
14046 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014047 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014048
Tony Barbour5781e8f2015-08-04 16:23:11 -060014049 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014050
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014051 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014052}
14053
Karl Schultz6addd812016-02-02 17:17:23 -070014054TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014055 TEST_DESCRIPTION(
14056 "Test that an error is produced for mismatched types across "
14057 "the vertex->fragment shader interface, when the variable is contained within "
14058 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014060
14061 ASSERT_NO_FATAL_FAILURE(InitState());
14062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14063
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014064 char const *vsSource =
14065 "#version 450\n"
14066 "\n"
14067 "out block { layout(location=0) int x; } outs;\n"
14068 "out gl_PerVertex {\n"
14069 " vec4 gl_Position;\n"
14070 "};\n"
14071 "void main(){\n"
14072 " outs.x = 0;\n"
14073 " gl_Position = vec4(1);\n"
14074 "}\n";
14075 char const *fsSource =
14076 "#version 450\n"
14077 "\n"
14078 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14079 "layout(location=0) out vec4 color;\n"
14080 "void main(){\n"
14081 " color = vec4(ins.x);\n"
14082 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014083
14084 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14085 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14086
14087 VkPipelineObj pipe(m_device);
14088 pipe.AddColorAttachment();
14089 pipe.AddShader(&vs);
14090 pipe.AddShader(&fs);
14091
14092 VkDescriptorSetObj descriptorSet(m_device);
14093 descriptorSet.AppendDummy();
14094 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14095
14096 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14097
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014098 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014099}
14100
14101TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014102 TEST_DESCRIPTION(
14103 "Test that an error is produced for location mismatches across "
14104 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14105 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014106 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 +130014107
14108 ASSERT_NO_FATAL_FAILURE(InitState());
14109 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14110
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014111 char const *vsSource =
14112 "#version 450\n"
14113 "\n"
14114 "out block { layout(location=1) float x; } outs;\n"
14115 "out gl_PerVertex {\n"
14116 " vec4 gl_Position;\n"
14117 "};\n"
14118 "void main(){\n"
14119 " outs.x = 0;\n"
14120 " gl_Position = vec4(1);\n"
14121 "}\n";
14122 char const *fsSource =
14123 "#version 450\n"
14124 "\n"
14125 "in block { layout(location=0) float x; } ins;\n"
14126 "layout(location=0) out vec4 color;\n"
14127 "void main(){\n"
14128 " color = vec4(ins.x);\n"
14129 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014130
14131 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14132 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14133
14134 VkPipelineObj pipe(m_device);
14135 pipe.AddColorAttachment();
14136 pipe.AddShader(&vs);
14137 pipe.AddShader(&fs);
14138
14139 VkDescriptorSetObj descriptorSet(m_device);
14140 descriptorSet.AppendDummy();
14141 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14142
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014143 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014144 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14145
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014146 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014147}
14148
14149TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014150 TEST_DESCRIPTION(
14151 "Test that an error is produced for component mismatches across the "
14152 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14153 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014154 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 +130014155
14156 ASSERT_NO_FATAL_FAILURE(InitState());
14157 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14158
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014159 char const *vsSource =
14160 "#version 450\n"
14161 "\n"
14162 "out block { layout(location=0, component=0) float x; } outs;\n"
14163 "out gl_PerVertex {\n"
14164 " vec4 gl_Position;\n"
14165 "};\n"
14166 "void main(){\n"
14167 " outs.x = 0;\n"
14168 " gl_Position = vec4(1);\n"
14169 "}\n";
14170 char const *fsSource =
14171 "#version 450\n"
14172 "\n"
14173 "in block { layout(location=0, component=1) float x; } ins;\n"
14174 "layout(location=0) out vec4 color;\n"
14175 "void main(){\n"
14176 " color = vec4(ins.x);\n"
14177 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014178
14179 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14180 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14181
14182 VkPipelineObj pipe(m_device);
14183 pipe.AddColorAttachment();
14184 pipe.AddShader(&vs);
14185 pipe.AddShader(&fs);
14186
14187 VkDescriptorSetObj descriptorSet(m_device);
14188 descriptorSet.AppendDummy();
14189 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14190
14191 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14192
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014193 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014194}
14195
Chris Forbes1f3b0152016-11-30 12:48:40 +130014196TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14197 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14198
14199 ASSERT_NO_FATAL_FAILURE(InitState());
14200 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14201
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014202 char const *vsSource =
14203 "#version 450\n"
14204 "layout(location=0) out mediump float x;\n"
14205 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14206 char const *fsSource =
14207 "#version 450\n"
14208 "layout(location=0) in highp float x;\n"
14209 "layout(location=0) out vec4 color;\n"
14210 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014211
14212 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14213 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14214
14215 VkPipelineObj pipe(m_device);
14216 pipe.AddColorAttachment();
14217 pipe.AddShader(&vs);
14218 pipe.AddShader(&fs);
14219
14220 VkDescriptorSetObj descriptorSet(m_device);
14221 descriptorSet.AppendDummy();
14222 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14223
14224 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14225
14226 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14227
14228 m_errorMonitor->VerifyFound();
14229}
14230
Chris Forbes870a39e2016-11-30 12:55:56 +130014231TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14232 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14233
14234 ASSERT_NO_FATAL_FAILURE(InitState());
14235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14236
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014237 char const *vsSource =
14238 "#version 450\n"
14239 "out block { layout(location=0) mediump float x; };\n"
14240 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14241 char const *fsSource =
14242 "#version 450\n"
14243 "in block { layout(location=0) highp float x; };\n"
14244 "layout(location=0) out vec4 color;\n"
14245 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014246
14247 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14248 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14249
14250 VkPipelineObj pipe(m_device);
14251 pipe.AddColorAttachment();
14252 pipe.AddShader(&vs);
14253 pipe.AddShader(&fs);
14254
14255 VkDescriptorSetObj descriptorSet(m_device);
14256 descriptorSet.AppendDummy();
14257 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14258
14259 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14260
14261 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14262
14263 m_errorMonitor->VerifyFound();
14264}
14265
Karl Schultz6addd812016-02-02 17:17:23 -070014266TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014267 TEST_DESCRIPTION(
14268 "Test that a warning is produced for a vertex attribute which is "
14269 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014271
Chris Forbesde136e02015-05-25 11:13:28 +120014272 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014273 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014274
14275 VkVertexInputBindingDescription input_binding;
14276 memset(&input_binding, 0, sizeof(input_binding));
14277
14278 VkVertexInputAttributeDescription input_attrib;
14279 memset(&input_attrib, 0, sizeof(input_attrib));
14280 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14281
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014282 char const *vsSource =
14283 "#version 450\n"
14284 "\n"
14285 "out gl_PerVertex {\n"
14286 " vec4 gl_Position;\n"
14287 "};\n"
14288 "void main(){\n"
14289 " gl_Position = vec4(1);\n"
14290 "}\n";
14291 char const *fsSource =
14292 "#version 450\n"
14293 "\n"
14294 "layout(location=0) out vec4 color;\n"
14295 "void main(){\n"
14296 " color = vec4(1);\n"
14297 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014298
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014299 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14300 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014301
14302 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014303 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014304 pipe.AddShader(&vs);
14305 pipe.AddShader(&fs);
14306
14307 pipe.AddVertexInputBindings(&input_binding, 1);
14308 pipe.AddVertexInputAttribs(&input_attrib, 1);
14309
Chris Forbesde136e02015-05-25 11:13:28 +120014310 VkDescriptorSetObj descriptorSet(m_device);
14311 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014312 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014313
Tony Barbour5781e8f2015-08-04 16:23:11 -060014314 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014315
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014316 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014317}
14318
Karl Schultz6addd812016-02-02 17:17:23 -070014319TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014320 TEST_DESCRIPTION(
14321 "Test that a warning is produced for a location mismatch on "
14322 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014324
14325 ASSERT_NO_FATAL_FAILURE(InitState());
14326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14327
14328 VkVertexInputBindingDescription input_binding;
14329 memset(&input_binding, 0, sizeof(input_binding));
14330
14331 VkVertexInputAttributeDescription input_attrib;
14332 memset(&input_attrib, 0, sizeof(input_attrib));
14333 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14334
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014335 char const *vsSource =
14336 "#version 450\n"
14337 "\n"
14338 "layout(location=1) in float x;\n"
14339 "out gl_PerVertex {\n"
14340 " vec4 gl_Position;\n"
14341 "};\n"
14342 "void main(){\n"
14343 " gl_Position = vec4(x);\n"
14344 "}\n";
14345 char const *fsSource =
14346 "#version 450\n"
14347 "\n"
14348 "layout(location=0) out vec4 color;\n"
14349 "void main(){\n"
14350 " color = vec4(1);\n"
14351 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014352
14353 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14354 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14355
14356 VkPipelineObj pipe(m_device);
14357 pipe.AddColorAttachment();
14358 pipe.AddShader(&vs);
14359 pipe.AddShader(&fs);
14360
14361 pipe.AddVertexInputBindings(&input_binding, 1);
14362 pipe.AddVertexInputAttribs(&input_attrib, 1);
14363
14364 VkDescriptorSetObj descriptorSet(m_device);
14365 descriptorSet.AppendDummy();
14366 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14367
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014368 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014369 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14370
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014371 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014372}
14373
Karl Schultz6addd812016-02-02 17:17:23 -070014374TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014375 TEST_DESCRIPTION(
14376 "Test that an error is produced for a vertex shader input which is not "
14377 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14379 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014380
Chris Forbes62e8e502015-05-25 11:13:29 +120014381 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014382 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014383
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014384 char const *vsSource =
14385 "#version 450\n"
14386 "\n"
14387 "layout(location=0) in vec4 x;\n" /* not provided */
14388 "out gl_PerVertex {\n"
14389 " vec4 gl_Position;\n"
14390 "};\n"
14391 "void main(){\n"
14392 " gl_Position = x;\n"
14393 "}\n";
14394 char const *fsSource =
14395 "#version 450\n"
14396 "\n"
14397 "layout(location=0) out vec4 color;\n"
14398 "void main(){\n"
14399 " color = vec4(1);\n"
14400 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014401
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014402 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14403 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014404
14405 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014406 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014407 pipe.AddShader(&vs);
14408 pipe.AddShader(&fs);
14409
Chris Forbes62e8e502015-05-25 11:13:29 +120014410 VkDescriptorSetObj descriptorSet(m_device);
14411 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014412 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014413
Tony Barbour5781e8f2015-08-04 16:23:11 -060014414 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014415
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014416 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014417}
14418
Karl Schultz6addd812016-02-02 17:17:23 -070014419TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014420 TEST_DESCRIPTION(
14421 "Test that an error is produced for a mismatch between the "
14422 "fundamental type (float/int/uint) of an attribute and the "
14423 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014424 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 -060014425
Chris Forbesc97d98e2015-05-25 11:13:31 +120014426 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014427 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014428
14429 VkVertexInputBindingDescription input_binding;
14430 memset(&input_binding, 0, sizeof(input_binding));
14431
14432 VkVertexInputAttributeDescription input_attrib;
14433 memset(&input_attrib, 0, sizeof(input_attrib));
14434 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14435
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014436 char const *vsSource =
14437 "#version 450\n"
14438 "\n"
14439 "layout(location=0) in int x;\n" /* attrib provided float */
14440 "out gl_PerVertex {\n"
14441 " vec4 gl_Position;\n"
14442 "};\n"
14443 "void main(){\n"
14444 " gl_Position = vec4(x);\n"
14445 "}\n";
14446 char const *fsSource =
14447 "#version 450\n"
14448 "\n"
14449 "layout(location=0) out vec4 color;\n"
14450 "void main(){\n"
14451 " color = vec4(1);\n"
14452 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014453
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014454 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14455 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014456
14457 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014458 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014459 pipe.AddShader(&vs);
14460 pipe.AddShader(&fs);
14461
14462 pipe.AddVertexInputBindings(&input_binding, 1);
14463 pipe.AddVertexInputAttribs(&input_attrib, 1);
14464
Chris Forbesc97d98e2015-05-25 11:13:31 +120014465 VkDescriptorSetObj descriptorSet(m_device);
14466 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014467 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014468
Tony Barbour5781e8f2015-08-04 16:23:11 -060014469 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014470
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014471 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014472}
14473
Chris Forbesc68b43c2016-04-06 11:18:47 +120014474TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014475 TEST_DESCRIPTION(
14476 "Test that an error is produced for a pipeline containing multiple "
14477 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014478 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14479 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014480
14481 ASSERT_NO_FATAL_FAILURE(InitState());
14482 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14483
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014484 char const *vsSource =
14485 "#version 450\n"
14486 "\n"
14487 "out gl_PerVertex {\n"
14488 " vec4 gl_Position;\n"
14489 "};\n"
14490 "void main(){\n"
14491 " gl_Position = vec4(1);\n"
14492 "}\n";
14493 char const *fsSource =
14494 "#version 450\n"
14495 "\n"
14496 "layout(location=0) out vec4 color;\n"
14497 "void main(){\n"
14498 " color = vec4(1);\n"
14499 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014500
14501 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14502 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14503
14504 VkPipelineObj pipe(m_device);
14505 pipe.AddColorAttachment();
14506 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014507 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014508 pipe.AddShader(&fs);
14509
14510 VkDescriptorSetObj descriptorSet(m_device);
14511 descriptorSet.AppendDummy();
14512 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14513
14514 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14515
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014516 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014517}
14518
Chris Forbes82ff92a2016-09-09 10:50:24 +120014519TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014520 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014521
14522 ASSERT_NO_FATAL_FAILURE(InitState());
14523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14524
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014525 char const *vsSource =
14526 "#version 450\n"
14527 "out gl_PerVertex {\n"
14528 " vec4 gl_Position;\n"
14529 "};\n"
14530 "void main(){\n"
14531 " gl_Position = vec4(0);\n"
14532 "}\n";
14533 char const *fsSource =
14534 "#version 450\n"
14535 "\n"
14536 "layout(location=0) out vec4 color;\n"
14537 "void main(){\n"
14538 " color = vec4(1);\n"
14539 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014540
14541 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14542 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14543
14544 VkPipelineObj pipe(m_device);
14545 pipe.AddColorAttachment();
14546 pipe.AddShader(&vs);
14547 pipe.AddShader(&fs);
14548
14549 VkDescriptorSetObj descriptorSet(m_device);
14550 descriptorSet.AppendDummy();
14551 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14552
14553 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14554
14555 m_errorMonitor->VerifyFound();
14556}
14557
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014558TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014559 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14560 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14561 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014562
14563 ASSERT_NO_FATAL_FAILURE(InitState());
14564 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14565
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014566 char const *vsSource =
14567 "#version 450\n"
14568 "void main(){ gl_Position = vec4(0); }\n";
14569 char const *fsSource =
14570 "#version 450\n"
14571 "\n"
14572 "layout(location=0) out vec4 color;\n"
14573 "void main(){\n"
14574 " color = vec4(1);\n"
14575 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014576
14577 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14578 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14579
14580 VkPipelineObj pipe(m_device);
14581 pipe.AddColorAttachment();
14582 pipe.AddShader(&vs);
14583 pipe.AddShader(&fs);
14584
14585 VkDescriptorSetObj descriptorSet(m_device);
14586 descriptorSet.AppendDummy();
14587 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14588
14589 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014590 {
14591 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14592 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14593 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014594 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014595 {
14596 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14597 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14598 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014599 },
14600 };
14601 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014602 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014603 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014604 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14605 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014606 VkRenderPass rp;
14607 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14608 ASSERT_VK_SUCCESS(err);
14609
14610 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14611
14612 m_errorMonitor->VerifyFound();
14613
14614 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14615}
14616
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014617TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014618 TEST_DESCRIPTION(
14619 "Test that an error is produced for a variable output from "
14620 "the TCS without the patch decoration, but consumed in the TES "
14621 "with the decoration.");
14622 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14623 "is per-vertex in tessellation control shader stage "
14624 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014625
14626 ASSERT_NO_FATAL_FAILURE(InitState());
14627 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14628
Chris Forbesc1e852d2016-04-04 19:26:42 +120014629 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014630 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014631 return;
14632 }
14633
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014634 char const *vsSource =
14635 "#version 450\n"
14636 "void main(){}\n";
14637 char const *tcsSource =
14638 "#version 450\n"
14639 "layout(location=0) out int x[];\n"
14640 "layout(vertices=3) out;\n"
14641 "void main(){\n"
14642 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14643 " gl_TessLevelInner[0] = 1;\n"
14644 " x[gl_InvocationID] = gl_InvocationID;\n"
14645 "}\n";
14646 char const *tesSource =
14647 "#version 450\n"
14648 "layout(triangles, equal_spacing, cw) in;\n"
14649 "layout(location=0) patch in int x;\n"
14650 "out gl_PerVertex { vec4 gl_Position; };\n"
14651 "void main(){\n"
14652 " gl_Position.xyz = gl_TessCoord;\n"
14653 " gl_Position.w = x;\n"
14654 "}\n";
14655 char const *fsSource =
14656 "#version 450\n"
14657 "layout(location=0) out vec4 color;\n"
14658 "void main(){\n"
14659 " color = vec4(1);\n"
14660 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014661
14662 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14663 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14664 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14665 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14666
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014667 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14668 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014669
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014670 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014671
14672 VkPipelineObj pipe(m_device);
14673 pipe.SetInputAssembly(&iasci);
14674 pipe.SetTessellation(&tsci);
14675 pipe.AddColorAttachment();
14676 pipe.AddShader(&vs);
14677 pipe.AddShader(&tcs);
14678 pipe.AddShader(&tes);
14679 pipe.AddShader(&fs);
14680
14681 VkDescriptorSetObj descriptorSet(m_device);
14682 descriptorSet.AppendDummy();
14683 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14684
14685 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14686
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014687 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014688}
14689
Karl Schultz6addd812016-02-02 17:17:23 -070014690TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014691 TEST_DESCRIPTION(
14692 "Test that an error is produced for a vertex attribute setup where multiple "
14693 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14695 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014696
Chris Forbes280ba2c2015-06-12 11:16:41 +120014697 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014699
14700 /* Two binding descriptions for binding 0 */
14701 VkVertexInputBindingDescription input_bindings[2];
14702 memset(input_bindings, 0, sizeof(input_bindings));
14703
14704 VkVertexInputAttributeDescription input_attrib;
14705 memset(&input_attrib, 0, sizeof(input_attrib));
14706 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14707
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014708 char const *vsSource =
14709 "#version 450\n"
14710 "\n"
14711 "layout(location=0) in float x;\n" /* attrib provided float */
14712 "out gl_PerVertex {\n"
14713 " vec4 gl_Position;\n"
14714 "};\n"
14715 "void main(){\n"
14716 " gl_Position = vec4(x);\n"
14717 "}\n";
14718 char const *fsSource =
14719 "#version 450\n"
14720 "\n"
14721 "layout(location=0) out vec4 color;\n"
14722 "void main(){\n"
14723 " color = vec4(1);\n"
14724 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014725
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014726 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14727 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014728
14729 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014730 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014731 pipe.AddShader(&vs);
14732 pipe.AddShader(&fs);
14733
14734 pipe.AddVertexInputBindings(input_bindings, 2);
14735 pipe.AddVertexInputAttribs(&input_attrib, 1);
14736
Chris Forbes280ba2c2015-06-12 11:16:41 +120014737 VkDescriptorSetObj descriptorSet(m_device);
14738 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014739 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014740
Tony Barbour5781e8f2015-08-04 16:23:11 -060014741 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014742
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014743 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014744}
Chris Forbes8f68b562015-05-25 11:13:32 +120014745
Karl Schultz6addd812016-02-02 17:17:23 -070014746TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014747 TEST_DESCRIPTION(
14748 "Test that an error is produced for a fragment shader which does not "
14749 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014751
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014752 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014753
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014754 char const *vsSource =
14755 "#version 450\n"
14756 "\n"
14757 "out gl_PerVertex {\n"
14758 " vec4 gl_Position;\n"
14759 "};\n"
14760 "void main(){\n"
14761 " gl_Position = vec4(1);\n"
14762 "}\n";
14763 char const *fsSource =
14764 "#version 450\n"
14765 "\n"
14766 "void main(){\n"
14767 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014768
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014769 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14770 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014771
14772 VkPipelineObj pipe(m_device);
14773 pipe.AddShader(&vs);
14774 pipe.AddShader(&fs);
14775
Chia-I Wu08accc62015-07-07 11:50:03 +080014776 /* set up CB 0, not written */
14777 pipe.AddColorAttachment();
14778 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014779
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014780 VkDescriptorSetObj descriptorSet(m_device);
14781 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014782 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014783
Tony Barbour5781e8f2015-08-04 16:23:11 -060014784 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014785
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014786 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014787}
14788
Karl Schultz6addd812016-02-02 17:17:23 -070014789TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014790 TEST_DESCRIPTION(
14791 "Test that a warning is produced for a fragment shader which provides a spurious "
14792 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014794 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014795
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014796 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014797
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014798 char const *vsSource =
14799 "#version 450\n"
14800 "\n"
14801 "out gl_PerVertex {\n"
14802 " vec4 gl_Position;\n"
14803 "};\n"
14804 "void main(){\n"
14805 " gl_Position = vec4(1);\n"
14806 "}\n";
14807 char const *fsSource =
14808 "#version 450\n"
14809 "\n"
14810 "layout(location=0) out vec4 x;\n"
14811 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14812 "void main(){\n"
14813 " x = vec4(1);\n"
14814 " y = vec4(1);\n"
14815 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014816
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014817 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14818 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014819
14820 VkPipelineObj pipe(m_device);
14821 pipe.AddShader(&vs);
14822 pipe.AddShader(&fs);
14823
Chia-I Wu08accc62015-07-07 11:50:03 +080014824 /* set up CB 0, not written */
14825 pipe.AddColorAttachment();
14826 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014827 /* FS writes CB 1, but we don't configure it */
14828
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014829 VkDescriptorSetObj descriptorSet(m_device);
14830 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014831 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014832
Tony Barbour5781e8f2015-08-04 16:23:11 -060014833 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014834
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014835 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014836}
14837
Karl Schultz6addd812016-02-02 17:17:23 -070014838TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014839 TEST_DESCRIPTION(
14840 "Test that an error is produced for a mismatch between the fundamental "
14841 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014843
Chris Forbesa36d69e2015-05-25 11:13:44 +120014844 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014845
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014846 char const *vsSource =
14847 "#version 450\n"
14848 "\n"
14849 "out gl_PerVertex {\n"
14850 " vec4 gl_Position;\n"
14851 "};\n"
14852 "void main(){\n"
14853 " gl_Position = vec4(1);\n"
14854 "}\n";
14855 char const *fsSource =
14856 "#version 450\n"
14857 "\n"
14858 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14859 "void main(){\n"
14860 " x = ivec4(1);\n"
14861 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014862
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014863 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14864 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014865
14866 VkPipelineObj pipe(m_device);
14867 pipe.AddShader(&vs);
14868 pipe.AddShader(&fs);
14869
Chia-I Wu08accc62015-07-07 11:50:03 +080014870 /* set up CB 0; type is UNORM by default */
14871 pipe.AddColorAttachment();
14872 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014873
Chris Forbesa36d69e2015-05-25 11:13:44 +120014874 VkDescriptorSetObj descriptorSet(m_device);
14875 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014876 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014877
Tony Barbour5781e8f2015-08-04 16:23:11 -060014878 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014879
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014880 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014881}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014882
Karl Schultz6addd812016-02-02 17:17:23 -070014883TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014884 TEST_DESCRIPTION(
14885 "Test that an error is produced for a shader consuming a uniform "
14886 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014888
Chris Forbes556c76c2015-08-14 12:04:59 +120014889 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014890
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014891 char const *vsSource =
14892 "#version 450\n"
14893 "\n"
14894 "out gl_PerVertex {\n"
14895 " vec4 gl_Position;\n"
14896 "};\n"
14897 "void main(){\n"
14898 " gl_Position = vec4(1);\n"
14899 "}\n";
14900 char const *fsSource =
14901 "#version 450\n"
14902 "\n"
14903 "layout(location=0) out vec4 x;\n"
14904 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14905 "void main(){\n"
14906 " x = vec4(bar.y);\n"
14907 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014908
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014909 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14910 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014911
Chris Forbes556c76c2015-08-14 12:04:59 +120014912 VkPipelineObj pipe(m_device);
14913 pipe.AddShader(&vs);
14914 pipe.AddShader(&fs);
14915
14916 /* set up CB 0; type is UNORM by default */
14917 pipe.AddColorAttachment();
14918 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14919
14920 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014921 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014922
14923 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14924
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014925 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014926}
14927
Chris Forbes5c59e902016-02-26 16:56:09 +130014928TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014929 TEST_DESCRIPTION(
14930 "Test that an error is produced for a shader consuming push constants "
14931 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014933
14934 ASSERT_NO_FATAL_FAILURE(InitState());
14935
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014936 char const *vsSource =
14937 "#version 450\n"
14938 "\n"
14939 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14940 "out gl_PerVertex {\n"
14941 " vec4 gl_Position;\n"
14942 "};\n"
14943 "void main(){\n"
14944 " gl_Position = vec4(consts.x);\n"
14945 "}\n";
14946 char const *fsSource =
14947 "#version 450\n"
14948 "\n"
14949 "layout(location=0) out vec4 x;\n"
14950 "void main(){\n"
14951 " x = vec4(1);\n"
14952 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014953
14954 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14955 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14956
14957 VkPipelineObj pipe(m_device);
14958 pipe.AddShader(&vs);
14959 pipe.AddShader(&fs);
14960
14961 /* set up CB 0; type is UNORM by default */
14962 pipe.AddColorAttachment();
14963 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14964
14965 VkDescriptorSetObj descriptorSet(m_device);
14966 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14967
14968 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14969
14970 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014971 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014972}
14973
Chris Forbes3fb17902016-08-22 14:57:55 +120014974TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014975 TEST_DESCRIPTION(
14976 "Test that an error is produced for a shader consuming an input attachment "
14977 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120014978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14979 "consumes input attachment index 0 but not provided in subpass");
14980
14981 ASSERT_NO_FATAL_FAILURE(InitState());
14982
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014983 char const *vsSource =
14984 "#version 450\n"
14985 "\n"
14986 "out gl_PerVertex {\n"
14987 " vec4 gl_Position;\n"
14988 "};\n"
14989 "void main(){\n"
14990 " gl_Position = vec4(1);\n"
14991 "}\n";
14992 char const *fsSource =
14993 "#version 450\n"
14994 "\n"
14995 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
14996 "layout(location=0) out vec4 color;\n"
14997 "void main() {\n"
14998 " color = subpassLoad(x);\n"
14999 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015000
15001 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15002 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15003
15004 VkPipelineObj pipe(m_device);
15005 pipe.AddShader(&vs);
15006 pipe.AddShader(&fs);
15007 pipe.AddColorAttachment();
15008 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15009
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015010 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15011 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015012 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015013 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015014 ASSERT_VK_SUCCESS(err);
15015
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015016 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015017 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015018 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015019 ASSERT_VK_SUCCESS(err);
15020
15021 // error here.
15022 pipe.CreateVKPipeline(pl, renderPass());
15023
15024 m_errorMonitor->VerifyFound();
15025
15026 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15027 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15028}
15029
Chris Forbes5a9a0472016-08-22 16:02:09 +120015030TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015031 TEST_DESCRIPTION(
15032 "Test that an error is produced for a shader consuming an input attachment "
15033 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15035 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15036
15037 ASSERT_NO_FATAL_FAILURE(InitState());
15038
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015039 char const *vsSource =
15040 "#version 450\n"
15041 "\n"
15042 "out gl_PerVertex {\n"
15043 " vec4 gl_Position;\n"
15044 "};\n"
15045 "void main(){\n"
15046 " gl_Position = vec4(1);\n"
15047 "}\n";
15048 char const *fsSource =
15049 "#version 450\n"
15050 "\n"
15051 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15052 "layout(location=0) out vec4 color;\n"
15053 "void main() {\n"
15054 " color = subpassLoad(x);\n"
15055 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015056
15057 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15058 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15059
15060 VkPipelineObj pipe(m_device);
15061 pipe.AddShader(&vs);
15062 pipe.AddShader(&fs);
15063 pipe.AddColorAttachment();
15064 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015066 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15067 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015068 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015069 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015070 ASSERT_VK_SUCCESS(err);
15071
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015072 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015073 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015074 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015075 ASSERT_VK_SUCCESS(err);
15076
15077 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015078 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15079 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15080 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15081 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15082 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 +120015083 };
15084 VkAttachmentReference color = {
15085 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15086 };
15087 VkAttachmentReference input = {
15088 1, VK_IMAGE_LAYOUT_GENERAL,
15089 };
15090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015091 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015092
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015093 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015094 VkRenderPass rp;
15095 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15096 ASSERT_VK_SUCCESS(err);
15097
15098 // error here.
15099 pipe.CreateVKPipeline(pl, rp);
15100
15101 m_errorMonitor->VerifyFound();
15102
15103 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15104 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15105 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15106}
15107
Chris Forbes541f7b02016-08-22 15:30:27 +120015108TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015109 TEST_DESCRIPTION(
15110 "Test that an error is produced for a shader consuming an input attachment "
15111 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015112 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015113 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015114
15115 ASSERT_NO_FATAL_FAILURE(InitState());
15116
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015117 char const *vsSource =
15118 "#version 450\n"
15119 "\n"
15120 "out gl_PerVertex {\n"
15121 " vec4 gl_Position;\n"
15122 "};\n"
15123 "void main(){\n"
15124 " gl_Position = vec4(1);\n"
15125 "}\n";
15126 char const *fsSource =
15127 "#version 450\n"
15128 "\n"
15129 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15130 "layout(location=0) out vec4 color;\n"
15131 "void main() {\n"
15132 " color = subpassLoad(xs[0]);\n"
15133 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015134
15135 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15136 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15137
15138 VkPipelineObj pipe(m_device);
15139 pipe.AddShader(&vs);
15140 pipe.AddShader(&fs);
15141 pipe.AddColorAttachment();
15142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15143
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015144 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15145 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015146 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015147 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015148 ASSERT_VK_SUCCESS(err);
15149
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015150 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015151 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015152 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015153 ASSERT_VK_SUCCESS(err);
15154
15155 // error here.
15156 pipe.CreateVKPipeline(pl, renderPass());
15157
15158 m_errorMonitor->VerifyFound();
15159
15160 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15161 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15162}
15163
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015164TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015165 TEST_DESCRIPTION(
15166 "Test that an error is produced for a compute pipeline consuming a "
15167 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015168 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015169
15170 ASSERT_NO_FATAL_FAILURE(InitState());
15171
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015172 char const *csSource =
15173 "#version 450\n"
15174 "\n"
15175 "layout(local_size_x=1) in;\n"
15176 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15177 "void main(){\n"
15178 " x = vec4(1);\n"
15179 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015180
15181 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15182
15183 VkDescriptorSetObj descriptorSet(m_device);
15184 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15185
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015186 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15187 nullptr,
15188 0,
15189 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15190 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15191 descriptorSet.GetPipelineLayout(),
15192 VK_NULL_HANDLE,
15193 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015194
15195 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015196 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015197
15198 m_errorMonitor->VerifyFound();
15199
15200 if (err == VK_SUCCESS) {
15201 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15202 }
15203}
15204
Chris Forbes22a9b092016-07-19 14:34:05 +120015205TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015206 TEST_DESCRIPTION(
15207 "Test that an error is produced for a pipeline consuming a "
15208 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015209 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15210 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015211
15212 ASSERT_NO_FATAL_FAILURE(InitState());
15213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015214 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15215 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015216 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015217 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015218 ASSERT_VK_SUCCESS(err);
15219
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015220 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015221 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015222 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015223 ASSERT_VK_SUCCESS(err);
15224
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015225 char const *csSource =
15226 "#version 450\n"
15227 "\n"
15228 "layout(local_size_x=1) in;\n"
15229 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15230 "void main() {\n"
15231 " x.x = 1.0f;\n"
15232 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015233 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15234
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015235 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15236 nullptr,
15237 0,
15238 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15239 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15240 pl,
15241 VK_NULL_HANDLE,
15242 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015243
15244 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015245 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015246
15247 m_errorMonitor->VerifyFound();
15248
15249 if (err == VK_SUCCESS) {
15250 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15251 }
15252
15253 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15254 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15255}
15256
Chris Forbes50020592016-07-27 13:52:41 +120015257TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015258 TEST_DESCRIPTION(
15259 "Test that an error is produced when an image view type "
15260 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015261
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015262 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 +120015263
15264 ASSERT_NO_FATAL_FAILURE(InitState());
15265 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15266
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015267 char const *vsSource =
15268 "#version 450\n"
15269 "\n"
15270 "out gl_PerVertex { vec4 gl_Position; };\n"
15271 "void main() { gl_Position = vec4(0); }\n";
15272 char const *fsSource =
15273 "#version 450\n"
15274 "\n"
15275 "layout(set=0, binding=0) uniform sampler3D s;\n"
15276 "layout(location=0) out vec4 color;\n"
15277 "void main() {\n"
15278 " color = texture(s, vec3(0));\n"
15279 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015280 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15281 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15282
15283 VkPipelineObj pipe(m_device);
15284 pipe.AddShader(&vs);
15285 pipe.AddShader(&fs);
15286 pipe.AddColorAttachment();
15287
15288 VkTextureObj texture(m_device, nullptr);
15289 VkSamplerObj sampler(m_device);
15290
15291 VkDescriptorSetObj descriptorSet(m_device);
15292 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15293 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15294
15295 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15296 ASSERT_VK_SUCCESS(err);
15297
Tony Barbour552f6c02016-12-21 14:34:07 -070015298 m_commandBuffer->BeginCommandBuffer();
15299 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015300
15301 m_commandBuffer->BindPipeline(pipe);
15302 m_commandBuffer->BindDescriptorSet(descriptorSet);
15303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015304 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015305 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015306 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015307 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15308
15309 // error produced here.
15310 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15311
15312 m_errorMonitor->VerifyFound();
15313
Tony Barbour552f6c02016-12-21 14:34:07 -070015314 m_commandBuffer->EndRenderPass();
15315 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015316}
15317
Chris Forbes5533bfc2016-07-27 14:12:34 +120015318TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015319 TEST_DESCRIPTION(
15320 "Test that an error is produced when a multisampled images "
15321 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015322
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015323 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015324
15325 ASSERT_NO_FATAL_FAILURE(InitState());
15326 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15327
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015328 char const *vsSource =
15329 "#version 450\n"
15330 "\n"
15331 "out gl_PerVertex { vec4 gl_Position; };\n"
15332 "void main() { gl_Position = vec4(0); }\n";
15333 char const *fsSource =
15334 "#version 450\n"
15335 "\n"
15336 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15337 "layout(location=0) out vec4 color;\n"
15338 "void main() {\n"
15339 " color = texelFetch(s, ivec2(0), 0);\n"
15340 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015341 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15342 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15343
15344 VkPipelineObj pipe(m_device);
15345 pipe.AddShader(&vs);
15346 pipe.AddShader(&fs);
15347 pipe.AddColorAttachment();
15348
15349 VkTextureObj texture(m_device, nullptr);
15350 VkSamplerObj sampler(m_device);
15351
15352 VkDescriptorSetObj descriptorSet(m_device);
15353 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15354 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15355
15356 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15357 ASSERT_VK_SUCCESS(err);
15358
Tony Barbour552f6c02016-12-21 14:34:07 -070015359 m_commandBuffer->BeginCommandBuffer();
15360 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015361
15362 m_commandBuffer->BindPipeline(pipe);
15363 m_commandBuffer->BindDescriptorSet(descriptorSet);
15364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015365 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015366 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015367 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015368 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15369
15370 // error produced here.
15371 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15372
15373 m_errorMonitor->VerifyFound();
15374
Tony Barbour552f6c02016-12-21 14:34:07 -070015375 m_commandBuffer->EndRenderPass();
15376 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015377}
15378
Mark Youngc48c4c12016-04-11 14:26:49 -060015379TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015381
15382 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015383
15384 // Create an image
15385 VkImage image;
15386
Karl Schultz6addd812016-02-02 17:17:23 -070015387 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15388 const int32_t tex_width = 32;
15389 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015390
15391 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015392 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15393 image_create_info.pNext = NULL;
15394 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15395 image_create_info.format = tex_format;
15396 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015397 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015398 image_create_info.extent.depth = 1;
15399 image_create_info.mipLevels = 1;
15400 image_create_info.arrayLayers = 1;
15401 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15402 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15403 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15404 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015405
15406 // Introduce error by sending down a bogus width extent
15407 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015408 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015409
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015410 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015411}
15412
Mark Youngc48c4c12016-04-11 14:26:49 -060015413TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015414 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015415
15416 ASSERT_NO_FATAL_FAILURE(InitState());
15417
15418 // Create an image
15419 VkImage image;
15420
15421 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15422 const int32_t tex_width = 32;
15423 const int32_t tex_height = 32;
15424
15425 VkImageCreateInfo image_create_info = {};
15426 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15427 image_create_info.pNext = NULL;
15428 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15429 image_create_info.format = tex_format;
15430 image_create_info.extent.width = tex_width;
15431 image_create_info.extent.height = tex_height;
15432 image_create_info.extent.depth = 1;
15433 image_create_info.mipLevels = 1;
15434 image_create_info.arrayLayers = 1;
15435 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15436 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15437 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15438 image_create_info.flags = 0;
15439
15440 // Introduce error by sending down a bogus width extent
15441 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015442 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015443 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15444
15445 m_errorMonitor->VerifyFound();
15446}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015447
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015448TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015449 TEST_DESCRIPTION(
15450 "Create a render pass with an attachment description "
15451 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015452
15453 ASSERT_NO_FATAL_FAILURE(InitState());
15454 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15455
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015457
15458 VkAttachmentReference color_attach = {};
15459 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15460 color_attach.attachment = 0;
15461 VkSubpassDescription subpass = {};
15462 subpass.colorAttachmentCount = 1;
15463 subpass.pColorAttachments = &color_attach;
15464
15465 VkRenderPassCreateInfo rpci = {};
15466 rpci.subpassCount = 1;
15467 rpci.pSubpasses = &subpass;
15468 rpci.attachmentCount = 1;
15469 VkAttachmentDescription attach_desc = {};
15470 attach_desc.format = VK_FORMAT_UNDEFINED;
15471 rpci.pAttachments = &attach_desc;
15472 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15473 VkRenderPass rp;
15474 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15475
15476 m_errorMonitor->VerifyFound();
15477
15478 if (result == VK_SUCCESS) {
15479 vkDestroyRenderPass(m_device->device(), rp, NULL);
15480 }
15481}
15482
Karl Schultz6addd812016-02-02 17:17:23 -070015483TEST_F(VkLayerTest, InvalidImageView) {
15484 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015485
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015486 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015487
Tobin Ehliscde08892015-09-22 10:11:37 -060015488 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015489
Mike Stroyana3082432015-09-25 13:39:21 -060015490 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015491 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015492
Karl Schultz6addd812016-02-02 17:17:23 -070015493 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15494 const int32_t tex_width = 32;
15495 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015496
15497 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015498 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15499 image_create_info.pNext = NULL;
15500 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15501 image_create_info.format = tex_format;
15502 image_create_info.extent.width = tex_width;
15503 image_create_info.extent.height = tex_height;
15504 image_create_info.extent.depth = 1;
15505 image_create_info.mipLevels = 1;
15506 image_create_info.arrayLayers = 1;
15507 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15508 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15509 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15510 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015511
Chia-I Wuf7458c52015-10-26 21:10:41 +080015512 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015513 ASSERT_VK_SUCCESS(err);
15514
15515 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015516 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015517 image_view_create_info.image = image;
15518 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15519 image_view_create_info.format = tex_format;
15520 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015521 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015522 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015523 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015524
15525 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015526 m_errorMonitor->SetUnexpectedError(
15527 "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 -060015528 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015529
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015530 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015531 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015532}
Mike Stroyana3082432015-09-25 13:39:21 -060015533
Mark Youngd339ba32016-05-30 13:28:35 -060015534TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15535 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015537 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015538
15539 ASSERT_NO_FATAL_FAILURE(InitState());
15540
15541 // Create an image and try to create a view with no memory backing the image
15542 VkImage image;
15543
15544 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15545 const int32_t tex_width = 32;
15546 const int32_t tex_height = 32;
15547
15548 VkImageCreateInfo image_create_info = {};
15549 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15550 image_create_info.pNext = NULL;
15551 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15552 image_create_info.format = tex_format;
15553 image_create_info.extent.width = tex_width;
15554 image_create_info.extent.height = tex_height;
15555 image_create_info.extent.depth = 1;
15556 image_create_info.mipLevels = 1;
15557 image_create_info.arrayLayers = 1;
15558 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15559 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15560 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15561 image_create_info.flags = 0;
15562
15563 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15564 ASSERT_VK_SUCCESS(err);
15565
15566 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015567 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015568 image_view_create_info.image = image;
15569 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15570 image_view_create_info.format = tex_format;
15571 image_view_create_info.subresourceRange.layerCount = 1;
15572 image_view_create_info.subresourceRange.baseMipLevel = 0;
15573 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015574 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015575
15576 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015577 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015578
15579 m_errorMonitor->VerifyFound();
15580 vkDestroyImage(m_device->device(), image, NULL);
15581 // If last error is success, it still created the view, so delete it.
15582 if (err == VK_SUCCESS) {
15583 vkDestroyImageView(m_device->device(), view, NULL);
15584 }
Mark Youngd339ba32016-05-30 13:28:35 -060015585}
15586
Karl Schultz6addd812016-02-02 17:17:23 -070015587TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015588 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015590
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015591 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015592
Karl Schultz6addd812016-02-02 17:17:23 -070015593 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015594 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015595 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015596 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015597
15598 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015599 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015600 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015601 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15602 image_view_create_info.format = tex_format;
15603 image_view_create_info.subresourceRange.baseMipLevel = 0;
15604 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015605 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015606 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015607 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015608
15609 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015610 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015611
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015612 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015613}
15614
Mike Weiblena1e13f42017-02-09 21:25:59 -070015615TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15616 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15617
15618 ASSERT_NO_FATAL_FAILURE(InitState());
15619 VkSubresourceLayout subres_layout = {};
15620
15621 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15622 {
15623 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15624 VkImageObj img(m_device);
15625 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15626 ASSERT_TRUE(img.initialized());
15627
15628 VkImageSubresource subres = {};
15629 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15630 subres.mipLevel = 0;
15631 subres.arrayLayer = 0;
15632
15633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15634 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15635 m_errorMonitor->VerifyFound();
15636 }
15637
15638 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15639 {
15640 VkImageObj img(m_device);
15641 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15642 ASSERT_TRUE(img.initialized());
15643
15644 VkImageSubresource subres = {};
15645 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15646 subres.mipLevel = 0;
15647 subres.arrayLayer = 0;
15648
15649 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15651 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15652 m_errorMonitor->VerifyFound();
15653 }
15654
15655 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15656 {
15657 VkImageObj img(m_device);
15658 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15659 ASSERT_TRUE(img.initialized());
15660
15661 VkImageSubresource subres = {};
15662 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15663 subres.mipLevel = 1; // ERROR: triggers VU 00739
15664 subres.arrayLayer = 0;
15665
15666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15667 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15668 m_errorMonitor->VerifyFound();
15669 }
15670
15671 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15672 {
15673 VkImageObj img(m_device);
15674 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15675 ASSERT_TRUE(img.initialized());
15676
15677 VkImageSubresource subres = {};
15678 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15679 subres.mipLevel = 0;
15680 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15681
15682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15683 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15684 m_errorMonitor->VerifyFound();
15685 }
15686}
15687
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015688TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015689 VkResult err;
15690 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015691
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015693
Mike Stroyana3082432015-09-25 13:39:21 -060015694 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015695
15696 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015697 VkImage srcImage;
15698 VkImage dstImage;
15699 VkDeviceMemory srcMem;
15700 VkDeviceMemory destMem;
15701 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015702
15703 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015704 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15705 image_create_info.pNext = NULL;
15706 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15707 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15708 image_create_info.extent.width = 32;
15709 image_create_info.extent.height = 32;
15710 image_create_info.extent.depth = 1;
15711 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015712 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015713 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15714 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15715 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15716 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015717
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015718 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015719 ASSERT_VK_SUCCESS(err);
15720
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015721 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015722 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015723 ASSERT_VK_SUCCESS(err);
15724
15725 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015726 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015727 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15728 memAlloc.pNext = NULL;
15729 memAlloc.allocationSize = 0;
15730 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015731
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015732 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015733 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015734 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015735 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015736 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015737 ASSERT_VK_SUCCESS(err);
15738
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015739 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015740 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015741 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015742 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015743 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015744 ASSERT_VK_SUCCESS(err);
15745
15746 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15747 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015748 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015749 ASSERT_VK_SUCCESS(err);
15750
Tony Barbour552f6c02016-12-21 14:34:07 -070015751 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015752 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015753 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015754 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015755 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015756 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015757 copyRegion.srcOffset.x = 0;
15758 copyRegion.srcOffset.y = 0;
15759 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015760 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015761 copyRegion.dstSubresource.mipLevel = 0;
15762 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015763 // Introduce failure by forcing the dst layerCount to differ from src
15764 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015765 copyRegion.dstOffset.x = 0;
15766 copyRegion.dstOffset.y = 0;
15767 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015768 copyRegion.extent.width = 1;
15769 copyRegion.extent.height = 1;
15770 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015771 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015772 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015773
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015774 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015775
Chia-I Wuf7458c52015-10-26 21:10:41 +080015776 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015777 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015778 vkFreeMemory(m_device->device(), srcMem, NULL);
15779 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015780}
15781
Tony Barbourd6673642016-05-05 14:46:39 -060015782TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015783 TEST_DESCRIPTION("Creating images with unsuported formats ");
15784
15785 ASSERT_NO_FATAL_FAILURE(InitState());
15786 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15787 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015788 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 -060015789 VK_IMAGE_TILING_OPTIMAL, 0);
15790 ASSERT_TRUE(image.initialized());
15791
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015792 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015793 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015794 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015795 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15796 image_create_info.format = VK_FORMAT_UNDEFINED;
15797 image_create_info.extent.width = 32;
15798 image_create_info.extent.height = 32;
15799 image_create_info.extent.depth = 1;
15800 image_create_info.mipLevels = 1;
15801 image_create_info.arrayLayers = 1;
15802 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15803 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15804 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015805
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15807 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015808
15809 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015810 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15811 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15812 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15813 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015814 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15815 m_errorMonitor->VerifyFound();
15816
Tony Barbourd6673642016-05-05 14:46:39 -060015817 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015818 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015819 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15820 VkFormat format = static_cast<VkFormat>(f);
15821 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015822 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015823 unsupported = format;
15824 break;
15825 }
15826 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015827
Tony Barbourd6673642016-05-05 14:46:39 -060015828 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015829 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015831
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015832 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15833 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15834 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15835 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15836 m_errorMonitor->SetUnexpectedError(
15837 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15838 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15839 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015840 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015841 m_errorMonitor->VerifyFound();
15842 }
15843}
15844
15845TEST_F(VkLayerTest, ImageLayerViewTests) {
15846 VkResult ret;
15847 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15848
15849 ASSERT_NO_FATAL_FAILURE(InitState());
15850
15851 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015852 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 -060015853 VK_IMAGE_TILING_OPTIMAL, 0);
15854 ASSERT_TRUE(image.initialized());
15855
15856 VkImageView imgView;
15857 VkImageViewCreateInfo imgViewInfo = {};
15858 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15859 imgViewInfo.image = image.handle();
15860 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15861 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15862 imgViewInfo.subresourceRange.layerCount = 1;
15863 imgViewInfo.subresourceRange.baseMipLevel = 0;
15864 imgViewInfo.subresourceRange.levelCount = 1;
15865 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15866
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015868 // View can't have baseMipLevel >= image's mipLevels - Expect
15869 // VIEW_CREATE_ERROR
15870 imgViewInfo.subresourceRange.baseMipLevel = 1;
15871 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15872 m_errorMonitor->VerifyFound();
15873 imgViewInfo.subresourceRange.baseMipLevel = 0;
15874
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015876 // View can't have baseArrayLayer >= image's arraySize - Expect
15877 // VIEW_CREATE_ERROR
15878 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15879 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15880 m_errorMonitor->VerifyFound();
15881 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15882
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015884 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15885 imgViewInfo.subresourceRange.levelCount = 0;
15886 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15887 m_errorMonitor->VerifyFound();
15888 imgViewInfo.subresourceRange.levelCount = 1;
15889
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015890 m_errorMonitor->SetDesiredFailureMsg(
15891 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15892 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015893 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15894 imgViewInfo.subresourceRange.layerCount = 0;
15895 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15896 m_errorMonitor->VerifyFound();
15897 imgViewInfo.subresourceRange.layerCount = 1;
15898
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15900 "Formats MUST be IDENTICAL unless "
15901 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15902 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015903 // Can't use depth format for view into color image - Expect INVALID_FORMAT
15904 imgViewInfo.format = VK_FORMAT_D24_UNORM_S8_UINT;
15905 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15906 m_errorMonitor->VerifyFound();
15907 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15908
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015910 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15911 // VIEW_CREATE_ERROR
15912 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15913 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15914 m_errorMonitor->VerifyFound();
15915 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15916
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015918 // TODO: Update framework to easily passing mutable flag into ImageObj init
15919 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015920 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15921 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15922 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015923 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15924 // VIEW_CREATE_ERROR
15925 VkImageCreateInfo mutImgInfo = image.create_info();
15926 VkImage mutImage;
15927 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015928 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015929 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15930 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15931 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15932 ASSERT_VK_SUCCESS(ret);
15933 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015934 m_errorMonitor->SetUnexpectedError(
15935 "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 -060015936 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15937 m_errorMonitor->VerifyFound();
15938 imgViewInfo.image = image.handle();
15939 vkDestroyImage(m_device->handle(), mutImage, NULL);
15940}
15941
Dave Houlton59a20702017-02-02 17:26:23 -070015942TEST_F(VkLayerTest, ImageBufferCopyTests) {
15943 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
15944
15945 ASSERT_NO_FATAL_FAILURE(InitState());
Dave Houlton584d51e2017-02-16 12:52:54 -070015946
15947 // Bail if any dimension of transfer granularity is 0.
15948 auto index = m_device->graphics_queue_node_index_;
15949 auto queue_family_properties = m_device->phy().queue_properties();
15950 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
15951 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
15952 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
15953 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
15954 return;
15955 }
15956
Dave Houlton59a20702017-02-02 17:26:23 -070015957 VkImageObj image_64k(m_device); // 128^2 texels, 64k
15958 VkImageObj image_16k(m_device); // 64^2 texels, 16k
15959 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070015960 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
15961 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
15962 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
15963 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
15964
Dave Houlton59a20702017-02-02 17:26:23 -070015965 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
15966 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15967 VK_IMAGE_TILING_OPTIMAL, 0);
15968 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
15969 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15970 VK_IMAGE_TILING_OPTIMAL, 0);
15971 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
15972 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070015973 ASSERT_TRUE(image_64k.initialized());
15974 ASSERT_TRUE(image_16k.initialized());
15975 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070015976
Dave Houltonf3229d52017-02-21 15:59:08 -070015977 // Verify all needed Depth/Stencil formats are supported
15978 bool missing_ds_support = false;
15979 VkFormatProperties props = {0, 0, 0};
15980 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
15981 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15982 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
15983 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15984 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
15985 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15986 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
15987 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
15988
15989 if (!missing_ds_support) {
15990 ds_image_4D_1S.init(
15991 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
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_4D_1S.initialized());
15995
15996 ds_image_3D_1S.init(
15997 256, 256, VK_FORMAT_D24_UNORM_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_3D_1S.initialized());
16001
16002 ds_image_2D.init(
16003 256, 256, VK_FORMAT_D16_UNORM,
16004 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16005 VK_IMAGE_TILING_OPTIMAL, 0);
16006 ASSERT_TRUE(ds_image_2D.initialized());
16007
16008 ds_image_1S.init(
16009 256, 256, VK_FORMAT_S8_UINT,
16010 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16011 VK_IMAGE_TILING_OPTIMAL, 0);
16012 ASSERT_TRUE(ds_image_1S.initialized());
16013 }
16014
16015 // Allocate buffers
16016 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016017 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016018 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16019 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16020 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16021 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016022
16023 VkBufferImageCopy region = {};
16024 region.bufferRowLength = 0;
16025 region.bufferImageHeight = 0;
16026 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16027 region.imageSubresource.layerCount = 1;
16028 region.imageOffset = {0, 0, 0};
16029 region.imageExtent = {64, 64, 1};
16030 region.bufferOffset = 0;
16031
16032 // attempt copies before putting command buffer in recording state
16033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16034 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16035 &region);
16036 m_errorMonitor->VerifyFound();
16037
16038 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16039 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16040 &region);
16041 m_errorMonitor->VerifyFound();
16042
16043 // start recording
16044 m_commandBuffer->BeginCommandBuffer();
16045
16046 // successful copies
16047 m_errorMonitor->ExpectSuccess();
16048 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16049 &region);
16050 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16051 &region);
16052 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16053 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16054 &region);
16055 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16056 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16057 &region);
16058 region.imageOffset.x = 0;
16059 region.imageExtent.height = 64;
16060 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16061 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16062 &region);
16063 m_errorMonitor->VerifyNotFound();
16064
16065 // image/buffer too small (extent) on copy to image
16066 region.imageExtent = {65, 64, 1};
16067 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16068 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16069 &region);
16070 m_errorMonitor->VerifyFound();
16071
16072 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16073 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16074 &region);
16075 m_errorMonitor->VerifyFound();
16076
16077 // image/buffer too small (offset) on copy to image
16078 region.imageExtent = {64, 64, 1};
16079 region.imageOffset = {0, 4, 0};
16080 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16081 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16082 &region);
16083 m_errorMonitor->VerifyFound();
16084
16085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16086 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16087 &region);
16088 m_errorMonitor->VerifyFound();
16089
16090 // image/buffer too small on copy to buffer
16091 region.imageExtent = {64, 64, 1};
16092 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016093 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16095 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16096 &region);
16097 m_errorMonitor->VerifyFound();
16098
16099 region.imageExtent = {64, 65, 1};
16100 region.bufferOffset = 0;
16101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16102 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16103 &region);
16104 m_errorMonitor->VerifyFound();
16105
16106 // buffer size ok but rowlength causes loose packing
16107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16108 region.imageExtent = {64, 64, 1};
16109 region.bufferRowLength = 68;
16110 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16111 &region);
16112 m_errorMonitor->VerifyFound();
16113
Dave Houlton59a20702017-02-02 17:26:23 -070016114 // aspect bits
16115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16116 region.imageExtent = {64, 64, 1};
16117 region.bufferRowLength = 0;
16118 region.bufferImageHeight = 0;
16119 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_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
16124 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16125 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16126 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16127 &region);
16128 m_errorMonitor->VerifyFound();
16129
16130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16131 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16132 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16133 buffer_16k.handle(), 1, &region);
16134 m_errorMonitor->VerifyFound();
16135
Dave Houltonf3229d52017-02-21 15:59:08 -070016136 // Test Depth/Stencil copies
16137 if (missing_ds_support) {
16138 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16139 } else {
16140 VkBufferImageCopy ds_region = {};
16141 ds_region.bufferOffset = 0;
16142 ds_region.bufferRowLength = 0;
16143 ds_region.bufferImageHeight = 0;
16144 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16145 ds_region.imageSubresource.mipLevel = 0;
16146 ds_region.imageSubresource.baseArrayLayer = 0;
16147 ds_region.imageSubresource.layerCount = 1;
16148 ds_region.imageOffset = {0, 0, 0};
16149 ds_region.imageExtent = {256, 256, 1};
16150
16151 // Depth copies that should succeed
16152 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16153 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16154 buffer_256k.handle(), 1, &ds_region);
16155 m_errorMonitor->VerifyNotFound();
16156
16157 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16158 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16159 buffer_256k.handle(), 1, &ds_region);
16160 m_errorMonitor->VerifyNotFound();
16161
16162 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16163 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16164 buffer_128k.handle(), 1, &ds_region);
16165 m_errorMonitor->VerifyNotFound();
16166
16167 // Depth copies that should fail
16168 ds_region.bufferOffset = 4;
16169 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16170 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16171 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16172 buffer_256k.handle(), 1, &ds_region);
16173 m_errorMonitor->VerifyFound();
16174
16175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16176 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16177 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16178 buffer_256k.handle(), 1, &ds_region);
16179 m_errorMonitor->VerifyFound();
16180
16181 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16182 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16183 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16184 buffer_128k.handle(), 1, &ds_region);
16185 m_errorMonitor->VerifyFound();
16186
16187 // Stencil copies that should succeed
16188 ds_region.bufferOffset = 0;
16189 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16190 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16191 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16192 buffer_64k.handle(), 1, &ds_region);
16193 m_errorMonitor->VerifyNotFound();
16194
16195 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16196 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16197 buffer_64k.handle(), 1, &ds_region);
16198 m_errorMonitor->VerifyNotFound();
16199
16200 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16201 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16202 buffer_64k.handle(), 1, &ds_region);
16203 m_errorMonitor->VerifyNotFound();
16204
16205 // Stencil copies that should fail
16206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16207 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16208 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16209 buffer_16k.handle(), 1, &ds_region);
16210 m_errorMonitor->VerifyFound();
16211
16212 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16213 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16214 ds_region.bufferRowLength = 260;
16215 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16216 buffer_64k.handle(), 1, &ds_region);
16217 m_errorMonitor->VerifyFound();
16218
16219 ds_region.bufferRowLength = 0;
16220 ds_region.bufferOffset = 4;
16221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16222 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16223 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16224 buffer_64k.handle(), 1, &ds_region);
16225 m_errorMonitor->VerifyFound();
16226 }
16227
Dave Houlton584d51e2017-02-16 12:52:54 -070016228 // Test compressed formats, if supported
16229 VkPhysicalDeviceFeatures device_features;
16230 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016231 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16232 device_features.textureCompressionASTC_LDR)) {
16233 printf(" No compressed formats supported - block compression tests skipped.\n");
16234 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070016235 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16236 if (device_features.textureCompressionBC) {
16237 image_16k_4x4comp.init(32, 32, VK_FORMAT_BC5_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
16238 } else if (device_features.textureCompressionETC2) {
16239 image_16k_4x4comp.init(32, 32, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16240 VK_IMAGE_TILING_OPTIMAL, 0);
16241 } else {
16242 image_16k_4x4comp.init(32, 32, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16243 0);
16244 }
16245 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016246
Dave Houlton584d51e2017-02-16 12:52:54 -070016247 // Just fits
16248 m_errorMonitor->ExpectSuccess();
16249 region.imageExtent = {128, 128, 1};
16250 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16251 buffer_16k.handle(), 1, &region);
16252 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016253
Dave Houlton584d51e2017-02-16 12:52:54 -070016254 // with offset, too big for buffer
16255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16256 region.bufferOffset = 16;
16257 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16258 buffer_16k.handle(), 1, &region);
16259 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016260
Dave Houlton584d51e2017-02-16 12:52:54 -070016261 // buffer offset must be a multiple of texel block size (16)
16262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16263 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16264 region.imageExtent = {64, 64, 1};
16265 region.bufferOffset = 24;
16266 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16267 buffer_16k.handle(), 1, &region);
16268 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016269
Dave Houlton584d51e2017-02-16 12:52:54 -070016270 // rowlength not a multiple of block width (4)
16271 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16272 region.bufferOffset = 0;
16273 region.bufferRowLength = 130;
16274 region.bufferImageHeight = 0;
16275 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16276 buffer_64k.handle(), 1, &region);
16277 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016278
Dave Houlton584d51e2017-02-16 12:52:54 -070016279 // imageheight not a multiple of block height (4)
16280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16281 region.bufferRowLength = 0;
16282 region.bufferImageHeight = 130;
16283 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16284 buffer_64k.handle(), 1, &region);
16285 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016286
Dave Houlton584d51e2017-02-16 12:52:54 -070016287 // image extents must be multiple of block dimensions (4x4)
16288 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16289 region.bufferImageHeight = 0;
16290 region.imageOffset = {4, 6, 0};
16291 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16292 buffer_64k.handle(), 1, &region);
16293 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016294
Dave Houlton584d51e2017-02-16 12:52:54 -070016295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16296 region.imageOffset = {22, 0, 0};
16297 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16298 buffer_64k.handle(), 1, &region);
16299 m_errorMonitor->VerifyFound();
16300 }
Dave Houlton59a20702017-02-02 17:26:23 -070016301}
16302
Tony Barbourd6673642016-05-05 14:46:39 -060016303TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016304 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016305
16306 ASSERT_NO_FATAL_FAILURE(InitState());
16307
Rene Lindsay135204f2016-12-22 17:11:09 -070016308 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016309 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016310 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 -070016311 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016312 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016313 vk_testing::Buffer buffer;
16314 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016315 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016316 VkBufferImageCopy region = {};
16317 region.bufferRowLength = 128;
16318 region.bufferImageHeight = 128;
16319 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16320 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016321 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016322 region.imageExtent.height = 4;
16323 region.imageExtent.width = 4;
16324 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016325
16326 VkImageObj image2(m_device);
16327 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 -070016328 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016329 ASSERT_TRUE(image2.initialized());
16330 vk_testing::Buffer buffer2;
16331 VkMemoryPropertyFlags reqs2 = 0;
16332 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16333 VkBufferImageCopy region2 = {};
16334 region2.bufferRowLength = 128;
16335 region2.bufferImageHeight = 128;
16336 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16337 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16338 region2.imageSubresource.layerCount = 1;
16339 region2.imageExtent.height = 4;
16340 region2.imageExtent.width = 4;
16341 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016342 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016343
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016344 // Image must have offset.z of 0 and extent.depth of 1
16345 // Introduce failure by setting imageExtent.depth to 0
16346 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016348 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016349 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016350 m_errorMonitor->VerifyFound();
16351
16352 region.imageExtent.depth = 1;
16353
16354 // Image must have offset.z of 0 and extent.depth of 1
16355 // Introduce failure by setting imageOffset.z to 4
16356 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016357 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016358 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016359 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016360 m_errorMonitor->VerifyFound();
16361
16362 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016363 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16364 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016365 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016366 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016367 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16368 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016369 m_errorMonitor->VerifyFound();
16370
16371 // BufferOffset must be a multiple of 4
16372 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016373 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016375 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16376 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016377 m_errorMonitor->VerifyFound();
16378
16379 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16380 region.bufferOffset = 0;
16381 region.imageExtent.height = 128;
16382 region.imageExtent.width = 128;
16383 // Introduce failure by setting bufferRowLength > 0 but less than width
16384 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016386 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16387 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016388 m_errorMonitor->VerifyFound();
16389
16390 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16391 region.bufferRowLength = 128;
16392 // Introduce failure by setting bufferRowHeight > 0 but less than height
16393 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016395 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16396 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016397 m_errorMonitor->VerifyFound();
16398
16399 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016400 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016401 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16402 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016403 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016404 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16405 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016406 VkImageBlit blitRegion = {};
16407 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16408 blitRegion.srcSubresource.baseArrayLayer = 0;
16409 blitRegion.srcSubresource.layerCount = 1;
16410 blitRegion.srcSubresource.mipLevel = 0;
16411 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16412 blitRegion.dstSubresource.baseArrayLayer = 0;
16413 blitRegion.dstSubresource.layerCount = 1;
16414 blitRegion.dstSubresource.mipLevel = 0;
16415
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016416 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016418 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016419 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16420 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016421 m_errorMonitor->VerifyFound();
16422
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016423 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016424 VkImageMemoryBarrier img_barrier;
16425 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16426 img_barrier.pNext = NULL;
16427 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16428 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16429 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16430 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16431 img_barrier.image = image.handle();
16432 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16433 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16434 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16435 img_barrier.subresourceRange.baseArrayLayer = 0;
16436 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016437 img_barrier.subresourceRange.layerCount = 0;
16438 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016439 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16440 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016441 m_errorMonitor->VerifyFound();
16442 img_barrier.subresourceRange.layerCount = 1;
16443}
16444
16445TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016446 TEST_DESCRIPTION("Exceed the limits of image format ");
16447
Cody Northropc31a84f2016-08-22 10:41:47 -060016448 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016449 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016450 VkImageCreateInfo image_create_info = {};
16451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16452 image_create_info.pNext = NULL;
16453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16454 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16455 image_create_info.extent.width = 32;
16456 image_create_info.extent.height = 32;
16457 image_create_info.extent.depth = 1;
16458 image_create_info.mipLevels = 1;
16459 image_create_info.arrayLayers = 1;
16460 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16461 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16462 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16463 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16464 image_create_info.flags = 0;
16465
16466 VkImage nullImg;
16467 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016468 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16469 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016470 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016471 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16472 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16473 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016474 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016475
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016476 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016477 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16478 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16479 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16480 m_errorMonitor->VerifyFound();
16481 image_create_info.mipLevels = 1;
16482
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016484 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16485 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16486 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16487 m_errorMonitor->VerifyFound();
16488 image_create_info.arrayLayers = 1;
16489
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016491 int samples = imgFmtProps.sampleCounts >> 1;
16492 image_create_info.samples = (VkSampleCountFlagBits)samples;
16493 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16494 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16495 m_errorMonitor->VerifyFound();
16496 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16497
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016498 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16499 "pCreateInfo->initialLayout, must be "
16500 "VK_IMAGE_LAYOUT_UNDEFINED or "
16501 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016502 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16503 // Expect INVALID_LAYOUT
16504 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16505 m_errorMonitor->VerifyFound();
16506 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16507}
16508
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016509TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016510 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016512
16513 ASSERT_NO_FATAL_FAILURE(InitState());
16514
16515 VkImageObj src_image(m_device);
16516 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16517 VkImageObj dst_image(m_device);
16518 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16519
Tony Barbour552f6c02016-12-21 14:34:07 -070016520 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016521 VkImageCopy copy_region;
16522 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16523 copy_region.srcSubresource.mipLevel = 0;
16524 copy_region.srcSubresource.baseArrayLayer = 0;
16525 copy_region.srcSubresource.layerCount = 0;
16526 copy_region.srcOffset.x = 0;
16527 copy_region.srcOffset.y = 0;
16528 copy_region.srcOffset.z = 0;
16529 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16530 copy_region.dstSubresource.mipLevel = 0;
16531 copy_region.dstSubresource.baseArrayLayer = 0;
16532 copy_region.dstSubresource.layerCount = 0;
16533 copy_region.dstOffset.x = 0;
16534 copy_region.dstOffset.y = 0;
16535 copy_region.dstOffset.z = 0;
16536 copy_region.extent.width = 64;
16537 copy_region.extent.height = 64;
16538 copy_region.extent.depth = 1;
16539 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16540 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016541 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016542
16543 m_errorMonitor->VerifyFound();
16544}
16545
16546TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016547 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016549
16550 ASSERT_NO_FATAL_FAILURE(InitState());
16551
16552 VkImageObj src_image(m_device);
16553 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16554 VkImageObj dst_image(m_device);
16555 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16556
Tony Barbour552f6c02016-12-21 14:34:07 -070016557 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016558 VkImageCopy copy_region;
16559 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16560 copy_region.srcSubresource.mipLevel = 0;
16561 copy_region.srcSubresource.baseArrayLayer = 0;
16562 copy_region.srcSubresource.layerCount = 0;
16563 copy_region.srcOffset.x = 0;
16564 copy_region.srcOffset.y = 0;
16565 copy_region.srcOffset.z = 0;
16566 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16567 copy_region.dstSubresource.mipLevel = 0;
16568 copy_region.dstSubresource.baseArrayLayer = 0;
16569 copy_region.dstSubresource.layerCount = 0;
16570 copy_region.dstOffset.x = 0;
16571 copy_region.dstOffset.y = 0;
16572 copy_region.dstOffset.z = 0;
16573 copy_region.extent.width = 64;
16574 copy_region.extent.height = 64;
16575 copy_region.extent.depth = 1;
16576 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16577 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016578 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016579
16580 m_errorMonitor->VerifyFound();
16581}
16582
Karl Schultz6addd812016-02-02 17:17:23 -070016583TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016584 VkResult err;
16585 bool pass;
16586
16587 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016588 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016589
16590 ASSERT_NO_FATAL_FAILURE(InitState());
16591
16592 // Create two images of different types and try to copy between them
16593 VkImage srcImage;
16594 VkImage dstImage;
16595 VkDeviceMemory srcMem;
16596 VkDeviceMemory destMem;
16597 VkMemoryRequirements memReqs;
16598
16599 VkImageCreateInfo image_create_info = {};
16600 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16601 image_create_info.pNext = NULL;
16602 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16603 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16604 image_create_info.extent.width = 32;
16605 image_create_info.extent.height = 32;
16606 image_create_info.extent.depth = 1;
16607 image_create_info.mipLevels = 1;
16608 image_create_info.arrayLayers = 1;
16609 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16610 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16611 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16612 image_create_info.flags = 0;
16613
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016614 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016615 ASSERT_VK_SUCCESS(err);
16616
16617 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16618 // Introduce failure by creating second image with a different-sized format.
16619 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16620
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016621 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016622 ASSERT_VK_SUCCESS(err);
16623
16624 // Allocate memory
16625 VkMemoryAllocateInfo memAlloc = {};
16626 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16627 memAlloc.pNext = NULL;
16628 memAlloc.allocationSize = 0;
16629 memAlloc.memoryTypeIndex = 0;
16630
16631 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16632 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016633 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016634 ASSERT_TRUE(pass);
16635 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16636 ASSERT_VK_SUCCESS(err);
16637
16638 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16639 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016640 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016641 ASSERT_TRUE(pass);
16642 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16643 ASSERT_VK_SUCCESS(err);
16644
16645 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16646 ASSERT_VK_SUCCESS(err);
16647 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16648 ASSERT_VK_SUCCESS(err);
16649
Tony Barbour552f6c02016-12-21 14:34:07 -070016650 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016651 VkImageCopy copyRegion;
16652 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16653 copyRegion.srcSubresource.mipLevel = 0;
16654 copyRegion.srcSubresource.baseArrayLayer = 0;
16655 copyRegion.srcSubresource.layerCount = 0;
16656 copyRegion.srcOffset.x = 0;
16657 copyRegion.srcOffset.y = 0;
16658 copyRegion.srcOffset.z = 0;
16659 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16660 copyRegion.dstSubresource.mipLevel = 0;
16661 copyRegion.dstSubresource.baseArrayLayer = 0;
16662 copyRegion.dstSubresource.layerCount = 0;
16663 copyRegion.dstOffset.x = 0;
16664 copyRegion.dstOffset.y = 0;
16665 copyRegion.dstOffset.z = 0;
16666 copyRegion.extent.width = 1;
16667 copyRegion.extent.height = 1;
16668 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016669 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016670 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016671
16672 m_errorMonitor->VerifyFound();
16673
16674 vkDestroyImage(m_device->device(), srcImage, NULL);
16675 vkDestroyImage(m_device->device(), dstImage, NULL);
16676 vkFreeMemory(m_device->device(), srcMem, NULL);
16677 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016678}
16679
Karl Schultz6addd812016-02-02 17:17:23 -070016680TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16681 VkResult err;
16682 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016683
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016684 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016685 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16686 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016687
Mike Stroyana3082432015-09-25 13:39:21 -060016688 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016689
16690 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016691 VkImage srcImage;
16692 VkImage dstImage;
16693 VkDeviceMemory srcMem;
16694 VkDeviceMemory destMem;
16695 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016696
16697 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016698 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16699 image_create_info.pNext = NULL;
16700 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16701 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16702 image_create_info.extent.width = 32;
16703 image_create_info.extent.height = 32;
16704 image_create_info.extent.depth = 1;
16705 image_create_info.mipLevels = 1;
16706 image_create_info.arrayLayers = 1;
16707 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16708 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16709 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16710 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016711
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016712 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016713 ASSERT_VK_SUCCESS(err);
16714
Karl Schultzbdb75952016-04-19 11:36:49 -060016715 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16716
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016717 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016718 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016719 image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016720 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016721
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016722 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016723 ASSERT_VK_SUCCESS(err);
16724
16725 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016726 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016727 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16728 memAlloc.pNext = NULL;
16729 memAlloc.allocationSize = 0;
16730 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016731
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016732 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016733 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016734 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016735 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016736 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016737 ASSERT_VK_SUCCESS(err);
16738
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016739 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016740 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016741 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016742 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016743 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016744 ASSERT_VK_SUCCESS(err);
16745
16746 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16747 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016748 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016749 ASSERT_VK_SUCCESS(err);
16750
Tony Barbour552f6c02016-12-21 14:34:07 -070016751 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016752 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016753 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016754 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016755 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016756 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016757 copyRegion.srcOffset.x = 0;
16758 copyRegion.srcOffset.y = 0;
16759 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016760 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016761 copyRegion.dstSubresource.mipLevel = 0;
16762 copyRegion.dstSubresource.baseArrayLayer = 0;
16763 copyRegion.dstSubresource.layerCount = 0;
16764 copyRegion.dstOffset.x = 0;
16765 copyRegion.dstOffset.y = 0;
16766 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016767 copyRegion.extent.width = 1;
16768 copyRegion.extent.height = 1;
16769 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016770 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016771 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016772
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016773 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016774
Chia-I Wuf7458c52015-10-26 21:10:41 +080016775 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016776 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016777 vkFreeMemory(m_device->device(), srcMem, NULL);
16778 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016779}
16780
Karl Schultz6addd812016-02-02 17:17:23 -070016781TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
16782 VkResult err;
16783 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016784
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016785 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16786 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016787
Mike Stroyana3082432015-09-25 13:39:21 -060016788 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016789
16790 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016791 VkImage srcImage;
16792 VkImage dstImage;
16793 VkDeviceMemory srcMem;
16794 VkDeviceMemory destMem;
16795 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016796
16797 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016798 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16799 image_create_info.pNext = NULL;
16800 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16801 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16802 image_create_info.extent.width = 32;
16803 image_create_info.extent.height = 1;
16804 image_create_info.extent.depth = 1;
16805 image_create_info.mipLevels = 1;
16806 image_create_info.arrayLayers = 1;
16807 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16808 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16809 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16810 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016811
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016812 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016813 ASSERT_VK_SUCCESS(err);
16814
Karl Schultz6addd812016-02-02 17:17:23 -070016815 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016816
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016817 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016818 ASSERT_VK_SUCCESS(err);
16819
16820 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016821 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016822 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16823 memAlloc.pNext = NULL;
16824 memAlloc.allocationSize = 0;
16825 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016826
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016827 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016828 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016829 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016830 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016831 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016832 ASSERT_VK_SUCCESS(err);
16833
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016834 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016835 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016836 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016837 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016838 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016839 ASSERT_VK_SUCCESS(err);
16840
16841 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16842 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016843 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016844 ASSERT_VK_SUCCESS(err);
16845
Tony Barbour552f6c02016-12-21 14:34:07 -070016846 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016847 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016848 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16849 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016850 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016851 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016852 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016853 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016854 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016855 resolveRegion.srcOffset.x = 0;
16856 resolveRegion.srcOffset.y = 0;
16857 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016858 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016859 resolveRegion.dstSubresource.mipLevel = 0;
16860 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016861 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016862 resolveRegion.dstOffset.x = 0;
16863 resolveRegion.dstOffset.y = 0;
16864 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016865 resolveRegion.extent.width = 1;
16866 resolveRegion.extent.height = 1;
16867 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016868 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016869 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016870
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016871 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016872
Chia-I Wuf7458c52015-10-26 21:10:41 +080016873 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016874 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016875 vkFreeMemory(m_device->device(), srcMem, NULL);
16876 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016877}
16878
Karl Schultz6addd812016-02-02 17:17:23 -070016879TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
16880 VkResult err;
16881 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016882
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16884 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016885
Mike Stroyana3082432015-09-25 13:39:21 -060016886 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016887
Chris Forbesa7530692016-05-08 12:35:39 +120016888 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070016889 VkImage srcImage;
16890 VkImage dstImage;
16891 VkDeviceMemory srcMem;
16892 VkDeviceMemory destMem;
16893 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016894
16895 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016896 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16897 image_create_info.pNext = NULL;
16898 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16899 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16900 image_create_info.extent.width = 32;
16901 image_create_info.extent.height = 1;
16902 image_create_info.extent.depth = 1;
16903 image_create_info.mipLevels = 1;
16904 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120016905 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016906 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
16907 // Note: Some implementations expect color attachment usage for any
16908 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016909 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070016910 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016911
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016912 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016913 ASSERT_VK_SUCCESS(err);
16914
Karl Schultz6addd812016-02-02 17:17:23 -070016915 // Note: Some implementations expect color attachment usage for any
16916 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016917 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016918
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016919 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016920 ASSERT_VK_SUCCESS(err);
16921
16922 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016923 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016924 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16925 memAlloc.pNext = NULL;
16926 memAlloc.allocationSize = 0;
16927 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016928
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016929 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016930 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016931 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016932 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016933 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016934 ASSERT_VK_SUCCESS(err);
16935
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016936 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016937 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016938 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016939 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016940 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016941 ASSERT_VK_SUCCESS(err);
16942
16943 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16944 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016945 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060016946 ASSERT_VK_SUCCESS(err);
16947
Tony Barbour552f6c02016-12-21 14:34:07 -070016948 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016949 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070016950 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
16951 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060016952 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016953 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016954 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060016955 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016956 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060016957 resolveRegion.srcOffset.x = 0;
16958 resolveRegion.srcOffset.y = 0;
16959 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080016960 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016961 resolveRegion.dstSubresource.mipLevel = 0;
16962 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130016963 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016964 resolveRegion.dstOffset.x = 0;
16965 resolveRegion.dstOffset.y = 0;
16966 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016967 resolveRegion.extent.width = 1;
16968 resolveRegion.extent.height = 1;
16969 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016970 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016971 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060016972
Chris Forbes8f36a8a2016-04-07 13:21:07 +120016973 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060016974
Chia-I Wuf7458c52015-10-26 21:10:41 +080016975 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016976 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080016977 vkFreeMemory(m_device->device(), srcMem, NULL);
16978 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016979}
16980
Karl Schultz6addd812016-02-02 17:17:23 -070016981TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
16982 VkResult err;
16983 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016984
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070016985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016986 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016987
Mike Stroyana3082432015-09-25 13:39:21 -060016988 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060016989
16990 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016991 VkImage srcImage;
16992 VkImage dstImage;
16993 VkDeviceMemory srcMem;
16994 VkDeviceMemory destMem;
16995 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016996
16997 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016998 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16999 image_create_info.pNext = NULL;
17000 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17001 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17002 image_create_info.extent.width = 32;
17003 image_create_info.extent.height = 1;
17004 image_create_info.extent.depth = 1;
17005 image_create_info.mipLevels = 1;
17006 image_create_info.arrayLayers = 1;
17007 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17008 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17009 // Note: Some implementations expect color attachment usage for any
17010 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017011 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017012 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017013
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017015 ASSERT_VK_SUCCESS(err);
17016
Karl Schultz6addd812016-02-02 17:17:23 -070017017 // Set format to something other than source image
17018 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17019 // Note: Some implementations expect color attachment usage for any
17020 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017021 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017022 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017023
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017024 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017025 ASSERT_VK_SUCCESS(err);
17026
17027 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017028 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017029 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17030 memAlloc.pNext = NULL;
17031 memAlloc.allocationSize = 0;
17032 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017033
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017034 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017035 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017036 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017037 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017038 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017039 ASSERT_VK_SUCCESS(err);
17040
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017041 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017042 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017043 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017044 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017045 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017046 ASSERT_VK_SUCCESS(err);
17047
17048 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17049 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017050 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017051 ASSERT_VK_SUCCESS(err);
17052
Tony Barbour552f6c02016-12-21 14:34:07 -070017053 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017054 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017055 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17056 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017057 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017058 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017059 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017060 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017061 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017062 resolveRegion.srcOffset.x = 0;
17063 resolveRegion.srcOffset.y = 0;
17064 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017065 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017066 resolveRegion.dstSubresource.mipLevel = 0;
17067 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017068 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017069 resolveRegion.dstOffset.x = 0;
17070 resolveRegion.dstOffset.y = 0;
17071 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017072 resolveRegion.extent.width = 1;
17073 resolveRegion.extent.height = 1;
17074 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017075 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017076 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017077
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017078 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017079
Chia-I Wuf7458c52015-10-26 21:10:41 +080017080 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017081 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017082 vkFreeMemory(m_device->device(), srcMem, NULL);
17083 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017084}
17085
Karl Schultz6addd812016-02-02 17:17:23 -070017086TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17087 VkResult err;
17088 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017089
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017090 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017091 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017092
Mike Stroyana3082432015-09-25 13:39:21 -060017093 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017094
17095 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017096 VkImage srcImage;
17097 VkImage dstImage;
17098 VkDeviceMemory srcMem;
17099 VkDeviceMemory destMem;
17100 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017101
17102 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017103 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17104 image_create_info.pNext = NULL;
17105 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17106 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17107 image_create_info.extent.width = 32;
17108 image_create_info.extent.height = 1;
17109 image_create_info.extent.depth = 1;
17110 image_create_info.mipLevels = 1;
17111 image_create_info.arrayLayers = 1;
17112 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17113 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17114 // Note: Some implementations expect color attachment usage for any
17115 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017116 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017117 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017118
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017119 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017120 ASSERT_VK_SUCCESS(err);
17121
Karl Schultz6addd812016-02-02 17:17:23 -070017122 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17123 // Note: Some implementations expect color attachment usage for any
17124 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017125 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017126 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017127
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017128 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017129 ASSERT_VK_SUCCESS(err);
17130
17131 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017132 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017133 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17134 memAlloc.pNext = NULL;
17135 memAlloc.allocationSize = 0;
17136 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017137
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017138 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017139 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017140 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017141 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017142 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017143 ASSERT_VK_SUCCESS(err);
17144
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017145 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017146 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017147 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017148 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017149 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017150 ASSERT_VK_SUCCESS(err);
17151
17152 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17153 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017154 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017155 ASSERT_VK_SUCCESS(err);
17156
Tony Barbour552f6c02016-12-21 14:34:07 -070017157 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017158 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017159 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17160 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017161 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017162 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017163 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017164 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017165 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017166 resolveRegion.srcOffset.x = 0;
17167 resolveRegion.srcOffset.y = 0;
17168 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017169 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017170 resolveRegion.dstSubresource.mipLevel = 0;
17171 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017172 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017173 resolveRegion.dstOffset.x = 0;
17174 resolveRegion.dstOffset.y = 0;
17175 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017176 resolveRegion.extent.width = 1;
17177 resolveRegion.extent.height = 1;
17178 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017179 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017180 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017181
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017182 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017183
Chia-I Wuf7458c52015-10-26 21:10:41 +080017184 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017185 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017186 vkFreeMemory(m_device->device(), srcMem, NULL);
17187 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017188}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017189
Karl Schultz6addd812016-02-02 17:17:23 -070017190TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017191 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017192 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17193 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017194 // The image format check comes 2nd in validation so we trigger it first,
17195 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017196 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017197
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17199 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017200
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017201 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017202
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017203 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017204 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17205 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017206
17207 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017208 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17209 ds_pool_ci.pNext = NULL;
17210 ds_pool_ci.maxSets = 1;
17211 ds_pool_ci.poolSizeCount = 1;
17212 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017213
17214 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017215 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017216 ASSERT_VK_SUCCESS(err);
17217
17218 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017219 dsl_binding.binding = 0;
17220 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17221 dsl_binding.descriptorCount = 1;
17222 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17223 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017224
17225 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017226 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17227 ds_layout_ci.pNext = NULL;
17228 ds_layout_ci.bindingCount = 1;
17229 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017230 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017231 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017232 ASSERT_VK_SUCCESS(err);
17233
17234 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017235 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017236 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017237 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017238 alloc_info.descriptorPool = ds_pool;
17239 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017240 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017241 ASSERT_VK_SUCCESS(err);
17242
Karl Schultz6addd812016-02-02 17:17:23 -070017243 VkImage image_bad;
17244 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017245 // One bad format and one good format for Color attachment
Tobin Ehlis269f0322016-05-25 16:24:21 -060017246 const VkFormat tex_format_bad = VK_FORMAT_D24_UNORM_S8_UINT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017247 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017248 const int32_t tex_width = 32;
17249 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017250
17251 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017252 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17253 image_create_info.pNext = NULL;
17254 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17255 image_create_info.format = tex_format_bad;
17256 image_create_info.extent.width = tex_width;
17257 image_create_info.extent.height = tex_height;
17258 image_create_info.extent.depth = 1;
17259 image_create_info.mipLevels = 1;
17260 image_create_info.arrayLayers = 1;
17261 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17262 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017263 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017264 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017265
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017266 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017267 ASSERT_VK_SUCCESS(err);
17268 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017269 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17270 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017271 ASSERT_VK_SUCCESS(err);
17272
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017273 // ---Bind image memory---
17274 VkMemoryRequirements img_mem_reqs;
17275 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17276 VkMemoryAllocateInfo image_alloc_info = {};
17277 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17278 image_alloc_info.pNext = NULL;
17279 image_alloc_info.memoryTypeIndex = 0;
17280 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017281 bool pass =
17282 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 -070017283 ASSERT_TRUE(pass);
17284 VkDeviceMemory mem;
17285 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17286 ASSERT_VK_SUCCESS(err);
17287 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17288 ASSERT_VK_SUCCESS(err);
17289 // -----------------------
17290
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017291 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017292 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017293 image_view_create_info.image = image_bad;
17294 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17295 image_view_create_info.format = tex_format_bad;
17296 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17297 image_view_create_info.subresourceRange.baseMipLevel = 0;
17298 image_view_create_info.subresourceRange.layerCount = 1;
17299 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017300 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017301
17302 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017303 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017304
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017305 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017306
Chia-I Wuf7458c52015-10-26 21:10:41 +080017307 vkDestroyImage(m_device->device(), image_bad, NULL);
17308 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017309 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17310 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017311
17312 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017313}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017314
17315TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017316 TEST_DESCRIPTION(
17317 "Call ClearColorImage w/ a depth|stencil image and "
17318 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017319
17320 ASSERT_NO_FATAL_FAILURE(InitState());
17321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17322
Tony Barbour552f6c02016-12-21 14:34:07 -070017323 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017324
17325 // Color image
17326 VkClearColorValue clear_color;
17327 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17328 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17329 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17330 const int32_t img_width = 32;
17331 const int32_t img_height = 32;
17332 VkImageCreateInfo image_create_info = {};
17333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17334 image_create_info.pNext = NULL;
17335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17336 image_create_info.format = color_format;
17337 image_create_info.extent.width = img_width;
17338 image_create_info.extent.height = img_height;
17339 image_create_info.extent.depth = 1;
17340 image_create_info.mipLevels = 1;
17341 image_create_info.arrayLayers = 1;
17342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17343 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17344 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17345
17346 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017347 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017348
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017349 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017350
17351 // Depth/Stencil image
17352 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017353 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017354 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17355 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
17356 ds_image_create_info.format = VK_FORMAT_D24_UNORM_S8_UINT;
17357 ds_image_create_info.extent.width = 64;
17358 ds_image_create_info.extent.height = 64;
17359 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017360 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 -060017361
17362 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017363 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017364
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017365 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 -060017366
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017367 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017368
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017369 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017370 &color_range);
17371
17372 m_errorMonitor->VerifyFound();
17373
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017374 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17375 "vkCmdClearColorImage called with "
17376 "image created without "
17377 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017378
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017379 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017380 &color_range);
17381
17382 m_errorMonitor->VerifyFound();
17383
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017384 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017385 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17386 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017387
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017388 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17389 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017390
17391 m_errorMonitor->VerifyFound();
17392}
Tobin Ehliscde08892015-09-22 10:11:37 -060017393
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017394// WSI Enabled Tests
17395//
Chris Forbes09368e42016-10-13 11:59:22 +130017396#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017397TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17398
17399#if defined(VK_USE_PLATFORM_XCB_KHR)
17400 VkSurfaceKHR surface = VK_NULL_HANDLE;
17401
17402 VkResult err;
17403 bool pass;
17404 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17405 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17406 // uint32_t swapchain_image_count = 0;
17407 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17408 // uint32_t image_index = 0;
17409 // VkPresentInfoKHR present_info = {};
17410
17411 ASSERT_NO_FATAL_FAILURE(InitState());
17412
17413 // Use the create function from one of the VK_KHR_*_surface extension in
17414 // order to create a surface, testing all known errors in the process,
17415 // before successfully creating a surface:
17416 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17417 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17418 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17419 pass = (err != VK_SUCCESS);
17420 ASSERT_TRUE(pass);
17421 m_errorMonitor->VerifyFound();
17422
17423 // Next, try to create a surface with the wrong
17424 // VkXcbSurfaceCreateInfoKHR::sType:
17425 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17426 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17427 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17428 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17429 pass = (err != VK_SUCCESS);
17430 ASSERT_TRUE(pass);
17431 m_errorMonitor->VerifyFound();
17432
17433 // Create a native window, and then correctly create a surface:
17434 xcb_connection_t *connection;
17435 xcb_screen_t *screen;
17436 xcb_window_t xcb_window;
17437 xcb_intern_atom_reply_t *atom_wm_delete_window;
17438
17439 const xcb_setup_t *setup;
17440 xcb_screen_iterator_t iter;
17441 int scr;
17442 uint32_t value_mask, value_list[32];
17443 int width = 1;
17444 int height = 1;
17445
17446 connection = xcb_connect(NULL, &scr);
17447 ASSERT_TRUE(connection != NULL);
17448 setup = xcb_get_setup(connection);
17449 iter = xcb_setup_roots_iterator(setup);
17450 while (scr-- > 0)
17451 xcb_screen_next(&iter);
17452 screen = iter.data;
17453
17454 xcb_window = xcb_generate_id(connection);
17455
17456 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17457 value_list[0] = screen->black_pixel;
17458 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17459
17460 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17461 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17462
17463 /* Magic code that will send notification when window is destroyed */
17464 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17465 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17466
17467 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17468 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17469 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17470 free(reply);
17471
17472 xcb_map_window(connection, xcb_window);
17473
17474 // Force the x/y coordinates to 100,100 results are identical in consecutive
17475 // runs
17476 const uint32_t coords[] = { 100, 100 };
17477 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17478
17479 // Finally, try to correctly create a surface:
17480 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17481 xcb_create_info.pNext = NULL;
17482 xcb_create_info.flags = 0;
17483 xcb_create_info.connection = connection;
17484 xcb_create_info.window = xcb_window;
17485 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17486 pass = (err == VK_SUCCESS);
17487 ASSERT_TRUE(pass);
17488
17489 // Check if surface supports presentation:
17490
17491 // 1st, do so without having queried the queue families:
17492 VkBool32 supported = false;
17493 // TODO: Get the following error to come out:
17494 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17495 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17496 "function");
17497 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17498 pass = (err != VK_SUCCESS);
17499 // ASSERT_TRUE(pass);
17500 // m_errorMonitor->VerifyFound();
17501
17502 // Next, query a queue family index that's too large:
17503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17504 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17505 pass = (err != VK_SUCCESS);
17506 ASSERT_TRUE(pass);
17507 m_errorMonitor->VerifyFound();
17508
17509 // Finally, do so correctly:
17510 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17511 // SUPPORTED
17512 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17513 pass = (err == VK_SUCCESS);
17514 ASSERT_TRUE(pass);
17515
17516 // Before proceeding, try to create a swapchain without having called
17517 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17518 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17519 swapchain_create_info.pNext = NULL;
17520 swapchain_create_info.flags = 0;
17521 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17522 swapchain_create_info.surface = surface;
17523 swapchain_create_info.imageArrayLayers = 1;
17524 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17525 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17526 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17527 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17528 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17529 pass = (err != VK_SUCCESS);
17530 ASSERT_TRUE(pass);
17531 m_errorMonitor->VerifyFound();
17532
17533 // Get the surface capabilities:
17534 VkSurfaceCapabilitiesKHR surface_capabilities;
17535
17536 // Do so correctly (only error logged by this entrypoint is if the
17537 // extension isn't enabled):
17538 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17539 pass = (err == VK_SUCCESS);
17540 ASSERT_TRUE(pass);
17541
17542 // Get the surface formats:
17543 uint32_t surface_format_count;
17544
17545 // First, try without a pointer to surface_format_count:
17546 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17547 "specified as NULL");
17548 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17549 pass = (err == VK_SUCCESS);
17550 ASSERT_TRUE(pass);
17551 m_errorMonitor->VerifyFound();
17552
17553 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17554 // correctly done a 1st try (to get the count):
17555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17556 surface_format_count = 0;
17557 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17558 pass = (err == VK_SUCCESS);
17559 ASSERT_TRUE(pass);
17560 m_errorMonitor->VerifyFound();
17561
17562 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17563 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17564 pass = (err == VK_SUCCESS);
17565 ASSERT_TRUE(pass);
17566
17567 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17568 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17569
17570 // Next, do a 2nd try with surface_format_count being set too high:
17571 surface_format_count += 5;
17572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17573 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17574 pass = (err == VK_SUCCESS);
17575 ASSERT_TRUE(pass);
17576 m_errorMonitor->VerifyFound();
17577
17578 // Finally, do a correct 1st and 2nd try:
17579 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17580 pass = (err == VK_SUCCESS);
17581 ASSERT_TRUE(pass);
17582 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17583 pass = (err == VK_SUCCESS);
17584 ASSERT_TRUE(pass);
17585
17586 // Get the surface present modes:
17587 uint32_t surface_present_mode_count;
17588
17589 // First, try without a pointer to surface_format_count:
17590 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17591 "specified as NULL");
17592
17593 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17594 pass = (err == VK_SUCCESS);
17595 ASSERT_TRUE(pass);
17596 m_errorMonitor->VerifyFound();
17597
17598 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17599 // correctly done a 1st try (to get the count):
17600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17601 surface_present_mode_count = 0;
17602 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17603 (VkPresentModeKHR *)&surface_present_mode_count);
17604 pass = (err == VK_SUCCESS);
17605 ASSERT_TRUE(pass);
17606 m_errorMonitor->VerifyFound();
17607
17608 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17609 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17610 pass = (err == VK_SUCCESS);
17611 ASSERT_TRUE(pass);
17612
17613 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17614 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17615
17616 // Next, do a 2nd try with surface_format_count being set too high:
17617 surface_present_mode_count += 5;
17618 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17619 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17620 pass = (err == VK_SUCCESS);
17621 ASSERT_TRUE(pass);
17622 m_errorMonitor->VerifyFound();
17623
17624 // Finally, do a correct 1st and 2nd try:
17625 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17626 pass = (err == VK_SUCCESS);
17627 ASSERT_TRUE(pass);
17628 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17629 pass = (err == VK_SUCCESS);
17630 ASSERT_TRUE(pass);
17631
17632 // Create a swapchain:
17633
17634 // First, try without a pointer to swapchain_create_info:
17635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17636 "specified as NULL");
17637
17638 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17639 pass = (err != VK_SUCCESS);
17640 ASSERT_TRUE(pass);
17641 m_errorMonitor->VerifyFound();
17642
17643 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17644 // sType:
17645 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17647
17648 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17649 pass = (err != VK_SUCCESS);
17650 ASSERT_TRUE(pass);
17651 m_errorMonitor->VerifyFound();
17652
17653 // Next, call with a NULL swapchain pointer:
17654 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17655 swapchain_create_info.pNext = NULL;
17656 swapchain_create_info.flags = 0;
17657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17658 "specified as NULL");
17659
17660 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17661 pass = (err != VK_SUCCESS);
17662 ASSERT_TRUE(pass);
17663 m_errorMonitor->VerifyFound();
17664
17665 // TODO: Enhance swapchain layer so that
17666 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17667
17668 // Next, call with a queue family index that's too large:
17669 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17670 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17671 swapchain_create_info.queueFamilyIndexCount = 2;
17672 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17673 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17674 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17675 pass = (err != VK_SUCCESS);
17676 ASSERT_TRUE(pass);
17677 m_errorMonitor->VerifyFound();
17678
17679 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17680 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17681 swapchain_create_info.queueFamilyIndexCount = 1;
17682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17683 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17684 "pCreateInfo->pQueueFamilyIndices).");
17685 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17686 pass = (err != VK_SUCCESS);
17687 ASSERT_TRUE(pass);
17688 m_errorMonitor->VerifyFound();
17689
17690 // Next, call with an invalid imageSharingMode:
17691 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17692 swapchain_create_info.queueFamilyIndexCount = 1;
17693 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17694 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17695 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17696 pass = (err != VK_SUCCESS);
17697 ASSERT_TRUE(pass);
17698 m_errorMonitor->VerifyFound();
17699 // Fix for the future:
17700 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17701 // SUPPORTED
17702 swapchain_create_info.queueFamilyIndexCount = 0;
17703 queueFamilyIndex[0] = 0;
17704 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17705
17706 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17707 // Get the images from a swapchain:
17708 // Acquire an image from a swapchain:
17709 // Present an image to a swapchain:
17710 // Destroy the swapchain:
17711
17712 // TODOs:
17713 //
17714 // - Try destroying the device without first destroying the swapchain
17715 //
17716 // - Try destroying the device without first destroying the surface
17717 //
17718 // - Try destroying the surface without first destroying the swapchain
17719
17720 // Destroy the surface:
17721 vkDestroySurfaceKHR(instance(), surface, NULL);
17722
17723 // Tear down the window:
17724 xcb_destroy_window(connection, xcb_window);
17725 xcb_disconnect(connection);
17726
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017727#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017728 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017729#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017730}
Chris Forbes09368e42016-10-13 11:59:22 +130017731#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017732
17733//
17734// POSITIVE VALIDATION TESTS
17735//
17736// These tests do not expect to encounter ANY validation errors pass only if this is true
17737
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070017738TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
17739 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
17740 ASSERT_NO_FATAL_FAILURE(InitState());
17741 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17742
17743 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17744 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17745 command_buffer_allocate_info.commandPool = m_commandPool;
17746 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17747 command_buffer_allocate_info.commandBufferCount = 1;
17748
17749 VkCommandBuffer secondary_command_buffer;
17750 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17751 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17752 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17753 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17754 command_buffer_inheritance_info.renderPass = m_renderPass;
17755 command_buffer_inheritance_info.framebuffer = m_framebuffer;
17756
17757 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17758 command_buffer_begin_info.flags =
17759 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
17760 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17761
17762 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17763 VkClearAttachment color_attachment;
17764 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17765 color_attachment.clearValue.color.float32[0] = 0;
17766 color_attachment.clearValue.color.float32[1] = 0;
17767 color_attachment.clearValue.color.float32[2] = 0;
17768 color_attachment.clearValue.color.float32[3] = 0;
17769 color_attachment.colorAttachment = 0;
17770 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
17771 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
17772}
17773
Tobin Ehlise0006882016-11-03 10:14:28 -060017774TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017775 TEST_DESCRIPTION(
17776 "Perform an image layout transition in a secondary command buffer followed "
17777 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060017778 VkResult err;
17779 m_errorMonitor->ExpectSuccess();
17780 ASSERT_NO_FATAL_FAILURE(InitState());
17781 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17782 // Allocate a secondary and primary cmd buffer
17783 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
17784 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
17785 command_buffer_allocate_info.commandPool = m_commandPool;
17786 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
17787 command_buffer_allocate_info.commandBufferCount = 1;
17788
17789 VkCommandBuffer secondary_command_buffer;
17790 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
17791 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
17792 VkCommandBuffer primary_command_buffer;
17793 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
17794 VkCommandBufferBeginInfo command_buffer_begin_info = {};
17795 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
17796 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
17797 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
17798 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
17799 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
17800
17801 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
17802 ASSERT_VK_SUCCESS(err);
17803 VkImageObj image(m_device);
17804 image.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
17805 ASSERT_TRUE(image.initialized());
17806 VkImageMemoryBarrier img_barrier = {};
17807 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17808 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17809 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17810 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
17811 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17812 img_barrier.image = image.handle();
17813 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17814 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17815 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17816 img_barrier.subresourceRange.baseArrayLayer = 0;
17817 img_barrier.subresourceRange.baseMipLevel = 0;
17818 img_barrier.subresourceRange.layerCount = 1;
17819 img_barrier.subresourceRange.levelCount = 1;
17820 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
17821 0, nullptr, 1, &img_barrier);
17822 err = vkEndCommandBuffer(secondary_command_buffer);
17823 ASSERT_VK_SUCCESS(err);
17824
17825 // Now update primary cmd buffer to execute secondary and transitions image
17826 command_buffer_begin_info.pInheritanceInfo = nullptr;
17827 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
17828 ASSERT_VK_SUCCESS(err);
17829 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
17830 VkImageMemoryBarrier img_barrier2 = {};
17831 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
17832 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
17833 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
17834 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17835 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
17836 img_barrier2.image = image.handle();
17837 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17838 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
17839 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
17840 img_barrier2.subresourceRange.baseArrayLayer = 0;
17841 img_barrier2.subresourceRange.baseMipLevel = 0;
17842 img_barrier2.subresourceRange.layerCount = 1;
17843 img_barrier2.subresourceRange.levelCount = 1;
17844 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
17845 nullptr, 1, &img_barrier2);
17846 err = vkEndCommandBuffer(primary_command_buffer);
17847 ASSERT_VK_SUCCESS(err);
17848 VkSubmitInfo submit_info = {};
17849 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
17850 submit_info.commandBufferCount = 1;
17851 submit_info.pCommandBuffers = &primary_command_buffer;
17852 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
17853 ASSERT_VK_SUCCESS(err);
17854 m_errorMonitor->VerifyNotFound();
17855 err = vkDeviceWaitIdle(m_device->device());
17856 ASSERT_VK_SUCCESS(err);
17857 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
17858 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
17859}
17860
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017861// This is a positive test. No failures are expected.
17862TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017863 TEST_DESCRIPTION(
17864 "Ensure that the vkUpdateDescriptorSets validation code "
17865 "is ignoring VkWriteDescriptorSet members that are not "
17866 "related to the descriptor type specified by "
17867 "VkWriteDescriptorSet::descriptorType. Correct "
17868 "validation behavior will result in the test running to "
17869 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017870
17871 const uintptr_t invalid_ptr = 0xcdcdcdcd;
17872
17873 ASSERT_NO_FATAL_FAILURE(InitState());
17874
17875 // Image Case
17876 {
17877 m_errorMonitor->ExpectSuccess();
17878
17879 VkImage image;
17880 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
17881 const int32_t tex_width = 32;
17882 const int32_t tex_height = 32;
17883 VkImageCreateInfo image_create_info = {};
17884 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17885 image_create_info.pNext = NULL;
17886 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17887 image_create_info.format = tex_format;
17888 image_create_info.extent.width = tex_width;
17889 image_create_info.extent.height = tex_height;
17890 image_create_info.extent.depth = 1;
17891 image_create_info.mipLevels = 1;
17892 image_create_info.arrayLayers = 1;
17893 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17894 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17895 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17896 image_create_info.flags = 0;
17897 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
17898 ASSERT_VK_SUCCESS(err);
17899
17900 VkMemoryRequirements memory_reqs;
17901 VkDeviceMemory image_memory;
17902 bool pass;
17903 VkMemoryAllocateInfo memory_info = {};
17904 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17905 memory_info.pNext = NULL;
17906 memory_info.allocationSize = 0;
17907 memory_info.memoryTypeIndex = 0;
17908 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
17909 memory_info.allocationSize = memory_reqs.size;
17910 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
17911 ASSERT_TRUE(pass);
17912 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
17913 ASSERT_VK_SUCCESS(err);
17914 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
17915 ASSERT_VK_SUCCESS(err);
17916
17917 VkImageViewCreateInfo image_view_create_info = {};
17918 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
17919 image_view_create_info.image = image;
17920 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17921 image_view_create_info.format = tex_format;
17922 image_view_create_info.subresourceRange.layerCount = 1;
17923 image_view_create_info.subresourceRange.baseMipLevel = 0;
17924 image_view_create_info.subresourceRange.levelCount = 1;
17925 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17926
17927 VkImageView view;
17928 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
17929 ASSERT_VK_SUCCESS(err);
17930
17931 VkDescriptorPoolSize ds_type_count = {};
17932 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17933 ds_type_count.descriptorCount = 1;
17934
17935 VkDescriptorPoolCreateInfo ds_pool_ci = {};
17936 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17937 ds_pool_ci.pNext = NULL;
17938 ds_pool_ci.maxSets = 1;
17939 ds_pool_ci.poolSizeCount = 1;
17940 ds_pool_ci.pPoolSizes = &ds_type_count;
17941
17942 VkDescriptorPool ds_pool;
17943 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
17944 ASSERT_VK_SUCCESS(err);
17945
17946 VkDescriptorSetLayoutBinding dsl_binding = {};
17947 dsl_binding.binding = 0;
17948 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17949 dsl_binding.descriptorCount = 1;
17950 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17951 dsl_binding.pImmutableSamplers = NULL;
17952
17953 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
17954 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17955 ds_layout_ci.pNext = NULL;
17956 ds_layout_ci.bindingCount = 1;
17957 ds_layout_ci.pBindings = &dsl_binding;
17958 VkDescriptorSetLayout ds_layout;
17959 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
17960 ASSERT_VK_SUCCESS(err);
17961
17962 VkDescriptorSet descriptor_set;
17963 VkDescriptorSetAllocateInfo alloc_info = {};
17964 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
17965 alloc_info.descriptorSetCount = 1;
17966 alloc_info.descriptorPool = ds_pool;
17967 alloc_info.pSetLayouts = &ds_layout;
17968 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
17969 ASSERT_VK_SUCCESS(err);
17970
17971 VkDescriptorImageInfo image_info = {};
17972 image_info.imageView = view;
17973 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
17974
17975 VkWriteDescriptorSet descriptor_write;
17976 memset(&descriptor_write, 0, sizeof(descriptor_write));
17977 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
17978 descriptor_write.dstSet = descriptor_set;
17979 descriptor_write.dstBinding = 0;
17980 descriptor_write.descriptorCount = 1;
17981 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17982 descriptor_write.pImageInfo = &image_info;
17983
17984 // Set pBufferInfo and pTexelBufferView to invalid values, which should
17985 // be
17986 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
17987 // This will most likely produce a crash if the parameter_validation
17988 // layer
17989 // does not correctly ignore pBufferInfo.
17990 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
17991 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
17992
17993 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
17994
17995 m_errorMonitor->VerifyNotFound();
17996
17997 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17998 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
17999 vkDestroyImageView(m_device->device(), view, NULL);
18000 vkDestroyImage(m_device->device(), image, NULL);
18001 vkFreeMemory(m_device->device(), image_memory, NULL);
18002 }
18003
18004 // Buffer Case
18005 {
18006 m_errorMonitor->ExpectSuccess();
18007
18008 VkBuffer buffer;
18009 uint32_t queue_family_index = 0;
18010 VkBufferCreateInfo buffer_create_info = {};
18011 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18012 buffer_create_info.size = 1024;
18013 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18014 buffer_create_info.queueFamilyIndexCount = 1;
18015 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18016
18017 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18018 ASSERT_VK_SUCCESS(err);
18019
18020 VkMemoryRequirements memory_reqs;
18021 VkDeviceMemory buffer_memory;
18022 bool pass;
18023 VkMemoryAllocateInfo memory_info = {};
18024 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18025 memory_info.pNext = NULL;
18026 memory_info.allocationSize = 0;
18027 memory_info.memoryTypeIndex = 0;
18028
18029 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18030 memory_info.allocationSize = memory_reqs.size;
18031 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18032 ASSERT_TRUE(pass);
18033
18034 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18035 ASSERT_VK_SUCCESS(err);
18036 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18037 ASSERT_VK_SUCCESS(err);
18038
18039 VkDescriptorPoolSize ds_type_count = {};
18040 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18041 ds_type_count.descriptorCount = 1;
18042
18043 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18044 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18045 ds_pool_ci.pNext = NULL;
18046 ds_pool_ci.maxSets = 1;
18047 ds_pool_ci.poolSizeCount = 1;
18048 ds_pool_ci.pPoolSizes = &ds_type_count;
18049
18050 VkDescriptorPool ds_pool;
18051 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18052 ASSERT_VK_SUCCESS(err);
18053
18054 VkDescriptorSetLayoutBinding dsl_binding = {};
18055 dsl_binding.binding = 0;
18056 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18057 dsl_binding.descriptorCount = 1;
18058 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18059 dsl_binding.pImmutableSamplers = NULL;
18060
18061 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18062 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18063 ds_layout_ci.pNext = NULL;
18064 ds_layout_ci.bindingCount = 1;
18065 ds_layout_ci.pBindings = &dsl_binding;
18066 VkDescriptorSetLayout ds_layout;
18067 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18068 ASSERT_VK_SUCCESS(err);
18069
18070 VkDescriptorSet descriptor_set;
18071 VkDescriptorSetAllocateInfo alloc_info = {};
18072 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18073 alloc_info.descriptorSetCount = 1;
18074 alloc_info.descriptorPool = ds_pool;
18075 alloc_info.pSetLayouts = &ds_layout;
18076 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18077 ASSERT_VK_SUCCESS(err);
18078
18079 VkDescriptorBufferInfo buffer_info = {};
18080 buffer_info.buffer = buffer;
18081 buffer_info.offset = 0;
18082 buffer_info.range = 1024;
18083
18084 VkWriteDescriptorSet descriptor_write;
18085 memset(&descriptor_write, 0, sizeof(descriptor_write));
18086 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18087 descriptor_write.dstSet = descriptor_set;
18088 descriptor_write.dstBinding = 0;
18089 descriptor_write.descriptorCount = 1;
18090 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18091 descriptor_write.pBufferInfo = &buffer_info;
18092
18093 // Set pImageInfo and pTexelBufferView to invalid values, which should
18094 // be
18095 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18096 // This will most likely produce a crash if the parameter_validation
18097 // layer
18098 // does not correctly ignore pImageInfo.
18099 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18100 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18101
18102 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18103
18104 m_errorMonitor->VerifyNotFound();
18105
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018106 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18107 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18108 vkDestroyBuffer(m_device->device(), buffer, NULL);
18109 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18110 }
18111
18112 // Texel Buffer Case
18113 {
18114 m_errorMonitor->ExpectSuccess();
18115
18116 VkBuffer buffer;
18117 uint32_t queue_family_index = 0;
18118 VkBufferCreateInfo buffer_create_info = {};
18119 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18120 buffer_create_info.size = 1024;
18121 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18122 buffer_create_info.queueFamilyIndexCount = 1;
18123 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18124
18125 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18126 ASSERT_VK_SUCCESS(err);
18127
18128 VkMemoryRequirements memory_reqs;
18129 VkDeviceMemory buffer_memory;
18130 bool pass;
18131 VkMemoryAllocateInfo memory_info = {};
18132 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18133 memory_info.pNext = NULL;
18134 memory_info.allocationSize = 0;
18135 memory_info.memoryTypeIndex = 0;
18136
18137 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18138 memory_info.allocationSize = memory_reqs.size;
18139 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18140 ASSERT_TRUE(pass);
18141
18142 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18143 ASSERT_VK_SUCCESS(err);
18144 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18145 ASSERT_VK_SUCCESS(err);
18146
18147 VkBufferViewCreateInfo buff_view_ci = {};
18148 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18149 buff_view_ci.buffer = buffer;
18150 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18151 buff_view_ci.range = VK_WHOLE_SIZE;
18152 VkBufferView buffer_view;
18153 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18154
18155 VkDescriptorPoolSize ds_type_count = {};
18156 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18157 ds_type_count.descriptorCount = 1;
18158
18159 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18160 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18161 ds_pool_ci.pNext = NULL;
18162 ds_pool_ci.maxSets = 1;
18163 ds_pool_ci.poolSizeCount = 1;
18164 ds_pool_ci.pPoolSizes = &ds_type_count;
18165
18166 VkDescriptorPool ds_pool;
18167 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18168 ASSERT_VK_SUCCESS(err);
18169
18170 VkDescriptorSetLayoutBinding dsl_binding = {};
18171 dsl_binding.binding = 0;
18172 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18173 dsl_binding.descriptorCount = 1;
18174 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18175 dsl_binding.pImmutableSamplers = NULL;
18176
18177 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18178 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18179 ds_layout_ci.pNext = NULL;
18180 ds_layout_ci.bindingCount = 1;
18181 ds_layout_ci.pBindings = &dsl_binding;
18182 VkDescriptorSetLayout ds_layout;
18183 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18184 ASSERT_VK_SUCCESS(err);
18185
18186 VkDescriptorSet descriptor_set;
18187 VkDescriptorSetAllocateInfo alloc_info = {};
18188 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18189 alloc_info.descriptorSetCount = 1;
18190 alloc_info.descriptorPool = ds_pool;
18191 alloc_info.pSetLayouts = &ds_layout;
18192 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18193 ASSERT_VK_SUCCESS(err);
18194
18195 VkWriteDescriptorSet descriptor_write;
18196 memset(&descriptor_write, 0, sizeof(descriptor_write));
18197 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18198 descriptor_write.dstSet = descriptor_set;
18199 descriptor_write.dstBinding = 0;
18200 descriptor_write.descriptorCount = 1;
18201 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18202 descriptor_write.pTexelBufferView = &buffer_view;
18203
18204 // Set pImageInfo and pBufferInfo to invalid values, which should be
18205 // ignored for descriptorType ==
18206 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18207 // This will most likely produce a crash if the parameter_validation
18208 // layer
18209 // does not correctly ignore pImageInfo and pBufferInfo.
18210 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18211 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18212
18213 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18214
18215 m_errorMonitor->VerifyNotFound();
18216
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018217 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18218 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18219 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18220 vkDestroyBuffer(m_device->device(), buffer, NULL);
18221 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18222 }
18223}
18224
Tobin Ehlisf7428442016-10-25 07:58:24 -060018225TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18226 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18227
18228 ASSERT_NO_FATAL_FAILURE(InitState());
18229 // Create layout where two binding #s are "1"
18230 static const uint32_t NUM_BINDINGS = 3;
18231 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18232 dsl_binding[0].binding = 1;
18233 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18234 dsl_binding[0].descriptorCount = 1;
18235 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18236 dsl_binding[0].pImmutableSamplers = NULL;
18237 dsl_binding[1].binding = 0;
18238 dsl_binding[1].descriptorCount = 1;
18239 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18240 dsl_binding[1].descriptorCount = 1;
18241 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18242 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018243 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018244 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18245 dsl_binding[2].descriptorCount = 1;
18246 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18247 dsl_binding[2].pImmutableSamplers = NULL;
18248
18249 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18250 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18251 ds_layout_ci.pNext = NULL;
18252 ds_layout_ci.bindingCount = NUM_BINDINGS;
18253 ds_layout_ci.pBindings = dsl_binding;
18254 VkDescriptorSetLayout ds_layout;
18255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18256 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18257 m_errorMonitor->VerifyFound();
18258}
18259
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018260TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018261 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18262
18263 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018264
Tony Barbour552f6c02016-12-21 14:34:07 -070018265 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018266
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018267 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18268
18269 {
18270 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18271 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18272 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18273 m_errorMonitor->VerifyFound();
18274 }
18275
18276 {
18277 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18278 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18279 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18280 m_errorMonitor->VerifyFound();
18281 }
18282
18283 {
18284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18285 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18286 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18287 m_errorMonitor->VerifyFound();
18288 }
18289
18290 {
18291 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18292 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18293 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18294 m_errorMonitor->VerifyFound();
18295 }
18296
18297 {
18298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18299 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18300 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18301 m_errorMonitor->VerifyFound();
18302 }
18303
18304 {
18305 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18306 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18307 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18308 m_errorMonitor->VerifyFound();
18309 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018310
18311 {
18312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18313 VkRect2D scissor = {{-1, 0}, {16, 16}};
18314 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18315 m_errorMonitor->VerifyFound();
18316 }
18317
18318 {
18319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18320 VkRect2D scissor = {{0, -2}, {16, 16}};
18321 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18322 m_errorMonitor->VerifyFound();
18323 }
18324
18325 {
18326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18327 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18328 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18329 m_errorMonitor->VerifyFound();
18330 }
18331
18332 {
18333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18334 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18335 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18336 m_errorMonitor->VerifyFound();
18337 }
18338
Tony Barbour552f6c02016-12-21 14:34:07 -070018339 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018340}
18341
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018342// This is a positive test. No failures are expected.
18343TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18344 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18345 VkResult err;
18346
18347 ASSERT_NO_FATAL_FAILURE(InitState());
18348 m_errorMonitor->ExpectSuccess();
18349 VkDescriptorPoolSize ds_type_count = {};
18350 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18351 ds_type_count.descriptorCount = 2;
18352
18353 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18354 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18355 ds_pool_ci.pNext = NULL;
18356 ds_pool_ci.maxSets = 1;
18357 ds_pool_ci.poolSizeCount = 1;
18358 ds_pool_ci.pPoolSizes = &ds_type_count;
18359
18360 VkDescriptorPool ds_pool;
18361 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18362 ASSERT_VK_SUCCESS(err);
18363
18364 // Create layout with two uniform buffer descriptors w/ empty binding between them
18365 static const uint32_t NUM_BINDINGS = 3;
18366 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18367 dsl_binding[0].binding = 0;
18368 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18369 dsl_binding[0].descriptorCount = 1;
18370 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18371 dsl_binding[0].pImmutableSamplers = NULL;
18372 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018373 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018374 dsl_binding[2].binding = 2;
18375 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18376 dsl_binding[2].descriptorCount = 1;
18377 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18378 dsl_binding[2].pImmutableSamplers = NULL;
18379
18380 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18381 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18382 ds_layout_ci.pNext = NULL;
18383 ds_layout_ci.bindingCount = NUM_BINDINGS;
18384 ds_layout_ci.pBindings = dsl_binding;
18385 VkDescriptorSetLayout ds_layout;
18386 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18387 ASSERT_VK_SUCCESS(err);
18388
18389 VkDescriptorSet descriptor_set = {};
18390 VkDescriptorSetAllocateInfo alloc_info = {};
18391 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18392 alloc_info.descriptorSetCount = 1;
18393 alloc_info.descriptorPool = ds_pool;
18394 alloc_info.pSetLayouts = &ds_layout;
18395 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18396 ASSERT_VK_SUCCESS(err);
18397
18398 // Create a buffer to be used for update
18399 VkBufferCreateInfo buff_ci = {};
18400 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18401 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18402 buff_ci.size = 256;
18403 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18404 VkBuffer buffer;
18405 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18406 ASSERT_VK_SUCCESS(err);
18407 // Have to bind memory to buffer before descriptor update
18408 VkMemoryAllocateInfo mem_alloc = {};
18409 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18410 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018411 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018412 mem_alloc.memoryTypeIndex = 0;
18413
18414 VkMemoryRequirements mem_reqs;
18415 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18416 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18417 if (!pass) {
18418 vkDestroyBuffer(m_device->device(), buffer, NULL);
18419 return;
18420 }
18421
18422 VkDeviceMemory mem;
18423 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18424 ASSERT_VK_SUCCESS(err);
18425 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18426 ASSERT_VK_SUCCESS(err);
18427
18428 // Only update the descriptor at binding 2
18429 VkDescriptorBufferInfo buff_info = {};
18430 buff_info.buffer = buffer;
18431 buff_info.offset = 0;
18432 buff_info.range = VK_WHOLE_SIZE;
18433 VkWriteDescriptorSet descriptor_write = {};
18434 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18435 descriptor_write.dstBinding = 2;
18436 descriptor_write.descriptorCount = 1;
18437 descriptor_write.pTexelBufferView = nullptr;
18438 descriptor_write.pBufferInfo = &buff_info;
18439 descriptor_write.pImageInfo = nullptr;
18440 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18441 descriptor_write.dstSet = descriptor_set;
18442
18443 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18444
18445 m_errorMonitor->VerifyNotFound();
18446 // Cleanup
18447 vkFreeMemory(m_device->device(), mem, NULL);
18448 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18449 vkDestroyBuffer(m_device->device(), buffer, NULL);
18450 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18451}
18452
18453// This is a positive test. No failures are expected.
18454TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18455 VkResult err;
18456 bool pass;
18457
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018458 TEST_DESCRIPTION(
18459 "Create a buffer, allocate memory, bind memory, destroy "
18460 "the buffer, create an image, and bind the same memory to "
18461 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018462
18463 m_errorMonitor->ExpectSuccess();
18464
18465 ASSERT_NO_FATAL_FAILURE(InitState());
18466
18467 VkBuffer buffer;
18468 VkImage image;
18469 VkDeviceMemory mem;
18470 VkMemoryRequirements mem_reqs;
18471
18472 VkBufferCreateInfo buf_info = {};
18473 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18474 buf_info.pNext = NULL;
18475 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18476 buf_info.size = 256;
18477 buf_info.queueFamilyIndexCount = 0;
18478 buf_info.pQueueFamilyIndices = NULL;
18479 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18480 buf_info.flags = 0;
18481 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18482 ASSERT_VK_SUCCESS(err);
18483
18484 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18485
18486 VkMemoryAllocateInfo alloc_info = {};
18487 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18488 alloc_info.pNext = NULL;
18489 alloc_info.memoryTypeIndex = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070018490
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018491 // Ensure memory is big enough for both bindings
18492 alloc_info.allocationSize = 0x10000;
18493
18494 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18495 if (!pass) {
18496 vkDestroyBuffer(m_device->device(), buffer, NULL);
18497 return;
18498 }
18499
18500 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18501 ASSERT_VK_SUCCESS(err);
18502
18503 uint8_t *pData;
18504 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18505 ASSERT_VK_SUCCESS(err);
18506
18507 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18508
18509 vkUnmapMemory(m_device->device(), mem);
18510
18511 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18512 ASSERT_VK_SUCCESS(err);
18513
18514 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18515 // memory. In fact, it was never used by the GPU.
18516 // Just be be sure, wait for idle.
18517 vkDestroyBuffer(m_device->device(), buffer, NULL);
18518 vkDeviceWaitIdle(m_device->device());
18519
Tobin Ehlis6a005702016-12-28 15:25:56 -070018520 // Use optimal as some platforms report linear support but then fail image creation
18521 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18522 VkImageFormatProperties image_format_properties;
18523 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18524 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18525 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018526 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018527 vkFreeMemory(m_device->device(), mem, NULL);
18528 return;
18529 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018530 VkImageCreateInfo image_create_info = {};
18531 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18532 image_create_info.pNext = NULL;
18533 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18534 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18535 image_create_info.extent.width = 64;
18536 image_create_info.extent.height = 64;
18537 image_create_info.extent.depth = 1;
18538 image_create_info.mipLevels = 1;
18539 image_create_info.arrayLayers = 1;
18540 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018541 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018542 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18543 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18544 image_create_info.queueFamilyIndexCount = 0;
18545 image_create_info.pQueueFamilyIndices = NULL;
18546 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18547 image_create_info.flags = 0;
18548
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018549 /* Create a mappable image. It will be the texture if linear images are ok
18550 * to be textures or it will be the staging image if they are not.
18551 */
18552 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18553 ASSERT_VK_SUCCESS(err);
18554
18555 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18556
Tobin Ehlis6a005702016-12-28 15:25:56 -070018557 VkMemoryAllocateInfo mem_alloc = {};
18558 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18559 mem_alloc.pNext = NULL;
18560 mem_alloc.allocationSize = 0;
18561 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018562 mem_alloc.allocationSize = mem_reqs.size;
18563
18564 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18565 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018566 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018567 vkDestroyImage(m_device->device(), image, NULL);
18568 return;
18569 }
18570
18571 // VALIDATION FAILURE:
18572 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18573 ASSERT_VK_SUCCESS(err);
18574
18575 m_errorMonitor->VerifyNotFound();
18576
18577 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018578 vkDestroyImage(m_device->device(), image, NULL);
18579}
18580
Tony Barbourab713912017-02-02 14:17:35 -070018581// This is a positive test. No failures are expected.
18582TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18583 VkResult err;
18584
18585 TEST_DESCRIPTION(
18586 "Call all applicable destroy and free routines with NULL"
18587 "handles, expecting no validation errors");
18588
18589 m_errorMonitor->ExpectSuccess();
18590
18591 ASSERT_NO_FATAL_FAILURE(InitState());
18592 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18593 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18594 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18595 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18596 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18597 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18598 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18599 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18600 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18601 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18602 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18603 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18604 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18605 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18606 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18607 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18608 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18609 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18610 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18611 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18612
18613 VkCommandPool command_pool;
18614 VkCommandPoolCreateInfo pool_create_info{};
18615 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18616 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18617 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18618 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18619 VkCommandBuffer command_buffers[3] = {};
18620 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18621 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18622 command_buffer_allocate_info.commandPool = command_pool;
18623 command_buffer_allocate_info.commandBufferCount = 1;
18624 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18625 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18626 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18627 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18628
18629 VkDescriptorPoolSize ds_type_count = {};
18630 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18631 ds_type_count.descriptorCount = 1;
18632
18633 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18634 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18635 ds_pool_ci.pNext = NULL;
18636 ds_pool_ci.maxSets = 1;
18637 ds_pool_ci.poolSizeCount = 1;
18638 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18639 ds_pool_ci.pPoolSizes = &ds_type_count;
18640
18641 VkDescriptorPool ds_pool;
18642 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18643 ASSERT_VK_SUCCESS(err);
18644
18645 VkDescriptorSetLayoutBinding dsl_binding = {};
18646 dsl_binding.binding = 2;
18647 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18648 dsl_binding.descriptorCount = 1;
18649 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18650 dsl_binding.pImmutableSamplers = NULL;
18651 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18652 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18653 ds_layout_ci.pNext = NULL;
18654 ds_layout_ci.bindingCount = 1;
18655 ds_layout_ci.pBindings = &dsl_binding;
18656 VkDescriptorSetLayout ds_layout;
18657 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18658 ASSERT_VK_SUCCESS(err);
18659
18660 VkDescriptorSet descriptor_sets[3] = {};
18661 VkDescriptorSetAllocateInfo alloc_info = {};
18662 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18663 alloc_info.descriptorSetCount = 1;
18664 alloc_info.descriptorPool = ds_pool;
18665 alloc_info.pSetLayouts = &ds_layout;
18666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18667 ASSERT_VK_SUCCESS(err);
18668 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18671
18672 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18673
18674 m_errorMonitor->VerifyNotFound();
18675}
18676
Tony Barbour626994c2017-02-08 15:29:37 -070018677TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018678 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018679
18680 m_errorMonitor->ExpectSuccess();
18681
18682 ASSERT_NO_FATAL_FAILURE(InitState());
18683 VkCommandBuffer cmd_bufs[4];
18684 VkCommandBufferAllocateInfo alloc_info;
18685 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18686 alloc_info.pNext = NULL;
18687 alloc_info.commandBufferCount = 4;
18688 alloc_info.commandPool = m_commandPool;
18689 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18690 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18691 VkImageObj image(m_device);
18692 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18693 ASSERT_TRUE(image.initialized());
18694 VkCommandBufferBeginInfo cb_binfo;
18695 cb_binfo.pNext = NULL;
18696 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18697 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18698 cb_binfo.flags = 0;
18699 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18700 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18701 VkImageMemoryBarrier img_barrier = {};
18702 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18703 img_barrier.pNext = NULL;
18704 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18705 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18706 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18707 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18708 img_barrier.image = image.handle();
18709 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18710 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18711 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18712 img_barrier.subresourceRange.baseArrayLayer = 0;
18713 img_barrier.subresourceRange.baseMipLevel = 0;
18714 img_barrier.subresourceRange.layerCount = 1;
18715 img_barrier.subresourceRange.levelCount = 1;
18716 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18717 &img_barrier);
18718 vkEndCommandBuffer(cmd_bufs[0]);
18719 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18720 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18721 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18722 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18723 &img_barrier);
18724 vkEndCommandBuffer(cmd_bufs[1]);
18725 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
18726 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18727 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18728 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18729 &img_barrier);
18730 vkEndCommandBuffer(cmd_bufs[2]);
18731 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
18732 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
18733 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
18734 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18735 &img_barrier);
18736 vkEndCommandBuffer(cmd_bufs[3]);
18737
18738 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
18739 VkSemaphore semaphore1, semaphore2;
18740 VkSemaphoreCreateInfo semaphore_create_info{};
18741 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
18742 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
18743 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
18744 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
18745 VkSubmitInfo submit_info[3];
18746 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18747 submit_info[0].pNext = nullptr;
18748 submit_info[0].commandBufferCount = 1;
18749 submit_info[0].pCommandBuffers = &cmd_bufs[0];
18750 submit_info[0].signalSemaphoreCount = 1;
18751 submit_info[0].pSignalSemaphores = &semaphore1;
18752 submit_info[0].waitSemaphoreCount = 0;
18753 submit_info[0].pWaitDstStageMask = nullptr;
18754 submit_info[0].pWaitDstStageMask = flags;
18755 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18756 submit_info[1].pNext = nullptr;
18757 submit_info[1].commandBufferCount = 1;
18758 submit_info[1].pCommandBuffers = &cmd_bufs[1];
18759 submit_info[1].waitSemaphoreCount = 1;
18760 submit_info[1].pWaitSemaphores = &semaphore1;
18761 submit_info[1].signalSemaphoreCount = 1;
18762 submit_info[1].pSignalSemaphores = &semaphore2;
18763 submit_info[1].pWaitDstStageMask = flags;
18764 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18765 submit_info[2].pNext = nullptr;
18766 submit_info[2].commandBufferCount = 2;
18767 submit_info[2].pCommandBuffers = &cmd_bufs[2];
18768 submit_info[2].waitSemaphoreCount = 1;
18769 submit_info[2].pWaitSemaphores = &semaphore2;
18770 submit_info[2].signalSemaphoreCount = 0;
18771 submit_info[2].pSignalSemaphores = nullptr;
18772 submit_info[2].pWaitDstStageMask = flags;
18773 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
18774 vkQueueWaitIdle(m_device->m_queue);
18775
18776 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
18777 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
18778 m_errorMonitor->VerifyNotFound();
18779}
18780
Tobin Ehlis953e8392016-11-17 10:54:13 -070018781TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
18782 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
18783 // We previously had a bug where dynamic offset of inactive bindings was still being used
18784 VkResult err;
18785 m_errorMonitor->ExpectSuccess();
18786
18787 ASSERT_NO_FATAL_FAILURE(InitState());
18788 ASSERT_NO_FATAL_FAILURE(InitViewport());
18789 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18790
18791 VkDescriptorPoolSize ds_type_count = {};
18792 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18793 ds_type_count.descriptorCount = 3;
18794
18795 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18796 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18797 ds_pool_ci.pNext = NULL;
18798 ds_pool_ci.maxSets = 1;
18799 ds_pool_ci.poolSizeCount = 1;
18800 ds_pool_ci.pPoolSizes = &ds_type_count;
18801
18802 VkDescriptorPool ds_pool;
18803 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18804 ASSERT_VK_SUCCESS(err);
18805
18806 const uint32_t BINDING_COUNT = 3;
18807 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018808 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018809 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18810 dsl_binding[0].descriptorCount = 1;
18811 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18812 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018813 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018814 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18815 dsl_binding[1].descriptorCount = 1;
18816 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18817 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070018818 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070018819 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18820 dsl_binding[2].descriptorCount = 1;
18821 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18822 dsl_binding[2].pImmutableSamplers = NULL;
18823
18824 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18825 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18826 ds_layout_ci.pNext = NULL;
18827 ds_layout_ci.bindingCount = BINDING_COUNT;
18828 ds_layout_ci.pBindings = dsl_binding;
18829 VkDescriptorSetLayout ds_layout;
18830 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18831 ASSERT_VK_SUCCESS(err);
18832
18833 VkDescriptorSet descriptor_set;
18834 VkDescriptorSetAllocateInfo alloc_info = {};
18835 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18836 alloc_info.descriptorSetCount = 1;
18837 alloc_info.descriptorPool = ds_pool;
18838 alloc_info.pSetLayouts = &ds_layout;
18839 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18840 ASSERT_VK_SUCCESS(err);
18841
18842 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
18843 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
18844 pipeline_layout_ci.pNext = NULL;
18845 pipeline_layout_ci.setLayoutCount = 1;
18846 pipeline_layout_ci.pSetLayouts = &ds_layout;
18847
18848 VkPipelineLayout pipeline_layout;
18849 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
18850 ASSERT_VK_SUCCESS(err);
18851
18852 // Create two buffers to update the descriptors with
18853 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
18854 uint32_t qfi = 0;
18855 VkBufferCreateInfo buffCI = {};
18856 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18857 buffCI.size = 2048;
18858 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18859 buffCI.queueFamilyIndexCount = 1;
18860 buffCI.pQueueFamilyIndices = &qfi;
18861
18862 VkBuffer dyub1;
18863 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
18864 ASSERT_VK_SUCCESS(err);
18865 // buffer2
18866 buffCI.size = 1024;
18867 VkBuffer dyub2;
18868 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
18869 ASSERT_VK_SUCCESS(err);
18870 // Allocate memory and bind to buffers
18871 VkMemoryAllocateInfo mem_alloc[2] = {};
18872 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18873 mem_alloc[0].pNext = NULL;
18874 mem_alloc[0].memoryTypeIndex = 0;
18875 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18876 mem_alloc[1].pNext = NULL;
18877 mem_alloc[1].memoryTypeIndex = 0;
18878
18879 VkMemoryRequirements mem_reqs1;
18880 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
18881 VkMemoryRequirements mem_reqs2;
18882 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
18883 mem_alloc[0].allocationSize = mem_reqs1.size;
18884 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
18885 mem_alloc[1].allocationSize = mem_reqs2.size;
18886 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
18887 if (!pass) {
18888 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18889 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18890 return;
18891 }
18892
18893 VkDeviceMemory mem1;
18894 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
18895 ASSERT_VK_SUCCESS(err);
18896 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
18897 ASSERT_VK_SUCCESS(err);
18898 VkDeviceMemory mem2;
18899 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
18900 ASSERT_VK_SUCCESS(err);
18901 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
18902 ASSERT_VK_SUCCESS(err);
18903 // Update descriptors
18904 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
18905 buff_info[0].buffer = dyub1;
18906 buff_info[0].offset = 0;
18907 buff_info[0].range = 256;
18908 buff_info[1].buffer = dyub1;
18909 buff_info[1].offset = 256;
18910 buff_info[1].range = 512;
18911 buff_info[2].buffer = dyub2;
18912 buff_info[2].offset = 0;
18913 buff_info[2].range = 512;
18914
18915 VkWriteDescriptorSet descriptor_write;
18916 memset(&descriptor_write, 0, sizeof(descriptor_write));
18917 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18918 descriptor_write.dstSet = descriptor_set;
18919 descriptor_write.dstBinding = 0;
18920 descriptor_write.descriptorCount = BINDING_COUNT;
18921 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18922 descriptor_write.pBufferInfo = buff_info;
18923
18924 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18925
Tony Barbour552f6c02016-12-21 14:34:07 -070018926 m_commandBuffer->BeginCommandBuffer();
18927 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070018928
18929 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018930 char const *vsSource =
18931 "#version 450\n"
18932 "\n"
18933 "out gl_PerVertex { \n"
18934 " vec4 gl_Position;\n"
18935 "};\n"
18936 "void main(){\n"
18937 " gl_Position = vec4(1);\n"
18938 "}\n";
18939 char const *fsSource =
18940 "#version 450\n"
18941 "\n"
18942 "layout(location=0) out vec4 x;\n"
18943 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
18944 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
18945 "void main(){\n"
18946 " x = vec4(bar1.y) + vec4(bar2.y);\n"
18947 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070018948 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
18949 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
18950 VkPipelineObj pipe(m_device);
18951 pipe.SetViewport(m_viewports);
18952 pipe.SetScissor(m_scissors);
18953 pipe.AddShader(&vs);
18954 pipe.AddShader(&fs);
18955 pipe.AddColorAttachment();
18956 pipe.CreateVKPipeline(pipeline_layout, renderPass());
18957
18958 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
18959 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
18960 // we used to have a bug in this case.
18961 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
18962 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
18963 &descriptor_set, BINDING_COUNT, dyn_off);
18964 Draw(1, 0, 0, 0);
18965 m_errorMonitor->VerifyNotFound();
18966
18967 vkDestroyBuffer(m_device->device(), dyub1, NULL);
18968 vkDestroyBuffer(m_device->device(), dyub2, NULL);
18969 vkFreeMemory(m_device->device(), mem1, NULL);
18970 vkFreeMemory(m_device->device(), mem2, NULL);
18971
18972 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
18973 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18974 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18975}
18976
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018977TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018978 TEST_DESCRIPTION(
18979 "Ensure that validations handling of non-coherent memory "
18980 "mapping while using VK_WHOLE_SIZE does not cause access "
18981 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018982 VkResult err;
18983 uint8_t *pData;
18984 ASSERT_NO_FATAL_FAILURE(InitState());
18985
18986 VkDeviceMemory mem;
18987 VkMemoryRequirements mem_reqs;
18988 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018989 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018990 VkMemoryAllocateInfo alloc_info = {};
18991 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18992 alloc_info.pNext = NULL;
18993 alloc_info.memoryTypeIndex = 0;
18994
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070018995 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018996 alloc_info.allocationSize = allocation_size;
18997
18998 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
18999 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 -070019000 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019001 if (!pass) {
19002 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019003 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19004 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019005 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019006 pass = m_device->phy().set_memory_type(
19007 mem_reqs.memoryTypeBits, &alloc_info,
19008 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19009 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019010 if (!pass) {
19011 return;
19012 }
19013 }
19014 }
19015
19016 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19017 ASSERT_VK_SUCCESS(err);
19018
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019019 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019020 m_errorMonitor->ExpectSuccess();
19021 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19022 ASSERT_VK_SUCCESS(err);
19023 VkMappedMemoryRange mmr = {};
19024 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19025 mmr.memory = mem;
19026 mmr.offset = 0;
19027 mmr.size = VK_WHOLE_SIZE;
19028 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19029 ASSERT_VK_SUCCESS(err);
19030 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19031 ASSERT_VK_SUCCESS(err);
19032 m_errorMonitor->VerifyNotFound();
19033 vkUnmapMemory(m_device->device(), mem);
19034
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019035 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019036 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019037 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019038 ASSERT_VK_SUCCESS(err);
19039 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19040 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019041 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019042 mmr.size = VK_WHOLE_SIZE;
19043 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19044 ASSERT_VK_SUCCESS(err);
19045 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19046 ASSERT_VK_SUCCESS(err);
19047 m_errorMonitor->VerifyNotFound();
19048 vkUnmapMemory(m_device->device(), mem);
19049
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019050 // Map with offset and size
19051 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019052 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019053 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019054 ASSERT_VK_SUCCESS(err);
19055 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19056 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019057 mmr.offset = 4 * atom_size;
19058 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019059 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19060 ASSERT_VK_SUCCESS(err);
19061 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19062 ASSERT_VK_SUCCESS(err);
19063 m_errorMonitor->VerifyNotFound();
19064 vkUnmapMemory(m_device->device(), mem);
19065
19066 // Map without offset and flush WHOLE_SIZE with two separate offsets
19067 m_errorMonitor->ExpectSuccess();
19068 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19069 ASSERT_VK_SUCCESS(err);
19070 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19071 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019072 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019073 mmr.size = VK_WHOLE_SIZE;
19074 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19075 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019076 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019077 mmr.size = VK_WHOLE_SIZE;
19078 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19079 ASSERT_VK_SUCCESS(err);
19080 m_errorMonitor->VerifyNotFound();
19081 vkUnmapMemory(m_device->device(), mem);
19082
19083 vkFreeMemory(m_device->device(), mem, NULL);
19084}
19085
19086// This is a positive test. We used to expect error in this case but spec now allows it
19087TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19088 m_errorMonitor->ExpectSuccess();
19089 vk_testing::Fence testFence;
19090 VkFenceCreateInfo fenceInfo = {};
19091 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19092 fenceInfo.pNext = NULL;
19093
19094 ASSERT_NO_FATAL_FAILURE(InitState());
19095 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019096 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019097 VkResult result = vkResetFences(m_device->device(), 1, fences);
19098 ASSERT_VK_SUCCESS(result);
19099
19100 m_errorMonitor->VerifyNotFound();
19101}
19102
19103TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19104 m_errorMonitor->ExpectSuccess();
19105
19106 ASSERT_NO_FATAL_FAILURE(InitState());
19107 VkResult err;
19108
19109 // Record (empty!) command buffer that can be submitted multiple times
19110 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019111 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19112 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019113 m_commandBuffer->BeginCommandBuffer(&cbbi);
19114 m_commandBuffer->EndCommandBuffer();
19115
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019116 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019117 VkFence fence;
19118 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19119 ASSERT_VK_SUCCESS(err);
19120
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019121 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019122 VkSemaphore s1, s2;
19123 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19124 ASSERT_VK_SUCCESS(err);
19125 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19126 ASSERT_VK_SUCCESS(err);
19127
19128 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019129 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019130 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19131 ASSERT_VK_SUCCESS(err);
19132
19133 // Submit CB again, signaling s2.
19134 si.pSignalSemaphores = &s2;
19135 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19136 ASSERT_VK_SUCCESS(err);
19137
19138 // Wait for fence.
19139 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19140 ASSERT_VK_SUCCESS(err);
19141
19142 // CB is still in flight from second submission, but semaphore s1 is no
19143 // longer in flight. delete it.
19144 vkDestroySemaphore(m_device->device(), s1, nullptr);
19145
19146 m_errorMonitor->VerifyNotFound();
19147
19148 // Force device idle and clean up remaining objects
19149 vkDeviceWaitIdle(m_device->device());
19150 vkDestroySemaphore(m_device->device(), s2, nullptr);
19151 vkDestroyFence(m_device->device(), fence, nullptr);
19152}
19153
19154TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19155 m_errorMonitor->ExpectSuccess();
19156
19157 ASSERT_NO_FATAL_FAILURE(InitState());
19158 VkResult err;
19159
19160 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019161 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019162 VkFence f1;
19163 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19164 ASSERT_VK_SUCCESS(err);
19165
19166 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019167 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019168 VkFence f2;
19169 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19170 ASSERT_VK_SUCCESS(err);
19171
19172 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019173 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019174 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19175
19176 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019177 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019178 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19179
19180 // Should have both retired!
19181 vkDestroyFence(m_device->device(), f1, nullptr);
19182 vkDestroyFence(m_device->device(), f2, nullptr);
19183
19184 m_errorMonitor->VerifyNotFound();
19185}
19186
19187TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019188 TEST_DESCRIPTION(
19189 "Verify that creating an image view from an image with valid usage "
19190 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019191
19192 ASSERT_NO_FATAL_FAILURE(InitState());
19193
19194 m_errorMonitor->ExpectSuccess();
19195 // Verify that we can create a view with usage INPUT_ATTACHMENT
19196 VkImageObj image(m_device);
19197 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19198 ASSERT_TRUE(image.initialized());
19199 VkImageView imageView;
19200 VkImageViewCreateInfo ivci = {};
19201 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19202 ivci.image = image.handle();
19203 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19204 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19205 ivci.subresourceRange.layerCount = 1;
19206 ivci.subresourceRange.baseMipLevel = 0;
19207 ivci.subresourceRange.levelCount = 1;
19208 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19209
19210 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19211 m_errorMonitor->VerifyNotFound();
19212 vkDestroyImageView(m_device->device(), imageView, NULL);
19213}
19214
19215// This is a positive test. No failures are expected.
19216TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019217 TEST_DESCRIPTION(
19218 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19219 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019220
19221 ASSERT_NO_FATAL_FAILURE(InitState());
19222
19223 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019224 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019225
19226 m_errorMonitor->ExpectSuccess();
19227
19228 VkImage image;
19229 VkImageCreateInfo image_create_info = {};
19230 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19231 image_create_info.pNext = NULL;
19232 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19233 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19234 image_create_info.extent.width = 64;
19235 image_create_info.extent.height = 64;
19236 image_create_info.extent.depth = 1;
19237 image_create_info.mipLevels = 1;
19238 image_create_info.arrayLayers = 1;
19239 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19240 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19241 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19242 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19243 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19244 ASSERT_VK_SUCCESS(err);
19245
19246 VkMemoryRequirements memory_reqs;
19247 VkDeviceMemory memory_one, memory_two;
19248 bool pass;
19249 VkMemoryAllocateInfo memory_info = {};
19250 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19251 memory_info.pNext = NULL;
19252 memory_info.allocationSize = 0;
19253 memory_info.memoryTypeIndex = 0;
19254 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19255 // Find an image big enough to allow sparse mapping of 2 memory regions
19256 // Increase the image size until it is at least twice the
19257 // size of the required alignment, to ensure we can bind both
19258 // allocated memory blocks to the image on aligned offsets.
19259 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19260 vkDestroyImage(m_device->device(), image, nullptr);
19261 image_create_info.extent.width *= 2;
19262 image_create_info.extent.height *= 2;
19263 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19264 ASSERT_VK_SUCCESS(err);
19265 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19266 }
19267 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19268 // at the end of the first
19269 memory_info.allocationSize = memory_reqs.alignment;
19270 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19271 ASSERT_TRUE(pass);
19272 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19273 ASSERT_VK_SUCCESS(err);
19274 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19275 ASSERT_VK_SUCCESS(err);
19276 VkSparseMemoryBind binds[2];
19277 binds[0].flags = 0;
19278 binds[0].memory = memory_one;
19279 binds[0].memoryOffset = 0;
19280 binds[0].resourceOffset = 0;
19281 binds[0].size = memory_info.allocationSize;
19282 binds[1].flags = 0;
19283 binds[1].memory = memory_two;
19284 binds[1].memoryOffset = 0;
19285 binds[1].resourceOffset = memory_info.allocationSize;
19286 binds[1].size = memory_info.allocationSize;
19287
19288 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19289 opaqueBindInfo.image = image;
19290 opaqueBindInfo.bindCount = 2;
19291 opaqueBindInfo.pBinds = binds;
19292
19293 VkFence fence = VK_NULL_HANDLE;
19294 VkBindSparseInfo bindSparseInfo = {};
19295 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19296 bindSparseInfo.imageOpaqueBindCount = 1;
19297 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19298
19299 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19300 vkQueueWaitIdle(m_device->m_queue);
19301 vkDestroyImage(m_device->device(), image, NULL);
19302 vkFreeMemory(m_device->device(), memory_one, NULL);
19303 vkFreeMemory(m_device->device(), memory_two, NULL);
19304 m_errorMonitor->VerifyNotFound();
19305}
19306
19307TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019308 TEST_DESCRIPTION(
19309 "Ensure that CmdBeginRenderPass with an attachment's "
19310 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19311 "the command buffer has prior knowledge of that "
19312 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019313
19314 m_errorMonitor->ExpectSuccess();
19315
19316 ASSERT_NO_FATAL_FAILURE(InitState());
19317
19318 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019319 VkAttachmentDescription attachment = {0,
19320 VK_FORMAT_R8G8B8A8_UNORM,
19321 VK_SAMPLE_COUNT_1_BIT,
19322 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19323 VK_ATTACHMENT_STORE_OP_STORE,
19324 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19325 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19326 VK_IMAGE_LAYOUT_UNDEFINED,
19327 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019328
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019329 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019330
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019331 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019332
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019333 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019334
19335 VkRenderPass rp;
19336 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19337 ASSERT_VK_SUCCESS(err);
19338
19339 // A compatible framebuffer.
19340 VkImageObj image(m_device);
19341 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19342 ASSERT_TRUE(image.initialized());
19343
19344 VkImageViewCreateInfo ivci = {
19345 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19346 nullptr,
19347 0,
19348 image.handle(),
19349 VK_IMAGE_VIEW_TYPE_2D,
19350 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019351 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19352 VK_COMPONENT_SWIZZLE_IDENTITY},
19353 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019354 };
19355 VkImageView view;
19356 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19357 ASSERT_VK_SUCCESS(err);
19358
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019359 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019360 VkFramebuffer fb;
19361 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19362 ASSERT_VK_SUCCESS(err);
19363
19364 // Record a single command buffer which uses this renderpass twice. The
19365 // bug is triggered at the beginning of the second renderpass, when the
19366 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019367 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 -070019368 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019369 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19370 vkCmdEndRenderPass(m_commandBuffer->handle());
19371 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19372
19373 m_errorMonitor->VerifyNotFound();
19374
19375 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019376 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019377
19378 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19379 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19380 vkDestroyImageView(m_device->device(), view, nullptr);
19381}
19382
19383TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019384 TEST_DESCRIPTION(
19385 "This test should pass. Create a Framebuffer and "
19386 "command buffer, bind them together, then destroy "
19387 "command pool and framebuffer and verify there are no "
19388 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019389
19390 m_errorMonitor->ExpectSuccess();
19391
19392 ASSERT_NO_FATAL_FAILURE(InitState());
19393
19394 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019395 VkAttachmentDescription attachment = {0,
19396 VK_FORMAT_R8G8B8A8_UNORM,
19397 VK_SAMPLE_COUNT_1_BIT,
19398 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19399 VK_ATTACHMENT_STORE_OP_STORE,
19400 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19401 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19402 VK_IMAGE_LAYOUT_UNDEFINED,
19403 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019404
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019405 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019406
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019407 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019408
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019409 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019410
19411 VkRenderPass rp;
19412 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19413 ASSERT_VK_SUCCESS(err);
19414
19415 // A compatible framebuffer.
19416 VkImageObj image(m_device);
19417 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19418 ASSERT_TRUE(image.initialized());
19419
19420 VkImageViewCreateInfo ivci = {
19421 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19422 nullptr,
19423 0,
19424 image.handle(),
19425 VK_IMAGE_VIEW_TYPE_2D,
19426 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019427 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19428 VK_COMPONENT_SWIZZLE_IDENTITY},
19429 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019430 };
19431 VkImageView view;
19432 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19433 ASSERT_VK_SUCCESS(err);
19434
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019435 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019436 VkFramebuffer fb;
19437 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19438 ASSERT_VK_SUCCESS(err);
19439
19440 // Explicitly create a command buffer to bind the FB to so that we can then
19441 // destroy the command pool in order to implicitly free command buffer
19442 VkCommandPool command_pool;
19443 VkCommandPoolCreateInfo pool_create_info{};
19444 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19445 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19446 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19447 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19448
19449 VkCommandBuffer command_buffer;
19450 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19451 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19452 command_buffer_allocate_info.commandPool = command_pool;
19453 command_buffer_allocate_info.commandBufferCount = 1;
19454 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19455 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19456
19457 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019458 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 -060019459 VkCommandBufferBeginInfo begin_info{};
19460 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19461 vkBeginCommandBuffer(command_buffer, &begin_info);
19462
19463 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19464 vkCmdEndRenderPass(command_buffer);
19465 vkEndCommandBuffer(command_buffer);
19466 vkDestroyImageView(m_device->device(), view, nullptr);
19467 // Destroy command pool to implicitly free command buffer
19468 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19469 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19470 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19471 m_errorMonitor->VerifyNotFound();
19472}
19473
19474TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019475 TEST_DESCRIPTION(
19476 "Ensure that CmdBeginRenderPass applies the layout "
19477 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019478
19479 m_errorMonitor->ExpectSuccess();
19480
19481 ASSERT_NO_FATAL_FAILURE(InitState());
19482
19483 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019484 VkAttachmentDescription attachment = {0,
19485 VK_FORMAT_R8G8B8A8_UNORM,
19486 VK_SAMPLE_COUNT_1_BIT,
19487 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19488 VK_ATTACHMENT_STORE_OP_STORE,
19489 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19490 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19491 VK_IMAGE_LAYOUT_UNDEFINED,
19492 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019493
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019494 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019495
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019496 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019497
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019498 VkSubpassDependency dep = {0,
19499 0,
19500 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19501 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19502 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19503 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19504 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019505
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019506 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019507
19508 VkResult err;
19509 VkRenderPass rp;
19510 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19511 ASSERT_VK_SUCCESS(err);
19512
19513 // A compatible framebuffer.
19514 VkImageObj image(m_device);
19515 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19516 ASSERT_TRUE(image.initialized());
19517
19518 VkImageViewCreateInfo ivci = {
19519 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19520 nullptr,
19521 0,
19522 image.handle(),
19523 VK_IMAGE_VIEW_TYPE_2D,
19524 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019525 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19526 VK_COMPONENT_SWIZZLE_IDENTITY},
19527 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019528 };
19529 VkImageView view;
19530 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19531 ASSERT_VK_SUCCESS(err);
19532
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019533 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019534 VkFramebuffer fb;
19535 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19536 ASSERT_VK_SUCCESS(err);
19537
19538 // Record a single command buffer which issues a pipeline barrier w/
19539 // image memory barrier for the attachment. This detects the previously
19540 // missing tracking of the subpass layout by throwing a validation error
19541 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019542 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 -070019543 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019544 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19545
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019546 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19547 nullptr,
19548 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19549 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19550 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19551 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19552 VK_QUEUE_FAMILY_IGNORED,
19553 VK_QUEUE_FAMILY_IGNORED,
19554 image.handle(),
19555 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019556 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019557 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19558 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019559
19560 vkCmdEndRenderPass(m_commandBuffer->handle());
19561 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019562 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019563
19564 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19565 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19566 vkDestroyImageView(m_device->device(), view, nullptr);
19567}
19568
19569TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019570 TEST_DESCRIPTION(
19571 "Validate that when an imageView of a depth/stencil image "
19572 "is used as a depth/stencil framebuffer attachment, the "
19573 "aspectMask is ignored and both depth and stencil image "
19574 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019575
19576 VkFormatProperties format_properties;
19577 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19578 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19579 return;
19580 }
19581
19582 m_errorMonitor->ExpectSuccess();
19583
19584 ASSERT_NO_FATAL_FAILURE(InitState());
19585
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019586 VkAttachmentDescription attachment = {0,
19587 VK_FORMAT_D32_SFLOAT_S8_UINT,
19588 VK_SAMPLE_COUNT_1_BIT,
19589 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19590 VK_ATTACHMENT_STORE_OP_STORE,
19591 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19592 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19593 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19594 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019595
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019596 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019597
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019598 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019599
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019600 VkSubpassDependency dep = {0,
19601 0,
19602 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19603 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19604 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19605 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19606 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019607
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019608 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019609
19610 VkResult err;
19611 VkRenderPass rp;
19612 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19613 ASSERT_VK_SUCCESS(err);
19614
19615 VkImageObj image(m_device);
19616 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019617 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019618 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019619 ASSERT_TRUE(image.initialized());
19620 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19621
19622 VkImageViewCreateInfo ivci = {
19623 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19624 nullptr,
19625 0,
19626 image.handle(),
19627 VK_IMAGE_VIEW_TYPE_2D,
19628 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019629 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19630 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019631 };
19632 VkImageView view;
19633 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19634 ASSERT_VK_SUCCESS(err);
19635
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019636 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019637 VkFramebuffer fb;
19638 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19639 ASSERT_VK_SUCCESS(err);
19640
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019641 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 -070019642 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019643 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19644
19645 VkImageMemoryBarrier imb = {};
19646 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19647 imb.pNext = nullptr;
19648 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19649 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19650 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19651 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19652 imb.srcQueueFamilyIndex = 0;
19653 imb.dstQueueFamilyIndex = 0;
19654 imb.image = image.handle();
19655 imb.subresourceRange.aspectMask = 0x6;
19656 imb.subresourceRange.baseMipLevel = 0;
19657 imb.subresourceRange.levelCount = 0x1;
19658 imb.subresourceRange.baseArrayLayer = 0;
19659 imb.subresourceRange.layerCount = 0x1;
19660
19661 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019662 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19663 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019664
19665 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019666 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019667 QueueCommandBuffer(false);
19668 m_errorMonitor->VerifyNotFound();
19669
19670 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19671 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19672 vkDestroyImageView(m_device->device(), view, nullptr);
19673}
19674
19675TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019676 TEST_DESCRIPTION(
19677 "Ensure that layout transitions work correctly without "
19678 "errors, when an attachment reference is "
19679 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019680
19681 m_errorMonitor->ExpectSuccess();
19682
19683 ASSERT_NO_FATAL_FAILURE(InitState());
19684
19685 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019686 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019687
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019688 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019689
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019690 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019691
19692 VkRenderPass rp;
19693 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19694 ASSERT_VK_SUCCESS(err);
19695
19696 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019697 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019698 VkFramebuffer fb;
19699 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19700 ASSERT_VK_SUCCESS(err);
19701
19702 // Record a command buffer which just begins and ends the renderpass. The
19703 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019704 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 -070019705 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019706 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19707 vkCmdEndRenderPass(m_commandBuffer->handle());
19708 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019709 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019710
19711 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19712 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19713}
19714
19715// This is a positive test. No errors are expected.
19716TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019717 TEST_DESCRIPTION(
19718 "Create a stencil-only attachment with a LOAD_OP set to "
19719 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019720 VkResult result = VK_SUCCESS;
19721 VkImageFormatProperties formatProps;
19722 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019723 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
19724 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019725 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
19726 return;
19727 }
19728
19729 ASSERT_NO_FATAL_FAILURE(InitState());
19730 VkFormat depth_stencil_fmt = VK_FORMAT_D24_UNORM_S8_UINT;
19731 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019732 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019733 VkAttachmentDescription att = {};
19734 VkAttachmentReference ref = {};
19735 att.format = depth_stencil_fmt;
19736 att.samples = VK_SAMPLE_COUNT_1_BIT;
19737 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
19738 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
19739 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
19740 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
19741 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19742 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19743
19744 VkClearValue clear;
19745 clear.depthStencil.depth = 1.0;
19746 clear.depthStencil.stencil = 0;
19747 ref.attachment = 0;
19748 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19749
19750 VkSubpassDescription subpass = {};
19751 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
19752 subpass.flags = 0;
19753 subpass.inputAttachmentCount = 0;
19754 subpass.pInputAttachments = NULL;
19755 subpass.colorAttachmentCount = 0;
19756 subpass.pColorAttachments = NULL;
19757 subpass.pResolveAttachments = NULL;
19758 subpass.pDepthStencilAttachment = &ref;
19759 subpass.preserveAttachmentCount = 0;
19760 subpass.pPreserveAttachments = NULL;
19761
19762 VkRenderPass rp;
19763 VkRenderPassCreateInfo rp_info = {};
19764 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
19765 rp_info.attachmentCount = 1;
19766 rp_info.pAttachments = &att;
19767 rp_info.subpassCount = 1;
19768 rp_info.pSubpasses = &subpass;
19769 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
19770 ASSERT_VK_SUCCESS(result);
19771
19772 VkImageView *depthView = m_depthStencil->BindInfo();
19773 VkFramebufferCreateInfo fb_info = {};
19774 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
19775 fb_info.pNext = NULL;
19776 fb_info.renderPass = rp;
19777 fb_info.attachmentCount = 1;
19778 fb_info.pAttachments = depthView;
19779 fb_info.width = 100;
19780 fb_info.height = 100;
19781 fb_info.layers = 1;
19782 VkFramebuffer fb;
19783 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
19784 ASSERT_VK_SUCCESS(result);
19785
19786 VkRenderPassBeginInfo rpbinfo = {};
19787 rpbinfo.clearValueCount = 1;
19788 rpbinfo.pClearValues = &clear;
19789 rpbinfo.pNext = NULL;
19790 rpbinfo.renderPass = rp;
19791 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
19792 rpbinfo.renderArea.extent.width = 100;
19793 rpbinfo.renderArea.extent.height = 100;
19794 rpbinfo.renderArea.offset.x = 0;
19795 rpbinfo.renderArea.offset.y = 0;
19796 rpbinfo.framebuffer = fb;
19797
19798 VkFence fence = {};
19799 VkFenceCreateInfo fence_ci = {};
19800 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19801 fence_ci.pNext = nullptr;
19802 fence_ci.flags = 0;
19803 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
19804 ASSERT_VK_SUCCESS(result);
19805
19806 m_commandBuffer->BeginCommandBuffer();
19807 m_commandBuffer->BeginRenderPass(rpbinfo);
19808 m_commandBuffer->EndRenderPass();
19809 m_commandBuffer->EndCommandBuffer();
19810 m_commandBuffer->QueueCommandBuffer(fence);
19811
19812 VkImageObj destImage(m_device);
19813 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 -070019814 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019815 VkImageMemoryBarrier barrier = {};
19816 VkImageSubresourceRange range;
19817 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19818 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19819 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
19820 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19821 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19822 barrier.image = m_depthStencil->handle();
19823 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19824 range.baseMipLevel = 0;
19825 range.levelCount = 1;
19826 range.baseArrayLayer = 0;
19827 range.layerCount = 1;
19828 barrier.subresourceRange = range;
19829 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19830 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
19831 cmdbuf.BeginCommandBuffer();
19832 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 -070019833 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019834 barrier.srcAccessMask = 0;
19835 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
19836 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19837 barrier.image = destImage.handle();
19838 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19839 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 -070019840 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019841 VkImageCopy cregion;
19842 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19843 cregion.srcSubresource.mipLevel = 0;
19844 cregion.srcSubresource.baseArrayLayer = 0;
19845 cregion.srcSubresource.layerCount = 1;
19846 cregion.srcOffset.x = 0;
19847 cregion.srcOffset.y = 0;
19848 cregion.srcOffset.z = 0;
19849 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
19850 cregion.dstSubresource.mipLevel = 0;
19851 cregion.dstSubresource.baseArrayLayer = 0;
19852 cregion.dstSubresource.layerCount = 1;
19853 cregion.dstOffset.x = 0;
19854 cregion.dstOffset.y = 0;
19855 cregion.dstOffset.z = 0;
19856 cregion.extent.width = 100;
19857 cregion.extent.height = 100;
19858 cregion.extent.depth = 1;
19859 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019860 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019861 cmdbuf.EndCommandBuffer();
19862
19863 VkSubmitInfo submit_info;
19864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19865 submit_info.pNext = NULL;
19866 submit_info.waitSemaphoreCount = 0;
19867 submit_info.pWaitSemaphores = NULL;
19868 submit_info.pWaitDstStageMask = NULL;
19869 submit_info.commandBufferCount = 1;
19870 submit_info.pCommandBuffers = &cmdbuf.handle();
19871 submit_info.signalSemaphoreCount = 0;
19872 submit_info.pSignalSemaphores = NULL;
19873
19874 m_errorMonitor->ExpectSuccess();
19875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
19876 m_errorMonitor->VerifyNotFound();
19877
19878 vkQueueWaitIdle(m_device->m_queue);
19879 vkDestroyFence(m_device->device(), fence, nullptr);
19880 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19881 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19882}
19883
19884// This is a positive test. No errors should be generated.
19885TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
19886 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
19887
19888 m_errorMonitor->ExpectSuccess();
19889 ASSERT_NO_FATAL_FAILURE(InitState());
19890
19891 VkEvent event;
19892 VkEventCreateInfo event_create_info{};
19893 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
19894 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
19895
19896 VkCommandPool command_pool;
19897 VkCommandPoolCreateInfo pool_create_info{};
19898 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19899 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19900 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19901 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19902
19903 VkCommandBuffer command_buffer;
19904 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19905 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19906 command_buffer_allocate_info.commandPool = command_pool;
19907 command_buffer_allocate_info.commandBufferCount = 1;
19908 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19909 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19910
19911 VkQueue queue = VK_NULL_HANDLE;
19912 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
19913
19914 {
19915 VkCommandBufferBeginInfo begin_info{};
19916 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19917 vkBeginCommandBuffer(command_buffer, &begin_info);
19918
19919 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 -070019920 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019921 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
19922 vkEndCommandBuffer(command_buffer);
19923 }
19924 {
19925 VkSubmitInfo submit_info{};
19926 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19927 submit_info.commandBufferCount = 1;
19928 submit_info.pCommandBuffers = &command_buffer;
19929 submit_info.signalSemaphoreCount = 0;
19930 submit_info.pSignalSemaphores = nullptr;
19931 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
19932 }
19933 { vkSetEvent(m_device->device(), event); }
19934
19935 vkQueueWaitIdle(queue);
19936
19937 vkDestroyEvent(m_device->device(), event, nullptr);
19938 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
19939 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19940
19941 m_errorMonitor->VerifyNotFound();
19942}
19943// This is a positive test. No errors should be generated.
19944TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
19945 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
19946
19947 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019948 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019949
19950 m_errorMonitor->ExpectSuccess();
19951
19952 VkQueryPool query_pool;
19953 VkQueryPoolCreateInfo query_pool_create_info{};
19954 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
19955 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
19956 query_pool_create_info.queryCount = 1;
19957 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
19958
19959 VkCommandPool command_pool;
19960 VkCommandPoolCreateInfo pool_create_info{};
19961 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19962 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19963 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19964 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19965
19966 VkCommandBuffer command_buffer;
19967 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19968 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19969 command_buffer_allocate_info.commandPool = command_pool;
19970 command_buffer_allocate_info.commandBufferCount = 1;
19971 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19972 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19973
19974 VkCommandBuffer secondary_command_buffer;
19975 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
19976 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
19977
19978 VkQueue queue = VK_NULL_HANDLE;
19979 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
19980
19981 uint32_t qfi = 0;
19982 VkBufferCreateInfo buff_create_info = {};
19983 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19984 buff_create_info.size = 1024;
19985 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
19986 buff_create_info.queueFamilyIndexCount = 1;
19987 buff_create_info.pQueueFamilyIndices = &qfi;
19988
19989 VkResult err;
19990 VkBuffer buffer;
19991 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
19992 ASSERT_VK_SUCCESS(err);
19993 VkMemoryAllocateInfo mem_alloc = {};
19994 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19995 mem_alloc.pNext = NULL;
19996 mem_alloc.allocationSize = 1024;
19997 mem_alloc.memoryTypeIndex = 0;
19998
19999 VkMemoryRequirements memReqs;
20000 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20001 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20002 if (!pass) {
20003 vkDestroyBuffer(m_device->device(), buffer, NULL);
20004 return;
20005 }
20006
20007 VkDeviceMemory mem;
20008 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20009 ASSERT_VK_SUCCESS(err);
20010 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20011 ASSERT_VK_SUCCESS(err);
20012
20013 VkCommandBufferInheritanceInfo hinfo = {};
20014 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20015 hinfo.renderPass = VK_NULL_HANDLE;
20016 hinfo.subpass = 0;
20017 hinfo.framebuffer = VK_NULL_HANDLE;
20018 hinfo.occlusionQueryEnable = VK_FALSE;
20019 hinfo.queryFlags = 0;
20020 hinfo.pipelineStatistics = 0;
20021
20022 {
20023 VkCommandBufferBeginInfo begin_info{};
20024 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20025 begin_info.pInheritanceInfo = &hinfo;
20026 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20027
20028 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20029 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20030
20031 vkEndCommandBuffer(secondary_command_buffer);
20032
20033 begin_info.pInheritanceInfo = nullptr;
20034 vkBeginCommandBuffer(command_buffer, &begin_info);
20035
20036 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20037 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20038
20039 vkEndCommandBuffer(command_buffer);
20040 }
20041 {
20042 VkSubmitInfo submit_info{};
20043 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20044 submit_info.commandBufferCount = 1;
20045 submit_info.pCommandBuffers = &command_buffer;
20046 submit_info.signalSemaphoreCount = 0;
20047 submit_info.pSignalSemaphores = nullptr;
20048 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20049 }
20050
20051 vkQueueWaitIdle(queue);
20052
20053 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20054 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20055 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20056 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20057 vkDestroyBuffer(m_device->device(), buffer, NULL);
20058 vkFreeMemory(m_device->device(), mem, NULL);
20059
20060 m_errorMonitor->VerifyNotFound();
20061}
20062
20063// This is a positive test. No errors should be generated.
20064TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20065 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20066
20067 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020068 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020069
20070 m_errorMonitor->ExpectSuccess();
20071
20072 VkQueryPool query_pool;
20073 VkQueryPoolCreateInfo query_pool_create_info{};
20074 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20075 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20076 query_pool_create_info.queryCount = 1;
20077 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20078
20079 VkCommandPool command_pool;
20080 VkCommandPoolCreateInfo pool_create_info{};
20081 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20082 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20083 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20084 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20085
20086 VkCommandBuffer command_buffer[2];
20087 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20088 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20089 command_buffer_allocate_info.commandPool = command_pool;
20090 command_buffer_allocate_info.commandBufferCount = 2;
20091 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20092 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20093
20094 VkQueue queue = VK_NULL_HANDLE;
20095 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20096
20097 uint32_t qfi = 0;
20098 VkBufferCreateInfo buff_create_info = {};
20099 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20100 buff_create_info.size = 1024;
20101 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20102 buff_create_info.queueFamilyIndexCount = 1;
20103 buff_create_info.pQueueFamilyIndices = &qfi;
20104
20105 VkResult err;
20106 VkBuffer buffer;
20107 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20108 ASSERT_VK_SUCCESS(err);
20109 VkMemoryAllocateInfo mem_alloc = {};
20110 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20111 mem_alloc.pNext = NULL;
20112 mem_alloc.allocationSize = 1024;
20113 mem_alloc.memoryTypeIndex = 0;
20114
20115 VkMemoryRequirements memReqs;
20116 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20117 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20118 if (!pass) {
20119 vkDestroyBuffer(m_device->device(), buffer, NULL);
20120 return;
20121 }
20122
20123 VkDeviceMemory mem;
20124 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20125 ASSERT_VK_SUCCESS(err);
20126 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20127 ASSERT_VK_SUCCESS(err);
20128
20129 {
20130 VkCommandBufferBeginInfo begin_info{};
20131 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20132 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20133
20134 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20135 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20136
20137 vkEndCommandBuffer(command_buffer[0]);
20138
20139 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20140
20141 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20142
20143 vkEndCommandBuffer(command_buffer[1]);
20144 }
20145 {
20146 VkSubmitInfo submit_info{};
20147 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20148 submit_info.commandBufferCount = 2;
20149 submit_info.pCommandBuffers = command_buffer;
20150 submit_info.signalSemaphoreCount = 0;
20151 submit_info.pSignalSemaphores = nullptr;
20152 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20153 }
20154
20155 vkQueueWaitIdle(queue);
20156
20157 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20158 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20159 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20160 vkDestroyBuffer(m_device->device(), buffer, NULL);
20161 vkFreeMemory(m_device->device(), mem, NULL);
20162
20163 m_errorMonitor->VerifyNotFound();
20164}
20165
Tony Barbourc46924f2016-11-04 11:49:52 -060020166TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020167 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20168
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020169 ASSERT_NO_FATAL_FAILURE(InitState());
20170 VkEvent event;
20171 VkEventCreateInfo event_create_info{};
20172 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20173 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20174
20175 VkCommandPool command_pool;
20176 VkCommandPoolCreateInfo pool_create_info{};
20177 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20178 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20179 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20180 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20181
20182 VkCommandBuffer command_buffer;
20183 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20184 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20185 command_buffer_allocate_info.commandPool = command_pool;
20186 command_buffer_allocate_info.commandBufferCount = 1;
20187 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20188 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20189
20190 VkQueue queue = VK_NULL_HANDLE;
20191 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20192
20193 {
20194 VkCommandBufferBeginInfo begin_info{};
20195 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20196 vkBeginCommandBuffer(command_buffer, &begin_info);
20197
20198 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020199 vkEndCommandBuffer(command_buffer);
20200 }
20201 {
20202 VkSubmitInfo submit_info{};
20203 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20204 submit_info.commandBufferCount = 1;
20205 submit_info.pCommandBuffers = &command_buffer;
20206 submit_info.signalSemaphoreCount = 0;
20207 submit_info.pSignalSemaphores = nullptr;
20208 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20209 }
20210 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20212 "that is already in use by a "
20213 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020214 vkSetEvent(m_device->device(), event);
20215 m_errorMonitor->VerifyFound();
20216 }
20217
20218 vkQueueWaitIdle(queue);
20219
20220 vkDestroyEvent(m_device->device(), event, nullptr);
20221 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20222 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20223}
20224
20225// This is a positive test. No errors should be generated.
20226TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020227 TEST_DESCRIPTION(
20228 "Two command buffers with two separate fences are each "
20229 "run through a Submit & WaitForFences cycle 3 times. This "
20230 "previously revealed a bug so running this positive test "
20231 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020232 m_errorMonitor->ExpectSuccess();
20233
20234 ASSERT_NO_FATAL_FAILURE(InitState());
20235 VkQueue queue = VK_NULL_HANDLE;
20236 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20237
20238 static const uint32_t NUM_OBJECTS = 2;
20239 static const uint32_t NUM_FRAMES = 3;
20240 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20241 VkFence fences[NUM_OBJECTS] = {};
20242
20243 VkCommandPool cmd_pool;
20244 VkCommandPoolCreateInfo cmd_pool_ci = {};
20245 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20246 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20247 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20248 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20249 ASSERT_VK_SUCCESS(err);
20250
20251 VkCommandBufferAllocateInfo cmd_buf_info = {};
20252 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20253 cmd_buf_info.commandPool = cmd_pool;
20254 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20255 cmd_buf_info.commandBufferCount = 1;
20256
20257 VkFenceCreateInfo fence_ci = {};
20258 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20259 fence_ci.pNext = nullptr;
20260 fence_ci.flags = 0;
20261
20262 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20263 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20264 ASSERT_VK_SUCCESS(err);
20265 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20266 ASSERT_VK_SUCCESS(err);
20267 }
20268
20269 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20270 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20271 // Create empty cmd buffer
20272 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20273 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20274
20275 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20276 ASSERT_VK_SUCCESS(err);
20277 err = vkEndCommandBuffer(cmd_buffers[obj]);
20278 ASSERT_VK_SUCCESS(err);
20279
20280 VkSubmitInfo submit_info = {};
20281 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20282 submit_info.commandBufferCount = 1;
20283 submit_info.pCommandBuffers = &cmd_buffers[obj];
20284 // Submit cmd buffer and wait for fence
20285 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20286 ASSERT_VK_SUCCESS(err);
20287 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20288 ASSERT_VK_SUCCESS(err);
20289 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20290 ASSERT_VK_SUCCESS(err);
20291 }
20292 }
20293 m_errorMonitor->VerifyNotFound();
20294 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20295 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20296 vkDestroyFence(m_device->device(), fences[i], nullptr);
20297 }
20298}
20299// This is a positive test. No errors should be generated.
20300TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020301 TEST_DESCRIPTION(
20302 "Two command buffers, each in a separate QueueSubmit call "
20303 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020304
20305 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020306 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020307
20308 m_errorMonitor->ExpectSuccess();
20309
20310 VkSemaphore semaphore;
20311 VkSemaphoreCreateInfo semaphore_create_info{};
20312 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20313 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20314
20315 VkCommandPool command_pool;
20316 VkCommandPoolCreateInfo pool_create_info{};
20317 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20318 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20319 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20320 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20321
20322 VkCommandBuffer command_buffer[2];
20323 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20324 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20325 command_buffer_allocate_info.commandPool = command_pool;
20326 command_buffer_allocate_info.commandBufferCount = 2;
20327 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20328 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20329
20330 VkQueue queue = VK_NULL_HANDLE;
20331 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20332
20333 {
20334 VkCommandBufferBeginInfo begin_info{};
20335 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20336 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20337
20338 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 -070020339 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020340
20341 VkViewport viewport{};
20342 viewport.maxDepth = 1.0f;
20343 viewport.minDepth = 0.0f;
20344 viewport.width = 512;
20345 viewport.height = 512;
20346 viewport.x = 0;
20347 viewport.y = 0;
20348 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20349 vkEndCommandBuffer(command_buffer[0]);
20350 }
20351 {
20352 VkCommandBufferBeginInfo begin_info{};
20353 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20354 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20355
20356 VkViewport viewport{};
20357 viewport.maxDepth = 1.0f;
20358 viewport.minDepth = 0.0f;
20359 viewport.width = 512;
20360 viewport.height = 512;
20361 viewport.x = 0;
20362 viewport.y = 0;
20363 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20364 vkEndCommandBuffer(command_buffer[1]);
20365 }
20366 {
20367 VkSubmitInfo submit_info{};
20368 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20369 submit_info.commandBufferCount = 1;
20370 submit_info.pCommandBuffers = &command_buffer[0];
20371 submit_info.signalSemaphoreCount = 1;
20372 submit_info.pSignalSemaphores = &semaphore;
20373 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20374 }
20375 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020376 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020377 VkSubmitInfo submit_info{};
20378 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20379 submit_info.commandBufferCount = 1;
20380 submit_info.pCommandBuffers = &command_buffer[1];
20381 submit_info.waitSemaphoreCount = 1;
20382 submit_info.pWaitSemaphores = &semaphore;
20383 submit_info.pWaitDstStageMask = flags;
20384 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20385 }
20386
20387 vkQueueWaitIdle(m_device->m_queue);
20388
20389 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20390 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20391 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20392
20393 m_errorMonitor->VerifyNotFound();
20394}
20395
20396// This is a positive test. No errors should be generated.
20397TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020398 TEST_DESCRIPTION(
20399 "Two command buffers, each in a separate QueueSubmit call "
20400 "submitted on separate queues, the second having a fence"
20401 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020402
20403 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020404 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020405
20406 m_errorMonitor->ExpectSuccess();
20407
20408 VkFence fence;
20409 VkFenceCreateInfo fence_create_info{};
20410 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20411 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20412
20413 VkSemaphore semaphore;
20414 VkSemaphoreCreateInfo semaphore_create_info{};
20415 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20416 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20417
20418 VkCommandPool command_pool;
20419 VkCommandPoolCreateInfo pool_create_info{};
20420 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20421 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20422 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20423 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20424
20425 VkCommandBuffer command_buffer[2];
20426 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20427 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20428 command_buffer_allocate_info.commandPool = command_pool;
20429 command_buffer_allocate_info.commandBufferCount = 2;
20430 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20431 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20432
20433 VkQueue queue = VK_NULL_HANDLE;
20434 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20435
20436 {
20437 VkCommandBufferBeginInfo begin_info{};
20438 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20439 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20440
20441 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 -070020442 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020443
20444 VkViewport viewport{};
20445 viewport.maxDepth = 1.0f;
20446 viewport.minDepth = 0.0f;
20447 viewport.width = 512;
20448 viewport.height = 512;
20449 viewport.x = 0;
20450 viewport.y = 0;
20451 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20452 vkEndCommandBuffer(command_buffer[0]);
20453 }
20454 {
20455 VkCommandBufferBeginInfo begin_info{};
20456 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20457 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20458
20459 VkViewport viewport{};
20460 viewport.maxDepth = 1.0f;
20461 viewport.minDepth = 0.0f;
20462 viewport.width = 512;
20463 viewport.height = 512;
20464 viewport.x = 0;
20465 viewport.y = 0;
20466 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20467 vkEndCommandBuffer(command_buffer[1]);
20468 }
20469 {
20470 VkSubmitInfo submit_info{};
20471 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20472 submit_info.commandBufferCount = 1;
20473 submit_info.pCommandBuffers = &command_buffer[0];
20474 submit_info.signalSemaphoreCount = 1;
20475 submit_info.pSignalSemaphores = &semaphore;
20476 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20477 }
20478 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020479 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020480 VkSubmitInfo submit_info{};
20481 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20482 submit_info.commandBufferCount = 1;
20483 submit_info.pCommandBuffers = &command_buffer[1];
20484 submit_info.waitSemaphoreCount = 1;
20485 submit_info.pWaitSemaphores = &semaphore;
20486 submit_info.pWaitDstStageMask = flags;
20487 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20488 }
20489
20490 vkQueueWaitIdle(m_device->m_queue);
20491
20492 vkDestroyFence(m_device->device(), fence, nullptr);
20493 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20494 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20495 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20496
20497 m_errorMonitor->VerifyNotFound();
20498}
20499
20500// This is a positive test. No errors should be generated.
20501TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020502 TEST_DESCRIPTION(
20503 "Two command buffers, each in a separate QueueSubmit call "
20504 "submitted on separate queues, the second having a fence"
20505 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020506
20507 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020508 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020509
20510 m_errorMonitor->ExpectSuccess();
20511
20512 VkFence fence;
20513 VkFenceCreateInfo fence_create_info{};
20514 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20515 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20516
20517 VkSemaphore semaphore;
20518 VkSemaphoreCreateInfo semaphore_create_info{};
20519 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20520 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20521
20522 VkCommandPool command_pool;
20523 VkCommandPoolCreateInfo pool_create_info{};
20524 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20525 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20526 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20527 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20528
20529 VkCommandBuffer command_buffer[2];
20530 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20531 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20532 command_buffer_allocate_info.commandPool = command_pool;
20533 command_buffer_allocate_info.commandBufferCount = 2;
20534 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20535 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20536
20537 VkQueue queue = VK_NULL_HANDLE;
20538 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20539
20540 {
20541 VkCommandBufferBeginInfo begin_info{};
20542 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20543 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20544
20545 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 -070020546 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020547
20548 VkViewport viewport{};
20549 viewport.maxDepth = 1.0f;
20550 viewport.minDepth = 0.0f;
20551 viewport.width = 512;
20552 viewport.height = 512;
20553 viewport.x = 0;
20554 viewport.y = 0;
20555 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20556 vkEndCommandBuffer(command_buffer[0]);
20557 }
20558 {
20559 VkCommandBufferBeginInfo begin_info{};
20560 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20561 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20562
20563 VkViewport viewport{};
20564 viewport.maxDepth = 1.0f;
20565 viewport.minDepth = 0.0f;
20566 viewport.width = 512;
20567 viewport.height = 512;
20568 viewport.x = 0;
20569 viewport.y = 0;
20570 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20571 vkEndCommandBuffer(command_buffer[1]);
20572 }
20573 {
20574 VkSubmitInfo submit_info{};
20575 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20576 submit_info.commandBufferCount = 1;
20577 submit_info.pCommandBuffers = &command_buffer[0];
20578 submit_info.signalSemaphoreCount = 1;
20579 submit_info.pSignalSemaphores = &semaphore;
20580 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20581 }
20582 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020583 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020584 VkSubmitInfo submit_info{};
20585 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20586 submit_info.commandBufferCount = 1;
20587 submit_info.pCommandBuffers = &command_buffer[1];
20588 submit_info.waitSemaphoreCount = 1;
20589 submit_info.pWaitSemaphores = &semaphore;
20590 submit_info.pWaitDstStageMask = flags;
20591 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20592 }
20593
20594 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20595 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20596
20597 vkDestroyFence(m_device->device(), fence, nullptr);
20598 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20599 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20600 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20601
20602 m_errorMonitor->VerifyNotFound();
20603}
20604
20605TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020606 ASSERT_NO_FATAL_FAILURE(InitState());
20607 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020608 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020609 return;
20610 }
20611
20612 VkResult err;
20613
20614 m_errorMonitor->ExpectSuccess();
20615
20616 VkQueue q0 = m_device->m_queue;
20617 VkQueue q1 = nullptr;
20618 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20619 ASSERT_NE(q1, nullptr);
20620
20621 // An (empty) command buffer. We must have work in the first submission --
20622 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020623 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020624 VkCommandPool pool;
20625 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20626 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020627 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20628 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020629 VkCommandBuffer cb;
20630 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20631 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020632 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020633 err = vkBeginCommandBuffer(cb, &cbbi);
20634 ASSERT_VK_SUCCESS(err);
20635 err = vkEndCommandBuffer(cb);
20636 ASSERT_VK_SUCCESS(err);
20637
20638 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020639 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020640 VkSemaphore s;
20641 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20642 ASSERT_VK_SUCCESS(err);
20643
20644 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020645 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020646
20647 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20648 ASSERT_VK_SUCCESS(err);
20649
20650 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020651 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020652 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020653
20654 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20655 ASSERT_VK_SUCCESS(err);
20656
20657 // Wait for q0 idle
20658 err = vkQueueWaitIdle(q0);
20659 ASSERT_VK_SUCCESS(err);
20660
20661 // Command buffer should have been completed (it was on q0); reset the pool.
20662 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20663
20664 m_errorMonitor->VerifyNotFound();
20665
20666 // Force device completely idle and clean up resources
20667 vkDeviceWaitIdle(m_device->device());
20668 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20669 vkDestroySemaphore(m_device->device(), s, nullptr);
20670}
20671
20672// This is a positive test. No errors should be generated.
20673TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020674 TEST_DESCRIPTION(
20675 "Two command buffers, each in a separate QueueSubmit call "
20676 "submitted on separate queues, the second having a fence, "
20677 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020678
20679 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020680 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020681
20682 m_errorMonitor->ExpectSuccess();
20683
20684 ASSERT_NO_FATAL_FAILURE(InitState());
20685 VkFence fence;
20686 VkFenceCreateInfo fence_create_info{};
20687 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20688 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20689
20690 VkSemaphore semaphore;
20691 VkSemaphoreCreateInfo semaphore_create_info{};
20692 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20693 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20694
20695 VkCommandPool command_pool;
20696 VkCommandPoolCreateInfo pool_create_info{};
20697 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20698 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20699 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20700 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20701
20702 VkCommandBuffer command_buffer[2];
20703 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20704 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20705 command_buffer_allocate_info.commandPool = command_pool;
20706 command_buffer_allocate_info.commandBufferCount = 2;
20707 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20708 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20709
20710 VkQueue queue = VK_NULL_HANDLE;
20711 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20712
20713 {
20714 VkCommandBufferBeginInfo begin_info{};
20715 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20716 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20717
20718 vkCmdPipelineBarrier(command_buffer[0], VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020719 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020720
20721 VkViewport viewport{};
20722 viewport.maxDepth = 1.0f;
20723 viewport.minDepth = 0.0f;
20724 viewport.width = 512;
20725 viewport.height = 512;
20726 viewport.x = 0;
20727 viewport.y = 0;
20728 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20729 vkEndCommandBuffer(command_buffer[0]);
20730 }
20731 {
20732 VkCommandBufferBeginInfo begin_info{};
20733 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20734 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20735
20736 VkViewport viewport{};
20737 viewport.maxDepth = 1.0f;
20738 viewport.minDepth = 0.0f;
20739 viewport.width = 512;
20740 viewport.height = 512;
20741 viewport.x = 0;
20742 viewport.y = 0;
20743 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20744 vkEndCommandBuffer(command_buffer[1]);
20745 }
20746 {
20747 VkSubmitInfo submit_info{};
20748 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20749 submit_info.commandBufferCount = 1;
20750 submit_info.pCommandBuffers = &command_buffer[0];
20751 submit_info.signalSemaphoreCount = 1;
20752 submit_info.pSignalSemaphores = &semaphore;
20753 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20754 }
20755 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020756 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020757 VkSubmitInfo submit_info{};
20758 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20759 submit_info.commandBufferCount = 1;
20760 submit_info.pCommandBuffers = &command_buffer[1];
20761 submit_info.waitSemaphoreCount = 1;
20762 submit_info.pWaitSemaphores = &semaphore;
20763 submit_info.pWaitDstStageMask = flags;
20764 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20765 }
20766
20767 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20768
20769 vkDestroyFence(m_device->device(), fence, nullptr);
20770 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20771 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20772 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20773
20774 m_errorMonitor->VerifyNotFound();
20775}
20776
20777// This is a positive test. No errors should be generated.
20778TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020779 TEST_DESCRIPTION(
20780 "Two command buffers, each in a separate QueueSubmit call "
20781 "on the same queue, sharing a signal/wait semaphore, the "
20782 "second having a fence, "
20783 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020784
20785 m_errorMonitor->ExpectSuccess();
20786
20787 ASSERT_NO_FATAL_FAILURE(InitState());
20788 VkFence fence;
20789 VkFenceCreateInfo fence_create_info{};
20790 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20791 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20792
20793 VkSemaphore semaphore;
20794 VkSemaphoreCreateInfo semaphore_create_info{};
20795 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20796 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20797
20798 VkCommandPool command_pool;
20799 VkCommandPoolCreateInfo pool_create_info{};
20800 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20801 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20802 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20803 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20804
20805 VkCommandBuffer command_buffer[2];
20806 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20807 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20808 command_buffer_allocate_info.commandPool = command_pool;
20809 command_buffer_allocate_info.commandBufferCount = 2;
20810 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20811 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20812
20813 {
20814 VkCommandBufferBeginInfo begin_info{};
20815 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20816 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20817
20818 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 -070020819 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020820
20821 VkViewport viewport{};
20822 viewport.maxDepth = 1.0f;
20823 viewport.minDepth = 0.0f;
20824 viewport.width = 512;
20825 viewport.height = 512;
20826 viewport.x = 0;
20827 viewport.y = 0;
20828 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20829 vkEndCommandBuffer(command_buffer[0]);
20830 }
20831 {
20832 VkCommandBufferBeginInfo begin_info{};
20833 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20834 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20835
20836 VkViewport viewport{};
20837 viewport.maxDepth = 1.0f;
20838 viewport.minDepth = 0.0f;
20839 viewport.width = 512;
20840 viewport.height = 512;
20841 viewport.x = 0;
20842 viewport.y = 0;
20843 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20844 vkEndCommandBuffer(command_buffer[1]);
20845 }
20846 {
20847 VkSubmitInfo submit_info{};
20848 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20849 submit_info.commandBufferCount = 1;
20850 submit_info.pCommandBuffers = &command_buffer[0];
20851 submit_info.signalSemaphoreCount = 1;
20852 submit_info.pSignalSemaphores = &semaphore;
20853 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20854 }
20855 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020856 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020857 VkSubmitInfo submit_info{};
20858 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20859 submit_info.commandBufferCount = 1;
20860 submit_info.pCommandBuffers = &command_buffer[1];
20861 submit_info.waitSemaphoreCount = 1;
20862 submit_info.pWaitSemaphores = &semaphore;
20863 submit_info.pWaitDstStageMask = flags;
20864 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20865 }
20866
20867 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20868
20869 vkDestroyFence(m_device->device(), fence, nullptr);
20870 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20871 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20872 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20873
20874 m_errorMonitor->VerifyNotFound();
20875}
20876
20877// This is a positive test. No errors should be generated.
20878TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020879 TEST_DESCRIPTION(
20880 "Two command buffers, each in a separate QueueSubmit call "
20881 "on the same queue, no fences, followed by a third QueueSubmit with NO "
20882 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020883
20884 m_errorMonitor->ExpectSuccess();
20885
20886 ASSERT_NO_FATAL_FAILURE(InitState());
20887 VkFence fence;
20888 VkFenceCreateInfo fence_create_info{};
20889 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20890 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20891
20892 VkCommandPool command_pool;
20893 VkCommandPoolCreateInfo pool_create_info{};
20894 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20895 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20896 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20897 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20898
20899 VkCommandBuffer command_buffer[2];
20900 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20901 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20902 command_buffer_allocate_info.commandPool = command_pool;
20903 command_buffer_allocate_info.commandBufferCount = 2;
20904 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20905 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20906
20907 {
20908 VkCommandBufferBeginInfo begin_info{};
20909 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20910 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20911
20912 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 -070020913 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020914
20915 VkViewport viewport{};
20916 viewport.maxDepth = 1.0f;
20917 viewport.minDepth = 0.0f;
20918 viewport.width = 512;
20919 viewport.height = 512;
20920 viewport.x = 0;
20921 viewport.y = 0;
20922 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20923 vkEndCommandBuffer(command_buffer[0]);
20924 }
20925 {
20926 VkCommandBufferBeginInfo begin_info{};
20927 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20928 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20929
20930 VkViewport viewport{};
20931 viewport.maxDepth = 1.0f;
20932 viewport.minDepth = 0.0f;
20933 viewport.width = 512;
20934 viewport.height = 512;
20935 viewport.x = 0;
20936 viewport.y = 0;
20937 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20938 vkEndCommandBuffer(command_buffer[1]);
20939 }
20940 {
20941 VkSubmitInfo submit_info{};
20942 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20943 submit_info.commandBufferCount = 1;
20944 submit_info.pCommandBuffers = &command_buffer[0];
20945 submit_info.signalSemaphoreCount = 0;
20946 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
20947 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20948 }
20949 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020950 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020951 VkSubmitInfo submit_info{};
20952 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20953 submit_info.commandBufferCount = 1;
20954 submit_info.pCommandBuffers = &command_buffer[1];
20955 submit_info.waitSemaphoreCount = 0;
20956 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
20957 submit_info.pWaitDstStageMask = flags;
20958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20959 }
20960
20961 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
20962
20963 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20964 ASSERT_VK_SUCCESS(err);
20965
20966 vkDestroyFence(m_device->device(), fence, nullptr);
20967 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20968 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20969
20970 m_errorMonitor->VerifyNotFound();
20971}
20972
20973// This is a positive test. No errors should be generated.
20974TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020975 TEST_DESCRIPTION(
20976 "Two command buffers, each in a separate QueueSubmit call "
20977 "on the same queue, the second having a fence, followed "
20978 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020979
20980 m_errorMonitor->ExpectSuccess();
20981
20982 ASSERT_NO_FATAL_FAILURE(InitState());
20983 VkFence fence;
20984 VkFenceCreateInfo fence_create_info{};
20985 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20986 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20987
20988 VkCommandPool command_pool;
20989 VkCommandPoolCreateInfo pool_create_info{};
20990 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20991 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20992 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20993 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20994
20995 VkCommandBuffer command_buffer[2];
20996 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20997 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20998 command_buffer_allocate_info.commandPool = command_pool;
20999 command_buffer_allocate_info.commandBufferCount = 2;
21000 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21001 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21002
21003 {
21004 VkCommandBufferBeginInfo begin_info{};
21005 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21006 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21007
21008 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 -070021009 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021010
21011 VkViewport viewport{};
21012 viewport.maxDepth = 1.0f;
21013 viewport.minDepth = 0.0f;
21014 viewport.width = 512;
21015 viewport.height = 512;
21016 viewport.x = 0;
21017 viewport.y = 0;
21018 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21019 vkEndCommandBuffer(command_buffer[0]);
21020 }
21021 {
21022 VkCommandBufferBeginInfo begin_info{};
21023 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21024 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21025
21026 VkViewport viewport{};
21027 viewport.maxDepth = 1.0f;
21028 viewport.minDepth = 0.0f;
21029 viewport.width = 512;
21030 viewport.height = 512;
21031 viewport.x = 0;
21032 viewport.y = 0;
21033 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21034 vkEndCommandBuffer(command_buffer[1]);
21035 }
21036 {
21037 VkSubmitInfo submit_info{};
21038 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21039 submit_info.commandBufferCount = 1;
21040 submit_info.pCommandBuffers = &command_buffer[0];
21041 submit_info.signalSemaphoreCount = 0;
21042 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21043 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21044 }
21045 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021046 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021047 VkSubmitInfo submit_info{};
21048 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21049 submit_info.commandBufferCount = 1;
21050 submit_info.pCommandBuffers = &command_buffer[1];
21051 submit_info.waitSemaphoreCount = 0;
21052 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21053 submit_info.pWaitDstStageMask = flags;
21054 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21055 }
21056
21057 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21058
21059 vkDestroyFence(m_device->device(), fence, nullptr);
21060 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21061 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21062
21063 m_errorMonitor->VerifyNotFound();
21064}
21065
21066// This is a positive test. No errors should be generated.
21067TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021068 TEST_DESCRIPTION(
21069 "Two command buffers each in a separate SubmitInfo sent in a single "
21070 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021071 ASSERT_NO_FATAL_FAILURE(InitState());
21072
21073 m_errorMonitor->ExpectSuccess();
21074
21075 VkFence fence;
21076 VkFenceCreateInfo fence_create_info{};
21077 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21078 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21079
21080 VkSemaphore semaphore;
21081 VkSemaphoreCreateInfo semaphore_create_info{};
21082 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21083 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21084
21085 VkCommandPool command_pool;
21086 VkCommandPoolCreateInfo pool_create_info{};
21087 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21088 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21089 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21090 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21091
21092 VkCommandBuffer command_buffer[2];
21093 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21094 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21095 command_buffer_allocate_info.commandPool = command_pool;
21096 command_buffer_allocate_info.commandBufferCount = 2;
21097 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21098 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21099
21100 {
21101 VkCommandBufferBeginInfo begin_info{};
21102 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21103 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21104
21105 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 -070021106 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021107
21108 VkViewport viewport{};
21109 viewport.maxDepth = 1.0f;
21110 viewport.minDepth = 0.0f;
21111 viewport.width = 512;
21112 viewport.height = 512;
21113 viewport.x = 0;
21114 viewport.y = 0;
21115 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21116 vkEndCommandBuffer(command_buffer[0]);
21117 }
21118 {
21119 VkCommandBufferBeginInfo begin_info{};
21120 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21121 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21122
21123 VkViewport viewport{};
21124 viewport.maxDepth = 1.0f;
21125 viewport.minDepth = 0.0f;
21126 viewport.width = 512;
21127 viewport.height = 512;
21128 viewport.x = 0;
21129 viewport.y = 0;
21130 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21131 vkEndCommandBuffer(command_buffer[1]);
21132 }
21133 {
21134 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021135 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021136
21137 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21138 submit_info[0].pNext = NULL;
21139 submit_info[0].commandBufferCount = 1;
21140 submit_info[0].pCommandBuffers = &command_buffer[0];
21141 submit_info[0].signalSemaphoreCount = 1;
21142 submit_info[0].pSignalSemaphores = &semaphore;
21143 submit_info[0].waitSemaphoreCount = 0;
21144 submit_info[0].pWaitSemaphores = NULL;
21145 submit_info[0].pWaitDstStageMask = 0;
21146
21147 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21148 submit_info[1].pNext = NULL;
21149 submit_info[1].commandBufferCount = 1;
21150 submit_info[1].pCommandBuffers = &command_buffer[1];
21151 submit_info[1].waitSemaphoreCount = 1;
21152 submit_info[1].pWaitSemaphores = &semaphore;
21153 submit_info[1].pWaitDstStageMask = flags;
21154 submit_info[1].signalSemaphoreCount = 0;
21155 submit_info[1].pSignalSemaphores = NULL;
21156 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21157 }
21158
21159 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21160
21161 vkDestroyFence(m_device->device(), fence, nullptr);
21162 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21163 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21164 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21165
21166 m_errorMonitor->VerifyNotFound();
21167}
21168
21169TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21170 m_errorMonitor->ExpectSuccess();
21171
21172 ASSERT_NO_FATAL_FAILURE(InitState());
21173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21174
Tony Barbour552f6c02016-12-21 14:34:07 -070021175 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021176
21177 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21178 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21179 m_errorMonitor->VerifyNotFound();
21180 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21181 m_errorMonitor->VerifyNotFound();
21182 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21183 m_errorMonitor->VerifyNotFound();
21184
21185 m_commandBuffer->EndCommandBuffer();
21186 m_errorMonitor->VerifyNotFound();
21187}
21188
21189TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021190 TEST_DESCRIPTION(
21191 "Positive test where we create a renderpass with an "
21192 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21193 "has a valid layout, and a second subpass then uses a "
21194 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021195 m_errorMonitor->ExpectSuccess();
21196 ASSERT_NO_FATAL_FAILURE(InitState());
21197
21198 VkAttachmentReference attach[2] = {};
21199 attach[0].attachment = 0;
21200 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21201 attach[1].attachment = 0;
21202 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21203 VkSubpassDescription subpasses[2] = {};
21204 // First subpass clears DS attach on load
21205 subpasses[0].pDepthStencilAttachment = &attach[0];
21206 // 2nd subpass reads in DS as input attachment
21207 subpasses[1].inputAttachmentCount = 1;
21208 subpasses[1].pInputAttachments = &attach[1];
21209 VkAttachmentDescription attach_desc = {};
21210 attach_desc.format = VK_FORMAT_D24_UNORM_S8_UINT;
21211 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21212 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21213 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21214 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21215 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21216 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21217 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21218 VkRenderPassCreateInfo rpci = {};
21219 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21220 rpci.attachmentCount = 1;
21221 rpci.pAttachments = &attach_desc;
21222 rpci.subpassCount = 2;
21223 rpci.pSubpasses = subpasses;
21224
21225 // Now create RenderPass and verify no errors
21226 VkRenderPass rp;
21227 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21228 m_errorMonitor->VerifyNotFound();
21229
21230 vkDestroyRenderPass(m_device->device(), rp, NULL);
21231}
21232
Tobin Ehlis01103de2017-02-16 13:22:47 -070021233TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21234 TEST_DESCRIPTION(
21235 "Create a render pass with depth-stencil attachment where layout transition "
21236 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21237 "transition has correctly occurred at queue submit time with no validation errors.");
21238
21239 VkFormat ds_format = VK_FORMAT_D24_UNORM_S8_UINT;
21240 VkImageFormatProperties format_props;
21241 vkGetPhysicalDeviceImageFormatProperties(gpu(), ds_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
21242 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21243 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
21244 printf("DS format VK_FORMAT_D24_UNORM_S8_UINT not supported, RenderPassDepthStencilLayoutTransition skipped.\n");
21245 return;
21246 }
21247
21248 m_errorMonitor->ExpectSuccess();
21249 ASSERT_NO_FATAL_FAILURE(InitState());
21250 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21251
21252 // A renderpass with one depth/stencil attachment.
21253 VkAttachmentDescription attachment = {0,
21254 ds_format,
21255 VK_SAMPLE_COUNT_1_BIT,
21256 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21257 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21258 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21259 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21260 VK_IMAGE_LAYOUT_UNDEFINED,
21261 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21262
21263 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21264
21265 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21266
21267 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21268
21269 VkRenderPass rp;
21270 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21271 ASSERT_VK_SUCCESS(err);
21272 // A compatible ds image.
21273 VkImageObj image(m_device);
21274 image.init(32, 32, ds_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
21275 ASSERT_TRUE(image.initialized());
21276
21277 VkImageViewCreateInfo ivci = {
21278 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21279 nullptr,
21280 0,
21281 image.handle(),
21282 VK_IMAGE_VIEW_TYPE_2D,
21283 ds_format,
21284 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21285 VK_COMPONENT_SWIZZLE_IDENTITY},
21286 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21287 };
21288 VkImageView view;
21289 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21290 ASSERT_VK_SUCCESS(err);
21291
21292 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21293 VkFramebuffer fb;
21294 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21295 ASSERT_VK_SUCCESS(err);
21296
21297 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21298 m_commandBuffer->BeginCommandBuffer();
21299 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21300 vkCmdEndRenderPass(m_commandBuffer->handle());
21301 m_commandBuffer->EndCommandBuffer();
21302 QueueCommandBuffer(false);
21303 m_errorMonitor->VerifyNotFound();
21304
21305 // Cleanup
21306 vkDestroyImageView(m_device->device(), view, NULL);
21307 vkDestroyRenderPass(m_device->device(), rp, NULL);
21308 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21309}
21310
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021311TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021312 TEST_DESCRIPTION(
21313 "Test that pipeline validation accepts matrices passed "
21314 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021315 m_errorMonitor->ExpectSuccess();
21316
21317 ASSERT_NO_FATAL_FAILURE(InitState());
21318 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21319
21320 VkVertexInputBindingDescription input_binding;
21321 memset(&input_binding, 0, sizeof(input_binding));
21322
21323 VkVertexInputAttributeDescription input_attribs[2];
21324 memset(input_attribs, 0, sizeof(input_attribs));
21325
21326 for (int i = 0; i < 2; i++) {
21327 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21328 input_attribs[i].location = i;
21329 }
21330
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021331 char const *vsSource =
21332 "#version 450\n"
21333 "\n"
21334 "layout(location=0) in mat2x4 x;\n"
21335 "out gl_PerVertex {\n"
21336 " vec4 gl_Position;\n"
21337 "};\n"
21338 "void main(){\n"
21339 " gl_Position = x[0] + x[1];\n"
21340 "}\n";
21341 char const *fsSource =
21342 "#version 450\n"
21343 "\n"
21344 "layout(location=0) out vec4 color;\n"
21345 "void main(){\n"
21346 " color = vec4(1);\n"
21347 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021348
21349 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21350 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21351
21352 VkPipelineObj pipe(m_device);
21353 pipe.AddColorAttachment();
21354 pipe.AddShader(&vs);
21355 pipe.AddShader(&fs);
21356
21357 pipe.AddVertexInputBindings(&input_binding, 1);
21358 pipe.AddVertexInputAttribs(input_attribs, 2);
21359
21360 VkDescriptorSetObj descriptorSet(m_device);
21361 descriptorSet.AppendDummy();
21362 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21363
21364 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21365
21366 /* expect success */
21367 m_errorMonitor->VerifyNotFound();
21368}
21369
21370TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21371 m_errorMonitor->ExpectSuccess();
21372
21373 ASSERT_NO_FATAL_FAILURE(InitState());
21374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21375
21376 VkVertexInputBindingDescription input_binding;
21377 memset(&input_binding, 0, sizeof(input_binding));
21378
21379 VkVertexInputAttributeDescription input_attribs[2];
21380 memset(input_attribs, 0, sizeof(input_attribs));
21381
21382 for (int i = 0; i < 2; i++) {
21383 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21384 input_attribs[i].location = i;
21385 }
21386
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021387 char const *vsSource =
21388 "#version 450\n"
21389 "\n"
21390 "layout(location=0) in vec4 x[2];\n"
21391 "out gl_PerVertex {\n"
21392 " vec4 gl_Position;\n"
21393 "};\n"
21394 "void main(){\n"
21395 " gl_Position = x[0] + x[1];\n"
21396 "}\n";
21397 char const *fsSource =
21398 "#version 450\n"
21399 "\n"
21400 "layout(location=0) out vec4 color;\n"
21401 "void main(){\n"
21402 " color = vec4(1);\n"
21403 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021404
21405 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21406 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21407
21408 VkPipelineObj pipe(m_device);
21409 pipe.AddColorAttachment();
21410 pipe.AddShader(&vs);
21411 pipe.AddShader(&fs);
21412
21413 pipe.AddVertexInputBindings(&input_binding, 1);
21414 pipe.AddVertexInputAttribs(input_attribs, 2);
21415
21416 VkDescriptorSetObj descriptorSet(m_device);
21417 descriptorSet.AppendDummy();
21418 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21419
21420 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21421
21422 m_errorMonitor->VerifyNotFound();
21423}
21424
21425TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021426 TEST_DESCRIPTION(
21427 "Test that pipeline validation accepts consuming a vertex attribute "
21428 "through multiple vertex shader inputs, each consuming a different "
21429 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021430 m_errorMonitor->ExpectSuccess();
21431
21432 ASSERT_NO_FATAL_FAILURE(InitState());
21433 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21434
21435 VkVertexInputBindingDescription input_binding;
21436 memset(&input_binding, 0, sizeof(input_binding));
21437
21438 VkVertexInputAttributeDescription input_attribs[3];
21439 memset(input_attribs, 0, sizeof(input_attribs));
21440
21441 for (int i = 0; i < 3; i++) {
21442 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21443 input_attribs[i].location = i;
21444 }
21445
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021446 char const *vsSource =
21447 "#version 450\n"
21448 "\n"
21449 "layout(location=0) in vec4 x;\n"
21450 "layout(location=1) in vec3 y1;\n"
21451 "layout(location=1, component=3) in float y2;\n"
21452 "layout(location=2) in vec4 z;\n"
21453 "out gl_PerVertex {\n"
21454 " vec4 gl_Position;\n"
21455 "};\n"
21456 "void main(){\n"
21457 " gl_Position = x + vec4(y1, y2) + z;\n"
21458 "}\n";
21459 char const *fsSource =
21460 "#version 450\n"
21461 "\n"
21462 "layout(location=0) out vec4 color;\n"
21463 "void main(){\n"
21464 " color = vec4(1);\n"
21465 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021466
21467 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21468 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21469
21470 VkPipelineObj pipe(m_device);
21471 pipe.AddColorAttachment();
21472 pipe.AddShader(&vs);
21473 pipe.AddShader(&fs);
21474
21475 pipe.AddVertexInputBindings(&input_binding, 1);
21476 pipe.AddVertexInputAttribs(input_attribs, 3);
21477
21478 VkDescriptorSetObj descriptorSet(m_device);
21479 descriptorSet.AppendDummy();
21480 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21481
21482 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21483
21484 m_errorMonitor->VerifyNotFound();
21485}
21486
21487TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21488 m_errorMonitor->ExpectSuccess();
21489
21490 ASSERT_NO_FATAL_FAILURE(InitState());
21491 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21492
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021493 char const *vsSource =
21494 "#version 450\n"
21495 "out gl_PerVertex {\n"
21496 " vec4 gl_Position;\n"
21497 "};\n"
21498 "void main(){\n"
21499 " gl_Position = vec4(0);\n"
21500 "}\n";
21501 char const *fsSource =
21502 "#version 450\n"
21503 "\n"
21504 "layout(location=0) out vec4 color;\n"
21505 "void main(){\n"
21506 " color = vec4(1);\n"
21507 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021508
21509 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21510 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21511
21512 VkPipelineObj pipe(m_device);
21513 pipe.AddColorAttachment();
21514 pipe.AddShader(&vs);
21515 pipe.AddShader(&fs);
21516
21517 VkDescriptorSetObj descriptorSet(m_device);
21518 descriptorSet.AppendDummy();
21519 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21520
21521 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21522
21523 m_errorMonitor->VerifyNotFound();
21524}
21525
21526TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021527 TEST_DESCRIPTION(
21528 "Test that pipeline validation accepts the relaxed type matching rules "
21529 "set out in 14.1.3: fundamental type must match, and producer side must "
21530 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021531 m_errorMonitor->ExpectSuccess();
21532
21533 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21534
21535 ASSERT_NO_FATAL_FAILURE(InitState());
21536 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21537
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021538 char const *vsSource =
21539 "#version 450\n"
21540 "out gl_PerVertex {\n"
21541 " vec4 gl_Position;\n"
21542 "};\n"
21543 "layout(location=0) out vec3 x;\n"
21544 "layout(location=1) out ivec3 y;\n"
21545 "layout(location=2) out vec3 z;\n"
21546 "void main(){\n"
21547 " gl_Position = vec4(0);\n"
21548 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21549 "}\n";
21550 char const *fsSource =
21551 "#version 450\n"
21552 "\n"
21553 "layout(location=0) out vec4 color;\n"
21554 "layout(location=0) in float x;\n"
21555 "layout(location=1) flat in int y;\n"
21556 "layout(location=2) in vec2 z;\n"
21557 "void main(){\n"
21558 " color = vec4(1 + x + y + z.x);\n"
21559 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021560
21561 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21562 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21563
21564 VkPipelineObj pipe(m_device);
21565 pipe.AddColorAttachment();
21566 pipe.AddShader(&vs);
21567 pipe.AddShader(&fs);
21568
21569 VkDescriptorSetObj descriptorSet(m_device);
21570 descriptorSet.AppendDummy();
21571 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21572
21573 VkResult err = VK_SUCCESS;
21574 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21575 ASSERT_VK_SUCCESS(err);
21576
21577 m_errorMonitor->VerifyNotFound();
21578}
21579
21580TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021581 TEST_DESCRIPTION(
21582 "Test that pipeline validation accepts per-vertex variables "
21583 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021584 m_errorMonitor->ExpectSuccess();
21585
21586 ASSERT_NO_FATAL_FAILURE(InitState());
21587 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21588
21589 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021590 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021591 return;
21592 }
21593
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021594 char const *vsSource =
21595 "#version 450\n"
21596 "void main(){}\n";
21597 char const *tcsSource =
21598 "#version 450\n"
21599 "layout(location=0) out int x[];\n"
21600 "layout(vertices=3) out;\n"
21601 "void main(){\n"
21602 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21603 " gl_TessLevelInner[0] = 1;\n"
21604 " x[gl_InvocationID] = gl_InvocationID;\n"
21605 "}\n";
21606 char const *tesSource =
21607 "#version 450\n"
21608 "layout(triangles, equal_spacing, cw) in;\n"
21609 "layout(location=0) in int x[];\n"
21610 "out gl_PerVertex { vec4 gl_Position; };\n"
21611 "void main(){\n"
21612 " gl_Position.xyz = gl_TessCoord;\n"
21613 " gl_Position.w = x[0] + x[1] + x[2];\n"
21614 "}\n";
21615 char const *fsSource =
21616 "#version 450\n"
21617 "layout(location=0) out vec4 color;\n"
21618 "void main(){\n"
21619 " color = vec4(1);\n"
21620 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021621
21622 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21623 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21624 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21625 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21626
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021627 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21628 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021629
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021630 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021631
21632 VkPipelineObj pipe(m_device);
21633 pipe.SetInputAssembly(&iasci);
21634 pipe.SetTessellation(&tsci);
21635 pipe.AddColorAttachment();
21636 pipe.AddShader(&vs);
21637 pipe.AddShader(&tcs);
21638 pipe.AddShader(&tes);
21639 pipe.AddShader(&fs);
21640
21641 VkDescriptorSetObj descriptorSet(m_device);
21642 descriptorSet.AppendDummy();
21643 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21644
21645 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21646
21647 m_errorMonitor->VerifyNotFound();
21648}
21649
21650TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021651 TEST_DESCRIPTION(
21652 "Test that pipeline validation accepts a user-defined "
21653 "interface block passed into the geometry shader. This "
21654 "is interesting because the 'extra' array level is not "
21655 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021656 m_errorMonitor->ExpectSuccess();
21657
21658 ASSERT_NO_FATAL_FAILURE(InitState());
21659 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21660
21661 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021662 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021663 return;
21664 }
21665
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021666 char const *vsSource =
21667 "#version 450\n"
21668 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21669 "void main(){\n"
21670 " vs_out.x = vec4(1);\n"
21671 "}\n";
21672 char const *gsSource =
21673 "#version 450\n"
21674 "layout(triangles) in;\n"
21675 "layout(triangle_strip, max_vertices=3) out;\n"
21676 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21677 "out gl_PerVertex { vec4 gl_Position; };\n"
21678 "void main() {\n"
21679 " gl_Position = gs_in[0].x;\n"
21680 " EmitVertex();\n"
21681 "}\n";
21682 char const *fsSource =
21683 "#version 450\n"
21684 "layout(location=0) out vec4 color;\n"
21685 "void main(){\n"
21686 " color = vec4(1);\n"
21687 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021688
21689 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21690 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21691 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21692
21693 VkPipelineObj pipe(m_device);
21694 pipe.AddColorAttachment();
21695 pipe.AddShader(&vs);
21696 pipe.AddShader(&gs);
21697 pipe.AddShader(&fs);
21698
21699 VkDescriptorSetObj descriptorSet(m_device);
21700 descriptorSet.AppendDummy();
21701 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21702
21703 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21704
21705 m_errorMonitor->VerifyNotFound();
21706}
21707
21708TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021709 TEST_DESCRIPTION(
21710 "Test that pipeline validation accepts basic use of 64bit vertex "
21711 "attributes. This is interesting because they consume multiple "
21712 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021713 m_errorMonitor->ExpectSuccess();
21714
21715 ASSERT_NO_FATAL_FAILURE(InitState());
21716 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21717
21718 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021719 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021720 return;
21721 }
21722
21723 VkVertexInputBindingDescription input_bindings[1];
21724 memset(input_bindings, 0, sizeof(input_bindings));
21725
21726 VkVertexInputAttributeDescription input_attribs[4];
21727 memset(input_attribs, 0, sizeof(input_attribs));
21728 input_attribs[0].location = 0;
21729 input_attribs[0].offset = 0;
21730 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21731 input_attribs[1].location = 2;
21732 input_attribs[1].offset = 32;
21733 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21734 input_attribs[2].location = 4;
21735 input_attribs[2].offset = 64;
21736 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21737 input_attribs[3].location = 6;
21738 input_attribs[3].offset = 96;
21739 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
21740
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021741 char const *vsSource =
21742 "#version 450\n"
21743 "\n"
21744 "layout(location=0) in dmat4 x;\n"
21745 "out gl_PerVertex {\n"
21746 " vec4 gl_Position;\n"
21747 "};\n"
21748 "void main(){\n"
21749 " gl_Position = vec4(x[0][0]);\n"
21750 "}\n";
21751 char const *fsSource =
21752 "#version 450\n"
21753 "\n"
21754 "layout(location=0) out vec4 color;\n"
21755 "void main(){\n"
21756 " color = vec4(1);\n"
21757 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021758
21759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21761
21762 VkPipelineObj pipe(m_device);
21763 pipe.AddColorAttachment();
21764 pipe.AddShader(&vs);
21765 pipe.AddShader(&fs);
21766
21767 pipe.AddVertexInputBindings(input_bindings, 1);
21768 pipe.AddVertexInputAttribs(input_attribs, 4);
21769
21770 VkDescriptorSetObj descriptorSet(m_device);
21771 descriptorSet.AppendDummy();
21772 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21773
21774 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21775
21776 m_errorMonitor->VerifyNotFound();
21777}
21778
21779TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
21780 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
21781 m_errorMonitor->ExpectSuccess();
21782
21783 ASSERT_NO_FATAL_FAILURE(InitState());
21784
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021785 char const *vsSource =
21786 "#version 450\n"
21787 "\n"
21788 "out gl_PerVertex {\n"
21789 " vec4 gl_Position;\n"
21790 "};\n"
21791 "void main(){\n"
21792 " gl_Position = vec4(1);\n"
21793 "}\n";
21794 char const *fsSource =
21795 "#version 450\n"
21796 "\n"
21797 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
21798 "layout(location=0) out vec4 color;\n"
21799 "void main() {\n"
21800 " color = subpassLoad(x);\n"
21801 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021802
21803 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21804 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21805
21806 VkPipelineObj pipe(m_device);
21807 pipe.AddShader(&vs);
21808 pipe.AddShader(&fs);
21809 pipe.AddColorAttachment();
21810 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21811
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021812 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
21813 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021814 VkDescriptorSetLayout dsl;
21815 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21816 ASSERT_VK_SUCCESS(err);
21817
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021818 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021819 VkPipelineLayout pl;
21820 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21821 ASSERT_VK_SUCCESS(err);
21822
21823 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021824 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21825 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21826 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
21827 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
21828 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 -060021829 };
21830 VkAttachmentReference color = {
21831 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
21832 };
21833 VkAttachmentReference input = {
21834 1, VK_IMAGE_LAYOUT_GENERAL,
21835 };
21836
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021837 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021838
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021839 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021840 VkRenderPass rp;
21841 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21842 ASSERT_VK_SUCCESS(err);
21843
21844 // should be OK. would go wrong here if it's going to...
21845 pipe.CreateVKPipeline(pl, rp);
21846
21847 m_errorMonitor->VerifyNotFound();
21848
21849 vkDestroyRenderPass(m_device->device(), rp, nullptr);
21850 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21851 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21852}
21853
21854TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021855 TEST_DESCRIPTION(
21856 "Test that pipeline validation accepts a compute pipeline which declares a "
21857 "descriptor-backed resource which is not provided, but the shader does not "
21858 "statically use it. This is interesting because it requires compute pipelines "
21859 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021860 m_errorMonitor->ExpectSuccess();
21861
21862 ASSERT_NO_FATAL_FAILURE(InitState());
21863
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021864 char const *csSource =
21865 "#version 450\n"
21866 "\n"
21867 "layout(local_size_x=1) in;\n"
21868 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
21869 "void main(){\n"
21870 " // x is not used.\n"
21871 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021872
21873 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21874
21875 VkDescriptorSetObj descriptorSet(m_device);
21876 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21877
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021878 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21879 nullptr,
21880 0,
21881 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21882 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21883 descriptorSet.GetPipelineLayout(),
21884 VK_NULL_HANDLE,
21885 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021886
21887 VkPipeline pipe;
21888 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21889
21890 m_errorMonitor->VerifyNotFound();
21891
21892 if (err == VK_SUCCESS) {
21893 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21894 }
21895}
21896
21897TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021898 TEST_DESCRIPTION(
21899 "Test that pipeline validation accepts a shader consuming only the "
21900 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021901 m_errorMonitor->ExpectSuccess();
21902
21903 ASSERT_NO_FATAL_FAILURE(InitState());
21904
21905 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021906 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21907 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21908 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021909 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021910 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021911 VkDescriptorSetLayout dsl;
21912 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21913 ASSERT_VK_SUCCESS(err);
21914
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021915 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021916 VkPipelineLayout pl;
21917 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21918 ASSERT_VK_SUCCESS(err);
21919
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021920 char const *csSource =
21921 "#version 450\n"
21922 "\n"
21923 "layout(local_size_x=1) in;\n"
21924 "layout(set=0, binding=0) uniform sampler s;\n"
21925 "layout(set=0, binding=1) uniform texture2D t;\n"
21926 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21927 "void main() {\n"
21928 " x = texture(sampler2D(t, s), vec2(0));\n"
21929 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021930 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21931
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021932 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21933 nullptr,
21934 0,
21935 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21936 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21937 pl,
21938 VK_NULL_HANDLE,
21939 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021940
21941 VkPipeline pipe;
21942 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
21943
21944 m_errorMonitor->VerifyNotFound();
21945
21946 if (err == VK_SUCCESS) {
21947 vkDestroyPipeline(m_device->device(), pipe, nullptr);
21948 }
21949
21950 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
21951 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
21952}
21953
21954TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021955 TEST_DESCRIPTION(
21956 "Test that pipeline validation accepts a shader consuming only the "
21957 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021958 m_errorMonitor->ExpectSuccess();
21959
21960 ASSERT_NO_FATAL_FAILURE(InitState());
21961
21962 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021963 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21964 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
21965 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021966 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021967 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021968 VkDescriptorSetLayout dsl;
21969 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
21970 ASSERT_VK_SUCCESS(err);
21971
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021972 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021973 VkPipelineLayout pl;
21974 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
21975 ASSERT_VK_SUCCESS(err);
21976
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021977 char const *csSource =
21978 "#version 450\n"
21979 "\n"
21980 "layout(local_size_x=1) in;\n"
21981 "layout(set=0, binding=0) uniform texture2D t;\n"
21982 "layout(set=0, binding=1) uniform sampler s;\n"
21983 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
21984 "void main() {\n"
21985 " x = texture(sampler2D(t, s), vec2(0));\n"
21986 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021987 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
21988
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021989 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
21990 nullptr,
21991 0,
21992 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
21993 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
21994 pl,
21995 VK_NULL_HANDLE,
21996 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021997
21998 VkPipeline pipe;
21999 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22000
22001 m_errorMonitor->VerifyNotFound();
22002
22003 if (err == VK_SUCCESS) {
22004 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22005 }
22006
22007 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22008 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22009}
22010
22011TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022012 TEST_DESCRIPTION(
22013 "Test that pipeline validation accepts a shader consuming "
22014 "both the sampler and the image of a combined image+sampler "
22015 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022016 m_errorMonitor->ExpectSuccess();
22017
22018 ASSERT_NO_FATAL_FAILURE(InitState());
22019
22020 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022021 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22022 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022023 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022024 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022025 VkDescriptorSetLayout dsl;
22026 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22027 ASSERT_VK_SUCCESS(err);
22028
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022029 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022030 VkPipelineLayout pl;
22031 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22032 ASSERT_VK_SUCCESS(err);
22033
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022034 char const *csSource =
22035 "#version 450\n"
22036 "\n"
22037 "layout(local_size_x=1) in;\n"
22038 "layout(set=0, binding=0) uniform texture2D t;\n"
22039 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22040 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22041 "void main() {\n"
22042 " x = texture(sampler2D(t, s), vec2(0));\n"
22043 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022044 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22045
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022046 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22047 nullptr,
22048 0,
22049 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22050 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22051 pl,
22052 VK_NULL_HANDLE,
22053 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022054
22055 VkPipeline pipe;
22056 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22057
22058 m_errorMonitor->VerifyNotFound();
22059
22060 if (err == VK_SUCCESS) {
22061 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22062 }
22063
22064 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22065 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22066}
22067
22068TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22069 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22070
22071 ASSERT_NO_FATAL_FAILURE(InitState());
22072
22073 // Positive test to check parameter_validation and unique_objects support
22074 // for NV_dedicated_allocation
22075 uint32_t extension_count = 0;
22076 bool supports_nv_dedicated_allocation = false;
22077 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22078 ASSERT_VK_SUCCESS(err);
22079
22080 if (extension_count > 0) {
22081 std::vector<VkExtensionProperties> available_extensions(extension_count);
22082
22083 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22084 ASSERT_VK_SUCCESS(err);
22085
22086 for (const auto &extension_props : available_extensions) {
22087 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22088 supports_nv_dedicated_allocation = true;
22089 }
22090 }
22091 }
22092
22093 if (supports_nv_dedicated_allocation) {
22094 m_errorMonitor->ExpectSuccess();
22095
22096 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22097 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22098 dedicated_buffer_create_info.pNext = nullptr;
22099 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22100
22101 uint32_t queue_family_index = 0;
22102 VkBufferCreateInfo buffer_create_info = {};
22103 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22104 buffer_create_info.pNext = &dedicated_buffer_create_info;
22105 buffer_create_info.size = 1024;
22106 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22107 buffer_create_info.queueFamilyIndexCount = 1;
22108 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22109
22110 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022111 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022112 ASSERT_VK_SUCCESS(err);
22113
22114 VkMemoryRequirements memory_reqs;
22115 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22116
22117 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22118 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22119 dedicated_memory_info.pNext = nullptr;
22120 dedicated_memory_info.buffer = buffer;
22121 dedicated_memory_info.image = VK_NULL_HANDLE;
22122
22123 VkMemoryAllocateInfo memory_info = {};
22124 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22125 memory_info.pNext = &dedicated_memory_info;
22126 memory_info.allocationSize = memory_reqs.size;
22127
22128 bool pass;
22129 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22130 ASSERT_TRUE(pass);
22131
22132 VkDeviceMemory buffer_memory;
22133 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22134 ASSERT_VK_SUCCESS(err);
22135
22136 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22137 ASSERT_VK_SUCCESS(err);
22138
22139 vkDestroyBuffer(m_device->device(), buffer, NULL);
22140 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22141
22142 m_errorMonitor->VerifyNotFound();
22143 }
22144}
22145
22146TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22147 VkResult err;
22148
22149 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22150
22151 ASSERT_NO_FATAL_FAILURE(InitState());
22152 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22153
22154 std::vector<const char *> device_extension_names;
22155 auto features = m_device->phy().features();
22156 // Artificially disable support for non-solid fill modes
22157 features.fillModeNonSolid = false;
22158 // The sacrificial device object
22159 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22160
22161 VkRenderpassObj render_pass(&test_device);
22162
22163 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22164 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22165 pipeline_layout_ci.setLayoutCount = 0;
22166 pipeline_layout_ci.pSetLayouts = NULL;
22167
22168 VkPipelineLayout pipeline_layout;
22169 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22170 ASSERT_VK_SUCCESS(err);
22171
22172 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22173 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22174 rs_ci.pNext = nullptr;
22175 rs_ci.lineWidth = 1.0f;
22176 rs_ci.rasterizerDiscardEnable = true;
22177
22178 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22179 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22180
22181 // Set polygonMode=FILL. No error is expected
22182 m_errorMonitor->ExpectSuccess();
22183 {
22184 VkPipelineObj pipe(&test_device);
22185 pipe.AddShader(&vs);
22186 pipe.AddShader(&fs);
22187 pipe.AddColorAttachment();
22188 // Set polygonMode to a good value
22189 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22190 pipe.SetRasterization(&rs_ci);
22191 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22192 }
22193 m_errorMonitor->VerifyNotFound();
22194
22195 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22196}
22197
22198TEST_F(VkPositiveLayerTest, ValidPushConstants) {
22199 VkResult err;
22200 ASSERT_NO_FATAL_FAILURE(InitState());
22201 ASSERT_NO_FATAL_FAILURE(InitViewport());
22202 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22203
22204 VkPipelineLayout pipeline_layout;
22205 VkPushConstantRange pc_range = {};
22206 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22207 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22208 pipeline_layout_ci.pushConstantRangeCount = 1;
22209 pipeline_layout_ci.pPushConstantRanges = &pc_range;
22210
22211 //
22212 // Check for invalid push constant ranges in pipeline layouts.
22213 //
22214 struct PipelineLayoutTestCase {
22215 VkPushConstantRange const range;
22216 char const *msg;
22217 };
22218
22219 // Check for overlapping ranges
22220 const uint32_t ranges_per_test = 5;
22221 struct OverlappingRangeTestCase {
22222 VkPushConstantRange const ranges[ranges_per_test];
22223 char const *msg;
22224 };
22225
22226 // Run some positive tests to make sure overlap checking in the layer is OK
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022227 const std::array<OverlappingRangeTestCase, 2> overlapping_range_tests_pos = {{{{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
22228 {VK_SHADER_STAGE_VERTEX_BIT, 4, 4},
22229 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
22230 {VK_SHADER_STAGE_VERTEX_BIT, 12, 4},
22231 {VK_SHADER_STAGE_VERTEX_BIT, 16, 4}},
22232 ""},
22233 {{{VK_SHADER_STAGE_VERTEX_BIT, 92, 24},
22234 {VK_SHADER_STAGE_VERTEX_BIT, 80, 4},
22235 {VK_SHADER_STAGE_VERTEX_BIT, 64, 8},
22236 {VK_SHADER_STAGE_VERTEX_BIT, 4, 16},
22237 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
22238 ""}}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022239 for (const auto &iter : overlapping_range_tests_pos) {
22240 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
22241 m_errorMonitor->ExpectSuccess();
22242 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22243 m_errorMonitor->VerifyNotFound();
22244 if (VK_SUCCESS == err) {
22245 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22246 }
22247 }
22248
22249 //
22250 // CmdPushConstants tests
22251 //
22252 const uint8_t dummy_values[100] = {};
22253
Tony Barbour552f6c02016-12-21 14:34:07 -070022254 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022255
22256 // positive overlapping range tests with cmd
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022257 const std::array<PipelineLayoutTestCase, 4> cmd_overlap_tests_pos = {{
22258 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, ""},
22259 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 4}, ""},
22260 {{VK_SHADER_STAGE_VERTEX_BIT, 20, 12}, ""},
22261 {{VK_SHADER_STAGE_VERTEX_BIT, 56, 36}, ""},
22262 }};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022263
22264 // Setup ranges: [0,16) [20,36) [36,44) [44,52) [56,80) [80,92)
22265 const VkPushConstantRange pc_range4[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022266 {VK_SHADER_STAGE_VERTEX_BIT, 20, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 0, 16}, {VK_SHADER_STAGE_VERTEX_BIT, 44, 8},
22267 {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 -060022268 };
22269
22270 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range4) / sizeof(VkPushConstantRange);
22271 pipeline_layout_ci.pPushConstantRanges = pc_range4;
22272 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22273 ASSERT_VK_SUCCESS(err);
22274 for (const auto &iter : cmd_overlap_tests_pos) {
22275 m_errorMonitor->ExpectSuccess();
22276 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.range.stageFlags, iter.range.offset,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022277 iter.range.size, dummy_values);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022278 m_errorMonitor->VerifyNotFound();
22279 }
22280 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
22281
Tony Barbour552f6c02016-12-21 14:34:07 -070022282 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022283}
22284
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022285#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022286TEST_F(VkPositiveLayerTest, LongFenceChain)
22287{
22288 m_errorMonitor->ExpectSuccess();
22289
22290 ASSERT_NO_FATAL_FAILURE(InitState());
22291 VkResult err;
22292
22293 std::vector<VkFence> fences;
22294
22295 const int chainLength = 32768;
22296
22297 for (int i = 0; i < chainLength; i++) {
22298 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22299 VkFence fence;
22300 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22301 ASSERT_VK_SUCCESS(err);
22302
22303 fences.push_back(fence);
22304
22305 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22306 0, nullptr, 0, nullptr };
22307 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22308 ASSERT_VK_SUCCESS(err);
22309
22310 }
22311
22312 // BOOM, stack overflow.
22313 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22314
22315 for (auto fence : fences)
22316 vkDestroyFence(m_device->device(), fence, nullptr);
22317
22318 m_errorMonitor->VerifyNotFound();
22319}
22320#endif
22321
Cody Northrop1242dfd2016-07-13 17:24:59 -060022322#if defined(ANDROID) && defined(VALIDATION_APK)
22323static bool initialized = false;
22324static bool active = false;
22325
22326// Convert Intents to argv
22327// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022328std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022329 std::vector<std::string> args;
22330 JavaVM &vm = *app.activity->vm;
22331 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022332 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022333
22334 JNIEnv &env = *p_env;
22335 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022336 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022337 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022338 jmethodID get_string_extra_method =
22339 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022340 jvalue get_string_extra_args;
22341 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022342 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022343
22344 std::string args_str;
22345 if (extra_str) {
22346 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22347 args_str = extra_utf;
22348 env.ReleaseStringUTFChars(extra_str, extra_utf);
22349 env.DeleteLocalRef(extra_str);
22350 }
22351
22352 env.DeleteLocalRef(get_string_extra_args.l);
22353 env.DeleteLocalRef(intent);
22354 vm.DetachCurrentThread();
22355
22356 // split args_str
22357 std::stringstream ss(args_str);
22358 std::string arg;
22359 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022360 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022361 }
22362
22363 return args;
22364}
22365
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022366static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022367
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022368static void processCommand(struct android_app *app, int32_t cmd) {
22369 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022370 case APP_CMD_INIT_WINDOW: {
22371 if (app->window) {
22372 initialized = true;
22373 }
22374 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022375 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022376 case APP_CMD_GAINED_FOCUS: {
22377 active = true;
22378 break;
22379 }
22380 case APP_CMD_LOST_FOCUS: {
22381 active = false;
22382 break;
22383 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022384 }
22385}
22386
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022387void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022388 app_dummy();
22389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022390 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022391
22392 int vulkanSupport = InitVulkan();
22393 if (vulkanSupport == 0) {
22394 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22395 return;
22396 }
22397
22398 app->onAppCmd = processCommand;
22399 app->onInputEvent = processInput;
22400
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022401 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022402 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022403 struct android_poll_source *source;
22404 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022405 if (source) {
22406 source->process(app, source);
22407 }
22408
22409 if (app->destroyRequested != 0) {
22410 VkTestFramework::Finish();
22411 return;
22412 }
22413 }
22414
22415 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022416 // Use the following key to send arguments to gtest, i.e.
22417 // --es args "--gtest_filter=-VkLayerTest.foo"
22418 const char key[] = "args";
22419 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022421 std::string filter = "";
22422 if (args.size() > 0) {
22423 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22424 filter += args[0];
22425 } else {
22426 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22427 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022428
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022429 int argc = 2;
22430 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22431 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022432
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022433 // Route output to files until we can override the gtest output
22434 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22435 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022436
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022437 ::testing::InitGoogleTest(&argc, argv);
22438 VkTestFramework::InitArgs(&argc, argv);
22439 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022440
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022441 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022442
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022443 if (result != 0) {
22444 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22445 } else {
22446 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22447 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022448
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022449 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022450
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022451 fclose(stdout);
22452 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022453
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022454 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022455 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022456 }
22457 }
22458}
22459#endif
22460
Tony Barbour300a6082015-04-07 13:44:53 -060022461int main(int argc, char **argv) {
22462 int result;
22463
Cody Northrop8e54a402016-03-08 22:25:52 -070022464#ifdef ANDROID
22465 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022466 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022467#endif
22468
Tony Barbour300a6082015-04-07 13:44:53 -060022469 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022470 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022471
22472 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22473
22474 result = RUN_ALL_TESTS();
22475
Tony Barbour6918cd52015-04-09 12:58:51 -060022476 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022477 return result;
22478}