blob: 88bc089ad0b6a1e40d28b6420c478ef622f5d1fa [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;
Tobin Ehliscdf95132017-03-15 13:50:56 -0600358 bool m_enable_maintenance1_ext = false;
Tony Barbour300a6082015-04-07 13:44:53 -0600359
360 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600361 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600362 std::vector<const char *> instance_extension_names;
363 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600364
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700365 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600366 /*
367 * Since CreateDbgMsgCallback is an instance level extension call
368 * any extension / layer that utilizes that feature also needs
369 * to be enabled at create instance time.
370 */
Karl Schultz6addd812016-02-02 17:17:23 -0700371 // Use Threading layer first to protect others from
372 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700373 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600374 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800375 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700376 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600377 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700378 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600379
Ian Elliott2c1daf52016-05-12 09:41:46 -0600380 if (m_enableWSI) {
381 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
382 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
383#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
384#if defined(VK_USE_PLATFORM_ANDROID_KHR)
385 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700386#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600387#if defined(VK_USE_PLATFORM_MIR_KHR)
388 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700389#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600390#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
391 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700392#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600393#if defined(VK_USE_PLATFORM_WIN32_KHR)
394 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700395#endif // VK_USE_PLATFORM_WIN32_KHR
396#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600397#if defined(VK_USE_PLATFORM_XCB_KHR)
398 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
399#elif defined(VK_USE_PLATFORM_XLIB_KHR)
400 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700401#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600402 }
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600403 if (m_enable_maintenance1_ext) {
404 device_extension_names.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME);
405 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600406
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600407 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600408 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800409 this->app_info.pApplicationName = "layer_tests";
410 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600411 this->app_info.pEngineName = "unittest";
412 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600413 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600414
Tony Barbour15524c32015-04-29 17:34:29 -0600415 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600416 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600417 }
418
419 virtual void TearDown() {
420 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600421 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600422 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600423 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600424
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600425 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600426};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500427
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600428void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500429 // Create identity matrix
430 int i;
431 struct vktriangle_vs_uniform data;
432
433 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 glm::mat4 View = glm::mat4(1.0f);
435 glm::mat4 Model = glm::mat4(1.0f);
436 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500437 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700438 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500439
440 memcpy(&data.mvp, &MVP[0][0], matrixSize);
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600443 {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 -0500444 };
445
Karl Schultz6addd812016-02-02 17:17:23 -0700446 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500447 data.position[i][0] = tri_data[i].posX;
448 data.position[i][1] = tri_data[i].posY;
449 data.position[i][2] = tri_data[i].posZ;
450 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700451 data.color[i][0] = tri_data[i].r;
452 data.color[i][1] = tri_data[i].g;
453 data.color[i][2] = tri_data[i].b;
454 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500455 }
456
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457 ASSERT_NO_FATAL_FAILURE(InitViewport());
458
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200459 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
460 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500461
Karl Schultz6addd812016-02-02 17:17:23 -0700462 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600463 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500464
465 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800466 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500467 pipelineobj.AddShader(&vs);
468 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600469 if (failMask & BsoFailLineWidth) {
470 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600471 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600472 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600473 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
474 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600475 }
476 if (failMask & BsoFailDepthBias) {
477 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600479 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600480 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600481 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600482 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600483 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700484 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700485 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600486 if (failMask & BsoFailViewport) {
487 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
488 }
489 if (failMask & BsoFailScissor) {
490 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
491 }
492 if (failMask & BsoFailBlend) {
493 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600494 VkPipelineColorBlendAttachmentState att_state = {};
495 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
496 att_state.blendEnable = VK_TRUE;
497 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600498 }
499 if (failMask & BsoFailDepthBounds) {
500 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
501 }
502 if (failMask & BsoFailStencilReadMask) {
503 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
504 }
505 if (failMask & BsoFailStencilWriteMask) {
506 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
507 }
508 if (failMask & BsoFailStencilReference) {
509 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
510 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500511
512 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600513 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
515 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700516 m_commandBuffer->BeginCommandBuffer();
517 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500518
Tony Barbourfe3351b2015-07-28 10:17:20 -0600519 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500520
521 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600522 if (failMask & BsoFailIndexBuffer) {
523 // Use DrawIndexed w/o an index buffer bound
524 DrawIndexed(3, 1, 0, 0, 0);
525 } else {
526 Draw(3, 1, 0, 0);
527 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500528
Mark Muellerd4914412016-06-13 17:52:06 -0600529 if (failMask & BsoFailCmdClearAttachments) {
530 VkClearAttachment color_attachment = {};
531 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700532 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600533 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
534
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600535 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600536 }
537
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700539 m_commandBuffer->EndRenderPass();
540 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600541 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542}
543
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600544void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
545 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600547 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500548 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600549 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500550 }
551
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800552 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700553 // Make sure depthWriteEnable is set so that Depth fail test will work
554 // correctly
555 // Make sure stencilTestEnable is set so that Stencil fail test will work
556 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600557 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800558 stencil.failOp = VK_STENCIL_OP_KEEP;
559 stencil.passOp = VK_STENCIL_OP_KEEP;
560 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
561 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600562
563 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
564 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600565 ds_ci.pNext = NULL;
566 ds_ci.depthTestEnable = VK_FALSE;
567 ds_ci.depthWriteEnable = VK_TRUE;
568 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
569 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 if (failMask & BsoFailDepthBounds) {
571 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600572 ds_ci.maxDepthBounds = 0.0f;
573 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600574 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600575 ds_ci.stencilTestEnable = VK_TRUE;
576 ds_ci.front = stencil;
577 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600578
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600579 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600580 pipelineobj.SetViewport(m_viewports);
581 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800582 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600583 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600584 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800585 commandBuffer->BindPipeline(pipelineobj);
586 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500587}
588
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -0600589class VkMaintenance1LayerTest : public VkLayerTest {
590 public:
591 protected:
592 VkMaintenance1LayerTest(){ m_enable_maintenance1_ext = true; }
593};
594
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600595class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700596 public:
597 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600598};
599
Ian Elliott2c1daf52016-05-12 09:41:46 -0600600class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700601 public:
602 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600603 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600604};
605
Mark Muellerdfe37552016-07-07 14:47:42 -0600606class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700607 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600608 enum eTestEnFlags {
609 eDoubleDelete,
610 eInvalidDeviceOffset,
611 eInvalidMemoryOffset,
612 eBindNullBuffer,
613 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600614 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600615 };
616
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600617 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600618
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600619 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
620 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600621 return true;
622 }
623 VkDeviceSize offset_limit = 0;
624 if (eInvalidMemoryOffset == aTestFlag) {
625 VkBuffer vulkanBuffer;
626 VkBufferCreateInfo buffer_create_info = {};
627 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
628 buffer_create_info.size = 32;
629 buffer_create_info.usage = aBufferUsage;
630
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600631 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600632 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600633
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600634 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600635 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
636 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600637 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
638 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600639 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600640 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600641 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600642 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 }
644 if (eOffsetAlignment < offset_limit) {
645 return true;
646 }
647 return false;
648 }
649
650 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600651 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
652 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600653 if (eBindNullBuffer == aTestFlag) {
654 VulkanMemory = 0;
655 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
656 } else {
657 VkBufferCreateInfo buffer_create_info = {};
658 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
659 buffer_create_info.size = 32;
660 buffer_create_info.usage = aBufferUsage;
661
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600663
664 CreateCurrent = true;
665
666 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600667 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600668
669 VkMemoryAllocateInfo memory_allocate_info = {};
670 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800671 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
673 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 if (!pass) {
675 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
676 return;
677 }
678
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600679 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600680 AllocateCurrent = true;
681 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600682 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
683 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600684 BoundCurrent = true;
685
686 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
687 }
688 }
689
690 ~VkBufferTest() {
691 if (CreateCurrent) {
692 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
693 }
694 if (AllocateCurrent) {
695 if (InvalidDeleteEn) {
696 union {
697 VkDeviceMemory device_memory;
698 unsigned long long index_access;
699 } bad_index;
700
701 bad_index.device_memory = VulkanMemory;
702 bad_index.index_access++;
703
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600704 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600705 }
706 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
707 }
708 }
709
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600710 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600711
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600712 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600713
714 void TestDoubleDestroy() {
715 // Destroy the buffer but leave the flag set, which will cause
716 // the buffer to be destroyed again in the destructor.
717 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
718 }
719
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700720 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600721 bool AllocateCurrent;
722 bool BoundCurrent;
723 bool CreateCurrent;
724 bool InvalidDeleteEn;
725
726 VkBuffer VulkanBuffer;
727 VkDevice VulkanDevice;
728 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600729};
730
731class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600733 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600734 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700735 : BoundCurrent(false),
736 AttributeCount(aAttributeCount),
737 BindingCount(aBindingCount),
738 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600739 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600740 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
741 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700742 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600743
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600744 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
745 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600746
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
748 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
749 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
750 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
751 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600752
753 unsigned i = 0;
754 do {
755 VertexInputAttributeDescription[i].binding = BindId;
756 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600757 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
758 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600759 i++;
760 } while (AttributeCount < i);
761
762 i = 0;
763 do {
764 VertexInputBindingDescription[i].binding = BindId;
765 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600766 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600767 i++;
768 } while (BindingCount < i);
769 }
770
771 ~VkVerticesObj() {
772 if (VertexInputAttributeDescription) {
773 delete[] VertexInputAttributeDescription;
774 }
775 if (VertexInputBindingDescription) {
776 delete[] VertexInputBindingDescription;
777 }
778 }
779
780 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600781 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
782 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600783 return true;
784 }
785
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600786 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600787 VkDeviceSize *offsetList;
788 unsigned offsetCount;
789
790 if (aOffsetCount) {
791 offsetList = aOffsetList;
792 offsetCount = aOffsetCount;
793 } else {
794 offsetList = new VkDeviceSize[1]();
795 offsetCount = 1;
796 }
797
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600798 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600799 BoundCurrent = true;
800
801 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600802 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600803 }
804 }
805
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700806 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600807 static uint32_t BindIdGenerator;
808
809 bool BoundCurrent;
810 unsigned AttributeCount;
811 unsigned BindingCount;
812 uint32_t BindId;
813
814 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
815 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
816 VkVertexInputBindingDescription *VertexInputBindingDescription;
817 VkConstantBufferObj VulkanMemoryBuffer;
818};
819
820uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500821// ********************************************************************************************************************
822// ********************************************************************************************************************
823// ********************************************************************************************************************
824// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600825TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700826 TEST_DESCRIPTION(
827 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
828 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600829
830 ASSERT_NO_FATAL_FAILURE(InitState());
831
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600832 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600833 // Specify NULL for a pointer to a handle
834 // Expected to trigger an error with
835 // parameter_validation::validate_required_pointer
836 vkGetPhysicalDeviceFeatures(gpu(), NULL);
837 m_errorMonitor->VerifyFound();
838
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
840 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600841 // Specify NULL for pointer to array count
842 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600843 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 m_errorMonitor->VerifyFound();
845
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600847 // Specify 0 for a required array count
848 // Expected to trigger an error with parameter_validation::validate_array
849 VkViewport view_port = {};
850 m_commandBuffer->SetViewport(0, 0, &view_port);
851 m_errorMonitor->VerifyFound();
852
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600853 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600854 // Specify NULL for a required array
855 // Expected to trigger an error with parameter_validation::validate_array
856 m_commandBuffer->SetViewport(0, 1, NULL);
857 m_errorMonitor->VerifyFound();
858
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600860 // Specify VK_NULL_HANDLE for a required handle
861 // Expected to trigger an error with
862 // parameter_validation::validate_required_handle
863 vkUnmapMemory(device(), VK_NULL_HANDLE);
864 m_errorMonitor->VerifyFound();
865
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
867 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600868 // Specify VK_NULL_HANDLE for a required handle array entry
869 // Expected to trigger an error with
870 // parameter_validation::validate_required_handle_array
871 VkFence fence = VK_NULL_HANDLE;
872 vkResetFences(device(), 1, &fence);
873 m_errorMonitor->VerifyFound();
874
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600875 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600876 // Specify NULL for a required struct pointer
877 // Expected to trigger an error with
878 // parameter_validation::validate_struct_type
879 VkDeviceMemory memory = VK_NULL_HANDLE;
880 vkAllocateMemory(device(), NULL, NULL, &memory);
881 m_errorMonitor->VerifyFound();
882
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600884 // Specify 0 for a required VkFlags parameter
885 // Expected to trigger an error with parameter_validation::validate_flags
886 m_commandBuffer->SetStencilReference(0, 0);
887 m_errorMonitor->VerifyFound();
888
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600889 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 -0600890 // Specify 0 for a required VkFlags array entry
891 // Expected to trigger an error with
892 // parameter_validation::validate_flags_array
893 VkSemaphore semaphore = VK_NULL_HANDLE;
894 VkPipelineStageFlags stageFlags = 0;
895 VkSubmitInfo submitInfo = {};
896 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
897 submitInfo.waitSemaphoreCount = 1;
898 submitInfo.pWaitSemaphores = &semaphore;
899 submitInfo.pWaitDstStageMask = &stageFlags;
900 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
901 m_errorMonitor->VerifyFound();
902}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600903
Dustin Gravesfce74c02016-05-10 11:42:58 -0600904TEST_F(VkLayerTest, ReservedParameter) {
905 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
906
907 ASSERT_NO_FATAL_FAILURE(InitState());
908
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600909 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600910 // Specify 0 for a reserved VkFlags parameter
911 // Expected to trigger an error with
912 // parameter_validation::validate_reserved_flags
913 VkEvent event_handle = VK_NULL_HANDLE;
914 VkEventCreateInfo event_info = {};
915 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
916 event_info.flags = 1;
917 vkCreateEvent(device(), &event_info, NULL, &event_handle);
918 m_errorMonitor->VerifyFound();
919}
920
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600921TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700922 TEST_DESCRIPTION(
923 "Specify an invalid VkStructureType for a Vulkan "
924 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600925
926 ASSERT_NO_FATAL_FAILURE(InitState());
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->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
933 VkMemoryAllocateInfo alloc_info = {};
934 VkDeviceMemory memory = VK_NULL_HANDLE;
935 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
936 m_errorMonitor->VerifyFound();
937
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600939 // Zero struct memory, effectively setting sType to
940 // VK_STRUCTURE_TYPE_APPLICATION_INFO
941 // Expected to trigger an error with
942 // parameter_validation::validate_struct_type_array
943 VkSubmitInfo submit_info = {};
944 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
945 m_errorMonitor->VerifyFound();
946}
947
948TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600949 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600950
951 ASSERT_NO_FATAL_FAILURE(InitState());
952
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600953 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600954 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600955 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600956 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600957 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600958 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600959 // Zero-initialization will provide the correct sType
960 VkApplicationInfo app_info = {};
961 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
962 event_alloc_info.pNext = &app_info;
963 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
964 m_errorMonitor->VerifyFound();
965
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
967 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600968 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
969 // a function that has allowed pNext structure types and specify
970 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600971 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600972 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600973 VkMemoryAllocateInfo memory_alloc_info = {};
974 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
975 memory_alloc_info.pNext = &app_info;
976 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600977 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600978}
Dustin Graves5d33d532016-05-09 16:21:12 -0600979
980TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600981 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600982
983 ASSERT_NO_FATAL_FAILURE(InitState());
984
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700985 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
986 "does not fall within the begin..end "
987 "range of the core VkFormat "
988 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600989 // Specify an invalid VkFormat value
990 // Expected to trigger an error with
991 // parameter_validation::validate_ranged_enum
992 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600993 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600994 m_errorMonitor->VerifyFound();
995
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600996 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 -0600997 // Specify an invalid VkFlags bitmask value
998 // Expected to trigger an error with parameter_validation::validate_flags
999 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001000 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1001 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -06001002 m_errorMonitor->VerifyFound();
1003
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001004 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 -06001005 // Specify an invalid VkFlags array entry
1006 // Expected to trigger an error with
1007 // parameter_validation::validate_flags_array
1008 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001009 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001010 VkSubmitInfo submit_info = {};
1011 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1012 submit_info.waitSemaphoreCount = 1;
1013 submit_info.pWaitSemaphores = &semaphore;
1014 submit_info.pWaitDstStageMask = &stage_flags;
1015 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1016 m_errorMonitor->VerifyFound();
1017
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001018 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001019 // Specify an invalid VkBool32 value
1020 // Expected to trigger a warning with
1021 // parameter_validation::validate_bool32
1022 VkSampler sampler = VK_NULL_HANDLE;
1023 VkSamplerCreateInfo sampler_info = {};
1024 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1025 sampler_info.pNext = NULL;
1026 sampler_info.magFilter = VK_FILTER_NEAREST;
1027 sampler_info.minFilter = VK_FILTER_NEAREST;
1028 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1029 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1030 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1031 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1032 sampler_info.mipLodBias = 1.0;
1033 sampler_info.maxAnisotropy = 1;
1034 sampler_info.compareEnable = VK_FALSE;
1035 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1036 sampler_info.minLod = 1.0;
1037 sampler_info.maxLod = 1.0;
1038 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1039 sampler_info.unnormalizedCoordinates = VK_FALSE;
1040 // Not VK_TRUE or VK_FALSE
1041 sampler_info.anisotropyEnable = 3;
1042 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1043 m_errorMonitor->VerifyFound();
1044}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001045
1046TEST_F(VkLayerTest, FailedReturnValue) {
1047 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1048
1049 ASSERT_NO_FATAL_FAILURE(InitState());
1050
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001051 // Find an unsupported image format
1052 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1053 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1054 VkFormat format = static_cast<VkFormat>(f);
1055 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001056 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001057 unsupported = format;
1058 break;
1059 }
1060 }
1061
1062 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001063 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1064 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001065 // Specify an unsupported VkFormat value to generate a
1066 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1067 // Expected to trigger a warning from
1068 // parameter_validation::validate_result
1069 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001070 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1071 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001072 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1073 m_errorMonitor->VerifyFound();
1074 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001075}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001076
1077TEST_F(VkLayerTest, UpdateBufferAlignment) {
1078 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080
1081 ASSERT_NO_FATAL_FAILURE(InitState());
1082
1083 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1084 vk_testing::Buffer buffer;
1085 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1086
Tony Barbour552f6c02016-12-21 14:34:07 -07001087 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001088 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001090 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1091 m_errorMonitor->VerifyFound();
1092
1093 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001095 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1096 m_errorMonitor->VerifyFound();
1097
1098 // Introduce failure by using dataSize that is < 0
1099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001100 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1102 m_errorMonitor->VerifyFound();
1103
1104 // Introduce failure by using dataSize that is > 65536
1105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001106 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001107 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1108 m_errorMonitor->VerifyFound();
1109
Tony Barbour552f6c02016-12-21 14:34:07 -07001110 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001111}
1112
1113TEST_F(VkLayerTest, FillBufferAlignment) {
1114 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1115
1116 ASSERT_NO_FATAL_FAILURE(InitState());
1117
1118 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1119 vk_testing::Buffer buffer;
1120 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1121
Tony Barbour552f6c02016-12-21 14:34:07 -07001122 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001123
1124 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
1129 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001130 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001131 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1132 m_errorMonitor->VerifyFound();
1133
1134 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001136 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1137 m_errorMonitor->VerifyFound();
1138
Tony Barbour552f6c02016-12-21 14:34:07 -07001139 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001140}
Dustin Graves40f35822016-06-23 11:12:53 -06001141
Cortd889ff92016-07-27 09:51:27 -07001142TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1143 VkResult err;
1144
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001145 TEST_DESCRIPTION(
1146 "Attempt to use a non-solid polygon fill mode in a "
1147 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001148
1149 ASSERT_NO_FATAL_FAILURE(InitState());
1150 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1151
1152 std::vector<const char *> device_extension_names;
1153 auto features = m_device->phy().features();
1154 // Artificially disable support for non-solid fill modes
1155 features.fillModeNonSolid = false;
1156 // The sacrificial device object
1157 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1158
1159 VkRenderpassObj render_pass(&test_device);
1160
1161 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1162 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1163 pipeline_layout_ci.setLayoutCount = 0;
1164 pipeline_layout_ci.pSetLayouts = NULL;
1165
1166 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001167 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001168 ASSERT_VK_SUCCESS(err);
1169
1170 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1171 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1172 rs_ci.pNext = nullptr;
1173 rs_ci.lineWidth = 1.0f;
1174 rs_ci.rasterizerDiscardEnable = true;
1175
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001176 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1177 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001178
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001179 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1181 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001182 {
1183 VkPipelineObj pipe(&test_device);
1184 pipe.AddShader(&vs);
1185 pipe.AddShader(&fs);
1186 pipe.AddColorAttachment();
1187 // Introduce failure by setting unsupported polygon mode
1188 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1189 pipe.SetRasterization(&rs_ci);
1190 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1191 }
1192 m_errorMonitor->VerifyFound();
1193
1194 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001195 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1196 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001197 {
1198 VkPipelineObj pipe(&test_device);
1199 pipe.AddShader(&vs);
1200 pipe.AddShader(&fs);
1201 pipe.AddColorAttachment();
1202 // Introduce failure by setting unsupported polygon mode
1203 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1204 pipe.SetRasterization(&rs_ci);
1205 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1206 }
1207 m_errorMonitor->VerifyFound();
1208
Cortd889ff92016-07-27 09:51:27 -07001209 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1210}
1211
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001212#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001213TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001214{
1215 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001216 VkFenceCreateInfo fenceInfo = {};
1217 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1218 fenceInfo.pNext = NULL;
1219 fenceInfo.flags = 0;
1220
Mike Weiblencce7ec72016-10-17 19:33:05 -06001221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001222
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001223 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001224
1225 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1226 vk_testing::Buffer buffer;
1227 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001228
Tony Barbourfe3351b2015-07-28 10:17:20 -06001229 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001230 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001231 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001232
1233 testFence.init(*m_device, fenceInfo);
1234
1235 // Bypass framework since it does the waits automatically
1236 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001237 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001238 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1239 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001240 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001241 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001242 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001243 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001244 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001245 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001246 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001247
1248 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001249 ASSERT_VK_SUCCESS( err );
1250
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001251 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001252 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001253
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001254 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001255}
1256
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001257TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001258{
1259 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001260 VkFenceCreateInfo fenceInfo = {};
1261 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1262 fenceInfo.pNext = NULL;
1263 fenceInfo.flags = 0;
1264
Mike Weiblencce7ec72016-10-17 19:33:05 -06001265 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001266
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001267 ASSERT_NO_FATAL_FAILURE(InitState());
1268 ASSERT_NO_FATAL_FAILURE(InitViewport());
1269 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1270
Tony Barbourfe3351b2015-07-28 10:17:20 -06001271 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001272 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001273 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001274
1275 testFence.init(*m_device, fenceInfo);
1276
1277 // Bypass framework since it does the waits automatically
1278 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001279 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001280 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1281 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001282 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001283 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001284 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001285 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001286 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001287 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001288 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001289
1290 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001291 ASSERT_VK_SUCCESS( err );
1292
Jon Ashburnf19916e2016-01-11 13:12:43 -07001293 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001294 VkCommandBufferBeginInfo info = {};
1295 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1296 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001297 info.renderPass = VK_NULL_HANDLE;
1298 info.subpass = 0;
1299 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001300 info.occlusionQueryEnable = VK_FALSE;
1301 info.queryFlags = 0;
1302 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001303
1304 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001305 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001306
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001307 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001308}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001309#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001310
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001311TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1312 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1313
1314 ASSERT_NO_FATAL_FAILURE(InitState());
1315
1316 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1317 VkBuffer buffer;
1318 VkBufferCreateInfo buf_info = {};
1319 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1320 buf_info.pNext = NULL;
1321 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1322 buf_info.size = 2048;
1323 buf_info.queueFamilyIndexCount = 0;
1324 buf_info.pQueueFamilyIndices = NULL;
1325 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1326 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1327 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1328 m_errorMonitor->VerifyFound();
1329
1330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1331 VkImage image;
1332 VkImageCreateInfo image_create_info = {};
1333 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1334 image_create_info.pNext = NULL;
1335 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1336 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1337 image_create_info.extent.width = 512;
1338 image_create_info.extent.height = 64;
1339 image_create_info.extent.depth = 1;
1340 image_create_info.mipLevels = 1;
1341 image_create_info.arrayLayers = 1;
1342 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1343 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1344 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1345 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1346 image_create_info.queueFamilyIndexCount = 0;
1347 image_create_info.pQueueFamilyIndices = NULL;
1348 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1349 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1350 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1351 m_errorMonitor->VerifyFound();
1352}
1353
Dave Houlton829c0d82017-01-24 15:09:17 -07001354TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1355 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1356
1357 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001358 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001359 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1360
1361 // Mask out device features we don't want
1362 VkPhysicalDeviceFeatures desired_features = available_features;
1363 desired_features.sparseResidencyImage2D = VK_FALSE;
1364 desired_features.sparseResidencyImage3D = VK_FALSE;
1365 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1366
1367 VkImage image = VK_NULL_HANDLE;
1368 VkResult result = VK_RESULT_MAX_ENUM;
1369 VkImageCreateInfo image_create_info = {};
1370 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1371 image_create_info.pNext = NULL;
1372 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1373 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1374 image_create_info.extent.width = 512;
1375 image_create_info.extent.height = 1;
1376 image_create_info.extent.depth = 1;
1377 image_create_info.mipLevels = 1;
1378 image_create_info.arrayLayers = 1;
1379 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1380 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1381 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1382 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1383 image_create_info.queueFamilyIndexCount = 0;
1384 image_create_info.pQueueFamilyIndices = NULL;
1385 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1386 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1387
1388 // 1D image w/ sparse residency is an error
1389 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1390 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1391 m_errorMonitor->VerifyFound();
1392 if (VK_SUCCESS == result) {
1393 vkDestroyImage(m_device->device(), image, NULL);
1394 image = VK_NULL_HANDLE;
1395 }
1396
1397 // 2D image w/ sparse residency when feature isn't available
1398 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1399 image_create_info.extent.height = 64;
1400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1401 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1402 m_errorMonitor->VerifyFound();
1403 if (VK_SUCCESS == result) {
1404 vkDestroyImage(m_device->device(), image, NULL);
1405 image = VK_NULL_HANDLE;
1406 }
1407
1408 // 3D image w/ sparse residency when feature isn't available
1409 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1410 image_create_info.extent.depth = 8;
1411 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1412 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1413 m_errorMonitor->VerifyFound();
1414 if (VK_SUCCESS == result) {
1415 vkDestroyImage(m_device->device(), image, NULL);
1416 image = VK_NULL_HANDLE;
1417 }
1418}
1419
1420TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1421 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1422
1423 // Determine which device feature are available
Jamie Madill35127872017-03-15 16:17:46 -04001424 VkPhysicalDeviceFeatures available_features = {};
Dave Houlton829c0d82017-01-24 15:09:17 -07001425 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1426
1427 // These tests all require that the device support sparse residency for 2D images
1428 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1429 return;
1430 }
1431
1432 // Mask out device features we don't want
1433 VkPhysicalDeviceFeatures desired_features = available_features;
1434 desired_features.sparseResidency2Samples = VK_FALSE;
1435 desired_features.sparseResidency4Samples = VK_FALSE;
1436 desired_features.sparseResidency8Samples = VK_FALSE;
1437 desired_features.sparseResidency16Samples = VK_FALSE;
1438 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1439
1440 VkImage image = VK_NULL_HANDLE;
1441 VkResult result = VK_RESULT_MAX_ENUM;
1442 VkImageCreateInfo image_create_info = {};
1443 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1444 image_create_info.pNext = NULL;
1445 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1446 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1447 image_create_info.extent.width = 64;
1448 image_create_info.extent.height = 64;
1449 image_create_info.extent.depth = 1;
1450 image_create_info.mipLevels = 1;
1451 image_create_info.arrayLayers = 1;
1452 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1453 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1454 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1455 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1456 image_create_info.queueFamilyIndexCount = 0;
1457 image_create_info.pQueueFamilyIndices = NULL;
1458 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1459 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1460
1461 // 2D image w/ sparse residency and linear tiling is an error
1462 m_errorMonitor->SetDesiredFailureMsg(
1463 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1464 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1465 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1466 m_errorMonitor->VerifyFound();
1467 if (VK_SUCCESS == result) {
1468 vkDestroyImage(m_device->device(), image, NULL);
1469 image = VK_NULL_HANDLE;
1470 }
1471 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1472
1473 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1474 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1475 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1476 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1477 m_errorMonitor->VerifyFound();
1478 if (VK_SUCCESS == result) {
1479 vkDestroyImage(m_device->device(), image, NULL);
1480 image = VK_NULL_HANDLE;
1481 }
1482
1483 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1485 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1486 m_errorMonitor->VerifyFound();
1487 if (VK_SUCCESS == result) {
1488 vkDestroyImage(m_device->device(), image, NULL);
1489 image = VK_NULL_HANDLE;
1490 }
1491
1492 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1493 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1494 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1495 m_errorMonitor->VerifyFound();
1496 if (VK_SUCCESS == result) {
1497 vkDestroyImage(m_device->device(), image, NULL);
1498 image = VK_NULL_HANDLE;
1499 }
1500
1501 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1503 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1504 m_errorMonitor->VerifyFound();
1505 if (VK_SUCCESS == result) {
1506 vkDestroyImage(m_device->device(), image, NULL);
1507 image = VK_NULL_HANDLE;
1508 }
1509}
1510
Tobin Ehlisf11be982016-05-11 13:52:53 -06001511TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 TEST_DESCRIPTION(
1513 "Create a buffer and image, allocate memory, and bind the "
1514 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001515 VkResult err;
1516 bool pass;
1517 ASSERT_NO_FATAL_FAILURE(InitState());
1518
Tobin Ehlis077ded32016-05-12 17:39:13 -06001519 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001520 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001521 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001522 VkDeviceMemory mem; // buffer will be bound first
1523 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001524 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001525 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001526
1527 VkBufferCreateInfo buf_info = {};
1528 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1529 buf_info.pNext = NULL;
1530 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1531 buf_info.size = 256;
1532 buf_info.queueFamilyIndexCount = 0;
1533 buf_info.pQueueFamilyIndices = NULL;
1534 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1535 buf_info.flags = 0;
1536 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1537 ASSERT_VK_SUCCESS(err);
1538
Tobin Ehlis077ded32016-05-12 17:39:13 -06001539 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001540
1541 VkImageCreateInfo image_create_info = {};
1542 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1543 image_create_info.pNext = NULL;
1544 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1545 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1546 image_create_info.extent.width = 64;
1547 image_create_info.extent.height = 64;
1548 image_create_info.extent.depth = 1;
1549 image_create_info.mipLevels = 1;
1550 image_create_info.arrayLayers = 1;
1551 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001552 // Image tiling must be optimal to trigger error when aliasing linear buffer
1553 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001554 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1555 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1556 image_create_info.queueFamilyIndexCount = 0;
1557 image_create_info.pQueueFamilyIndices = NULL;
1558 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1559 image_create_info.flags = 0;
1560
Tobin Ehlisf11be982016-05-11 13:52:53 -06001561 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1562 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001563 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1564 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001565
Tobin Ehlis077ded32016-05-12 17:39:13 -06001566 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1567
1568 VkMemoryAllocateInfo alloc_info = {};
1569 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1570 alloc_info.pNext = NULL;
1571 alloc_info.memoryTypeIndex = 0;
1572 // Ensure memory is big enough for both bindings
1573 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001574 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1575 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001576 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001577 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001578 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001579 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001580 return;
1581 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001582 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1583 ASSERT_VK_SUCCESS(err);
1584 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1585 ASSERT_VK_SUCCESS(err);
1586
Rene Lindsayd14f5572016-12-16 14:57:18 -07001587 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1588
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001589 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001590 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1592 m_errorMonitor->VerifyFound();
1593
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001594 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001595 // aliasing buffer2
1596 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1597 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001598 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1599 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001602 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001603 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001604 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001605 m_errorMonitor->VerifyFound();
1606
1607 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001608 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001609 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001610 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001611 vkFreeMemory(m_device->device(), mem, NULL);
1612 vkFreeMemory(m_device->device(), mem_img, NULL);
1613}
1614
Tobin Ehlis35372522016-05-12 08:32:31 -06001615TEST_F(VkLayerTest, InvalidMemoryMapping) {
1616 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1617 VkResult err;
1618 bool pass;
1619 ASSERT_NO_FATAL_FAILURE(InitState());
1620
1621 VkBuffer buffer;
1622 VkDeviceMemory mem;
1623 VkMemoryRequirements mem_reqs;
1624
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001625 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1626
Tobin Ehlis35372522016-05-12 08:32:31 -06001627 VkBufferCreateInfo buf_info = {};
1628 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1629 buf_info.pNext = NULL;
1630 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1631 buf_info.size = 256;
1632 buf_info.queueFamilyIndexCount = 0;
1633 buf_info.pQueueFamilyIndices = NULL;
1634 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1635 buf_info.flags = 0;
1636 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1637 ASSERT_VK_SUCCESS(err);
1638
1639 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1640 VkMemoryAllocateInfo alloc_info = {};
1641 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1642 alloc_info.pNext = NULL;
1643 alloc_info.memoryTypeIndex = 0;
1644
1645 // Ensure memory is big enough for both bindings
1646 static const VkDeviceSize allocation_size = 0x10000;
1647 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 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 -06001649 if (!pass) {
1650 vkDestroyBuffer(m_device->device(), buffer, NULL);
1651 return;
1652 }
1653 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1654 ASSERT_VK_SUCCESS(err);
1655
1656 uint8_t *pData;
1657 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001658 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 -06001659 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1660 m_errorMonitor->VerifyFound();
1661 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001663 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1665 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1666 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001667 m_errorMonitor->VerifyFound();
1668
1669 // Unmap the memory to avoid re-map error
1670 vkUnmapMemory(m_device->device(), mem);
1671 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001672 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1673 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1674 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 m_errorMonitor->VerifyFound();
1676 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001677 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1678 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001679 m_errorMonitor->VerifyFound();
1680 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001681 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001682 vkUnmapMemory(m_device->device(), mem);
1683 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001684
Tobin Ehlis35372522016-05-12 08:32:31 -06001685 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001686 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001687 ASSERT_VK_SUCCESS(err);
1688 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001689 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001690 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001695
Tobin Ehlis35372522016-05-12 08:32:31 -06001696 // Now flush range that oversteps mapped range
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001701 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
1706 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1707 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001708 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001709 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001710 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001711 mmr.size = VK_WHOLE_SIZE;
1712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001713 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1714 m_errorMonitor->VerifyFound();
1715
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001716#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001717 // Some platforms have an atomsize of 1 which makes the test meaningless
1718 if (atom_size > 3) {
1719 // Now with an offset 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 = 3; // Not a multiple of atom_size
1724 mmr.size = VK_WHOLE_SIZE;
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728
1729 // Now with a size NOT a multiple of the device limit
1730 vkUnmapMemory(m_device->device(), mem);
1731 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1732 ASSERT_VK_SUCCESS(err);
1733 mmr.offset = atom_size;
1734 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1736 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1737 m_errorMonitor->VerifyFound();
1738 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001739#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001740 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1741 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001742 if (!pass) {
1743 vkFreeMemory(m_device->device(), mem, NULL);
1744 vkDestroyBuffer(m_device->device(), buffer, NULL);
1745 return;
1746 }
1747 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1748 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1749
1750 vkDestroyBuffer(m_device->device(), buffer, NULL);
1751 vkFreeMemory(m_device->device(), mem, NULL);
1752}
1753
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001754#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001755TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1756 VkResult err;
1757 bool pass;
1758
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001759 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1760 // following declaration (which is temporarily being moved below):
1761 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001762 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001763 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001764 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001765 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001766 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001767 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001768
1769 ASSERT_NO_FATAL_FAILURE(InitState());
1770
Ian Elliott3f06ce52016-04-29 14:46:21 -06001771#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1772#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1773 // Use the functions from the VK_KHR_android_surface extension without
1774 // enabling that extension:
1775
1776 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001777 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001778 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1779 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001780 pass = (err != VK_SUCCESS);
1781 ASSERT_TRUE(pass);
1782 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001783#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001784
Ian Elliott3f06ce52016-04-29 14:46:21 -06001785#if defined(VK_USE_PLATFORM_MIR_KHR)
1786 // Use the functions from the VK_KHR_mir_surface extension without enabling
1787 // that extension:
1788
1789 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001790 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001792 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1793 pass = (err != VK_SUCCESS);
1794 ASSERT_TRUE(pass);
1795 m_errorMonitor->VerifyFound();
1796
1797 // Tell whether an mir_connection supports presentation:
1798 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1800 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001801 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001802#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001803
Ian Elliott3f06ce52016-04-29 14:46:21 -06001804#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1805 // Use the functions from the VK_KHR_wayland_surface extension without
1806 // enabling that extension:
1807
1808 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001809 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1811 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001812 pass = (err != VK_SUCCESS);
1813 ASSERT_TRUE(pass);
1814 m_errorMonitor->VerifyFound();
1815
1816 // Tell whether an wayland_display supports presentation:
1817 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1819 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001820 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001821#endif // VK_USE_PLATFORM_WAYLAND_KHR
1822#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001823
Ian Elliott3f06ce52016-04-29 14:46:21 -06001824#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001825 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1826 // TO NON-LINUX PLATFORMS:
1827 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001828 // Use the functions from the VK_KHR_win32_surface extension without
1829 // enabling that extension:
1830
1831 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001832 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1834 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001835 pass = (err != VK_SUCCESS);
1836 ASSERT_TRUE(pass);
1837 m_errorMonitor->VerifyFound();
1838
1839 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001841 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001842 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001843// Set this (for now, until all platforms are supported and tested):
1844#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001845#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001846#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1848 // TO NON-LINUX PLATFORMS:
1849 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001850#endif
1851#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001852 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1853 // that extension:
1854
1855 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001856 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1859 pass = (err != VK_SUCCESS);
1860 ASSERT_TRUE(pass);
1861 m_errorMonitor->VerifyFound();
1862
1863 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001864 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001865 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001866 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1867 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001868 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001869// Set this (for now, until all platforms are supported and tested):
1870#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001871#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001872
Ian Elliott12630812016-04-29 14:35:43 -06001873#if defined(VK_USE_PLATFORM_XLIB_KHR)
1874 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1875 // that extension:
1876
1877 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001878 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001880 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1881 pass = (err != VK_SUCCESS);
1882 ASSERT_TRUE(pass);
1883 m_errorMonitor->VerifyFound();
1884
1885 // Tell whether an Xlib VisualID supports presentation:
1886 Display *dpy = NULL;
1887 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001889 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1890 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001891// Set this (for now, until all platforms are supported and tested):
1892#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001893#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001894
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001895// Use the functions from the VK_KHR_surface extension without enabling
1896// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001897
Ian Elliott489eec02016-05-05 14:12:44 -06001898#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001899 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001900 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001901 vkDestroySurfaceKHR(instance(), surface, NULL);
1902 m_errorMonitor->VerifyFound();
1903
1904 // Check if surface supports presentation:
1905 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001906 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001907 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1908 pass = (err != VK_SUCCESS);
1909 ASSERT_TRUE(pass);
1910 m_errorMonitor->VerifyFound();
1911
1912 // Check surface capabilities:
1913 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1915 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001916 pass = (err != VK_SUCCESS);
1917 ASSERT_TRUE(pass);
1918 m_errorMonitor->VerifyFound();
1919
1920 // Check surface formats:
1921 uint32_t format_count = 0;
1922 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001923 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1924 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001925 pass = (err != VK_SUCCESS);
1926 ASSERT_TRUE(pass);
1927 m_errorMonitor->VerifyFound();
1928
1929 // Check surface present modes:
1930 uint32_t present_mode_count = 0;
1931 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001932 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1933 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 pass = (err != VK_SUCCESS);
1935 ASSERT_TRUE(pass);
1936 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001937#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001938
Ian Elliott1c32c772016-04-28 14:47:13 -06001939 // Use the functions from the VK_KHR_swapchain extension without enabling
1940 // that extension:
1941
1942 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1945 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001946 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001947 pass = (err != VK_SUCCESS);
1948 ASSERT_TRUE(pass);
1949 m_errorMonitor->VerifyFound();
1950
1951 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1953 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001954 pass = (err != VK_SUCCESS);
1955 ASSERT_TRUE(pass);
1956 m_errorMonitor->VerifyFound();
1957
Chris Forbeseb7d5502016-09-13 18:19:21 +12001958 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1959 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1960 VkFence fence;
1961 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1962
Ian Elliott1c32c772016-04-28 14:47:13 -06001963 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001964 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001965 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001966 pass = (err != VK_SUCCESS);
1967 ASSERT_TRUE(pass);
1968 m_errorMonitor->VerifyFound();
1969
Chris Forbeseb7d5502016-09-13 18:19:21 +12001970 vkDestroyFence(m_device->device(), fence, nullptr);
1971
Ian Elliott1c32c772016-04-28 14:47:13 -06001972 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001973 //
1974 // NOTE: Currently can't test this because a real swapchain is needed (as
1975 // opposed to the fake one we created) in order for the layer to lookup the
1976 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001977
1978 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001980 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1981 m_errorMonitor->VerifyFound();
1982}
Chris Forbes09368e42016-10-13 11:59:22 +13001983#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001984
Karl Schultz6addd812016-02-02 17:17:23 -07001985TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1986 VkResult err;
1987 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001989 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1990 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001991
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001993
1994 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001995 VkImage image;
1996 VkDeviceMemory mem;
1997 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001998
Karl Schultz6addd812016-02-02 17:17:23 -07001999 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2000 const int32_t tex_width = 32;
2001 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002002
Tony Barboureb254902015-07-15 12:50:33 -06002003 VkImageCreateInfo image_create_info = {};
2004 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002005 image_create_info.pNext = NULL;
2006 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2007 image_create_info.format = tex_format;
2008 image_create_info.extent.width = tex_width;
2009 image_create_info.extent.height = tex_height;
2010 image_create_info.extent.depth = 1;
2011 image_create_info.mipLevels = 1;
2012 image_create_info.arrayLayers = 1;
2013 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2014 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2015 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2016 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002017 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002018
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002019 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002020 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002021 mem_alloc.pNext = NULL;
2022 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002023
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002025 ASSERT_VK_SUCCESS(err);
2026
Karl Schultz6addd812016-02-02 17:17:23 -07002027 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028
Mark Lobodzinski23065352015-05-29 09:32:35 -05002029 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002031 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 -07002032 if (!pass) { // If we can't find any unmappable memory this test doesn't
2033 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002034 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002035 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002036 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002037
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002038 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002039 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002040 ASSERT_VK_SUCCESS(err);
2041
2042 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002043 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044 ASSERT_VK_SUCCESS(err);
2045
2046 // Map memory as if to initialize the image
2047 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002048 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002049
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002050 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002051
Chia-I Wuf7458c52015-10-26 21:10:41 +08002052 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002053 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002054}
2055
Karl Schultz6addd812016-02-02 17:17:23 -07002056TEST_F(VkLayerTest, RebindMemory) {
2057 VkResult err;
2058 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002060 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002061
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002062 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
2064 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002065 VkImage image;
2066 VkDeviceMemory mem1;
2067 VkDeviceMemory mem2;
2068 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002069
Karl Schultz6addd812016-02-02 17:17:23 -07002070 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2071 const int32_t tex_width = 32;
2072 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002073
Tony Barboureb254902015-07-15 12:50:33 -06002074 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002075 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2076 image_create_info.pNext = NULL;
2077 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2078 image_create_info.format = tex_format;
2079 image_create_info.extent.width = tex_width;
2080 image_create_info.extent.height = tex_height;
2081 image_create_info.extent.depth = 1;
2082 image_create_info.mipLevels = 1;
2083 image_create_info.arrayLayers = 1;
2084 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2085 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2086 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2087 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002088
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002089 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002090 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2091 mem_alloc.pNext = NULL;
2092 mem_alloc.allocationSize = 0;
2093 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002094
Karl Schultz6addd812016-02-02 17:17:23 -07002095 // Introduce failure, do NOT set memProps to
2096 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002097 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002098 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
2100
Karl Schultz6addd812016-02-02 17:17:23 -07002101 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002102
2103 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002104 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002105 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002106
2107 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002108 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002109 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002110 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002111 ASSERT_VK_SUCCESS(err);
2112
2113 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002114 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002115 ASSERT_VK_SUCCESS(err);
2116
Karl Schultz6addd812016-02-02 17:17:23 -07002117 // Introduce validation failure, try to bind a different memory object to
2118 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002119 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002120
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002121 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002122
Chia-I Wuf7458c52015-10-26 21:10:41 +08002123 vkDestroyImage(m_device->device(), image, NULL);
2124 vkFreeMemory(m_device->device(), mem1, NULL);
2125 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002126}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002127
Karl Schultz6addd812016-02-02 17:17:23 -07002128TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002129 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002130
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002131 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2132 "submitted in SIGNALED state. Fences "
2133 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002134
2135 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002136 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2137 fenceInfo.pNext = NULL;
2138 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002139
Tony Barbour300a6082015-04-07 13:44:53 -06002140 ASSERT_NO_FATAL_FAILURE(InitState());
2141 ASSERT_NO_FATAL_FAILURE(InitViewport());
2142 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2143
Tony Barbour552f6c02016-12-21 14:34:07 -07002144 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002145 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002146 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002147
2148 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002149
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002150 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002151 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2152 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002153 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002154 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002155 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002156 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002157 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002158 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002159 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002160
2161 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002162 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002163
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002164 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002165}
Chris Forbes4e44c912016-06-16 10:20:00 +12002166
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002167TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002168 TEST_DESCRIPTION(
2169 "Specify wrong usage for image then create conflicting view of image "
2170 "Initialize buffer with wrong usage then perform copy expecting errors "
2171 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002172 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002173
2174 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002175
Tony Barbourf887b162017-03-09 10:06:46 -07002176 auto format = find_depth_stencil_format(m_device);
2177 if (!format) {
2178 printf(" No Depth + Stencil format found. Skipped.\n");
2179 return;
2180 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002181
Tony Barbourf92621a2016-05-02 14:28:12 -06002182 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002183 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002184 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002185 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002186
Tony Barbourf92621a2016-05-02 14:28:12 -06002187 VkImageView dsv;
2188 VkImageViewCreateInfo dsvci = {};
2189 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2190 dsvci.image = image.handle();
2191 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002192 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002193 dsvci.subresourceRange.layerCount = 1;
2194 dsvci.subresourceRange.baseMipLevel = 0;
2195 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002196 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002197
Tony Barbourf92621a2016-05-02 14:28:12 -06002198 // Create a view with depth / stencil aspect for image with different usage
2199 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002200
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002201 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002202
2203 // Initialize buffer with TRANSFER_DST usage
2204 vk_testing::Buffer buffer;
2205 VkMemoryPropertyFlags reqs = 0;
2206 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2207 VkBufferImageCopy region = {};
2208 region.bufferRowLength = 128;
2209 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002210 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002211 region.imageSubresource.layerCount = 1;
2212 region.imageExtent.height = 16;
2213 region.imageExtent.width = 16;
2214 region.imageExtent.depth = 1;
2215
Mark Lobodzinski80871462017-02-16 10:37:27 -07002216 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002217 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002218
Chris Forbesda581202016-10-06 18:25:26 +13002219 // two separate errors from this call:
2220 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2221 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2222
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002223 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2224 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002225 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002226}
Tony Barbour75d79f02016-08-30 09:39:07 -06002227
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228TEST_F(VkLayerTest, LeakAnObject) {
2229 VkResult err;
2230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002232
2233 // Note that we have to create a new device since destroying the
2234 // framework's device causes Teardown() to fail and just calling Teardown
2235 // will destroy the errorMonitor.
2236
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002237 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002238
2239 ASSERT_NO_FATAL_FAILURE(InitState());
2240
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002241 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002242 std::vector<VkDeviceQueueCreateInfo> queue_info;
2243 queue_info.reserve(queue_props.size());
2244 std::vector<std::vector<float>> queue_priorities;
2245 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2246 VkDeviceQueueCreateInfo qi = {};
2247 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2248 qi.pNext = NULL;
2249 qi.queueFamilyIndex = i;
2250 qi.queueCount = queue_props[i].queueCount;
2251 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2252 qi.pQueuePriorities = queue_priorities[i].data();
2253 queue_info.push_back(qi);
2254 }
2255
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002256 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002257
2258 // The sacrificial device object
2259 VkDevice testDevice;
2260 VkDeviceCreateInfo device_create_info = {};
2261 auto features = m_device->phy().features();
2262 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2263 device_create_info.pNext = NULL;
2264 device_create_info.queueCreateInfoCount = queue_info.size();
2265 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002266 device_create_info.enabledLayerCount = 0;
2267 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002268 device_create_info.pEnabledFeatures = &features;
2269 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2270 ASSERT_VK_SUCCESS(err);
2271
2272 VkFence fence;
2273 VkFenceCreateInfo fence_create_info = {};
2274 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2275 fence_create_info.pNext = NULL;
2276 fence_create_info.flags = 0;
2277 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2278 ASSERT_VK_SUCCESS(err);
2279
2280 // Induce failure by not calling vkDestroyFence
2281 vkDestroyDevice(testDevice, NULL);
2282 m_errorMonitor->VerifyFound();
2283}
2284
2285TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002286 TEST_DESCRIPTION(
2287 "Allocate command buffers from one command pool and "
2288 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002289
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002291
Cody Northropc31a84f2016-08-22 10:41:47 -06002292 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002293 VkCommandPool command_pool_one;
2294 VkCommandPool command_pool_two;
2295
2296 VkCommandPoolCreateInfo pool_create_info{};
2297 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2298 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2299 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2300
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002301 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002302
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002303 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002304
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002305 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002306 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002307 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002308 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002309 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002310 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002311 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002312
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002313 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002314
2315 m_errorMonitor->VerifyFound();
2316
2317 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2318 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2319}
2320
2321TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2322 VkResult err;
2323
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002324 TEST_DESCRIPTION(
2325 "Allocate descriptor sets from one DS pool and "
2326 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002327
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002328 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002329
2330 ASSERT_NO_FATAL_FAILURE(InitState());
2331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2332
2333 VkDescriptorPoolSize ds_type_count = {};
2334 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2335 ds_type_count.descriptorCount = 1;
2336
2337 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2338 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2339 ds_pool_ci.pNext = NULL;
2340 ds_pool_ci.flags = 0;
2341 ds_pool_ci.maxSets = 1;
2342 ds_pool_ci.poolSizeCount = 1;
2343 ds_pool_ci.pPoolSizes = &ds_type_count;
2344
2345 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002346 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002347 ASSERT_VK_SUCCESS(err);
2348
2349 // Create a second descriptor pool
2350 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002351 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002352 ASSERT_VK_SUCCESS(err);
2353
2354 VkDescriptorSetLayoutBinding dsl_binding = {};
2355 dsl_binding.binding = 0;
2356 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2357 dsl_binding.descriptorCount = 1;
2358 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2359 dsl_binding.pImmutableSamplers = NULL;
2360
2361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2363 ds_layout_ci.pNext = NULL;
2364 ds_layout_ci.bindingCount = 1;
2365 ds_layout_ci.pBindings = &dsl_binding;
2366
2367 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002368 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002369 ASSERT_VK_SUCCESS(err);
2370
2371 VkDescriptorSet descriptorSet;
2372 VkDescriptorSetAllocateInfo alloc_info = {};
2373 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2374 alloc_info.descriptorSetCount = 1;
2375 alloc_info.descriptorPool = ds_pool_one;
2376 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002377 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002378 ASSERT_VK_SUCCESS(err);
2379
2380 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2381
2382 m_errorMonitor->VerifyFound();
2383
2384 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2385 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2386 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2387}
2388
2389TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002391
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002392 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002393
2394 ASSERT_NO_FATAL_FAILURE(InitState());
2395
2396 // Pass bogus handle into GetImageMemoryRequirements
2397 VkMemoryRequirements mem_reqs;
2398 uint64_t fakeImageHandle = 0xCADECADE;
2399 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2400
2401 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2402
2403 m_errorMonitor->VerifyFound();
2404}
2405
Mike Schuchardt17838902017-02-21 09:48:06 -07002406TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2407 TEST_DESCRIPTION(
2408 "Try to destroy a render pass object using a device other than the one it was created on. "
2409 "This should generate a distinct error from the invalid handle error.");
2410 // Create first device and renderpass
2411 ASSERT_NO_FATAL_FAILURE(InitState());
2412 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2413
2414 // Create second device
2415 float priorities[] = {1.0f};
2416 VkDeviceQueueCreateInfo queue_info{};
2417 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2418 queue_info.pNext = NULL;
2419 queue_info.flags = 0;
2420 queue_info.queueFamilyIndex = 0;
2421 queue_info.queueCount = 1;
2422 queue_info.pQueuePriorities = &priorities[0];
2423
2424 VkDeviceCreateInfo device_create_info = {};
2425 auto features = m_device->phy().features();
2426 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2427 device_create_info.pNext = NULL;
2428 device_create_info.queueCreateInfoCount = 1;
2429 device_create_info.pQueueCreateInfos = &queue_info;
2430 device_create_info.enabledLayerCount = 0;
2431 device_create_info.ppEnabledLayerNames = NULL;
2432 device_create_info.pEnabledFeatures = &features;
2433
2434 VkDevice second_device;
2435 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2436
2437 // Try to destroy the renderpass from the first device using the second device
2438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2439 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2440 m_errorMonitor->VerifyFound();
2441
2442 vkDestroyDevice(second_device, NULL);
2443}
2444
Karl Schultz6addd812016-02-02 17:17:23 -07002445TEST_F(VkLayerTest, PipelineNotBound) {
2446 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002447
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002448 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002449
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002451
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002452 ASSERT_NO_FATAL_FAILURE(InitState());
2453 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002454
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002455 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002456 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2457 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002458
2459 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002460 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2461 ds_pool_ci.pNext = NULL;
2462 ds_pool_ci.maxSets = 1;
2463 ds_pool_ci.poolSizeCount = 1;
2464 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002465
2466 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002467 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002468 ASSERT_VK_SUCCESS(err);
2469
2470 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002471 dsl_binding.binding = 0;
2472 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2473 dsl_binding.descriptorCount = 1;
2474 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2475 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002476
2477 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002478 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2479 ds_layout_ci.pNext = NULL;
2480 ds_layout_ci.bindingCount = 1;
2481 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002482
2483 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002484 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002485 ASSERT_VK_SUCCESS(err);
2486
2487 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002488 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002489 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002490 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002491 alloc_info.descriptorPool = ds_pool;
2492 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002493 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002494 ASSERT_VK_SUCCESS(err);
2495
2496 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002497 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2498 pipeline_layout_ci.pNext = NULL;
2499 pipeline_layout_ci.setLayoutCount = 1;
2500 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002501
2502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002504 ASSERT_VK_SUCCESS(err);
2505
Mark Youngad779052016-01-06 14:26:04 -07002506 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002507
Tony Barbour552f6c02016-12-21 14:34:07 -07002508 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002509 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002510
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002511 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002512
Chia-I Wuf7458c52015-10-26 21:10:41 +08002513 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2514 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2515 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002516}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002517
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002518TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2519 VkResult err;
2520
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002521 TEST_DESCRIPTION(
2522 "Test validation check for an invalid memory type index "
2523 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002524
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002525 ASSERT_NO_FATAL_FAILURE(InitState());
2526
2527 // Create an image, allocate memory, set a bad typeIndex and then try to
2528 // bind it
2529 VkImage image;
2530 VkDeviceMemory mem;
2531 VkMemoryRequirements mem_reqs;
2532 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2533 const int32_t tex_width = 32;
2534 const int32_t tex_height = 32;
2535
2536 VkImageCreateInfo image_create_info = {};
2537 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2538 image_create_info.pNext = NULL;
2539 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2540 image_create_info.format = tex_format;
2541 image_create_info.extent.width = tex_width;
2542 image_create_info.extent.height = tex_height;
2543 image_create_info.extent.depth = 1;
2544 image_create_info.mipLevels = 1;
2545 image_create_info.arrayLayers = 1;
2546 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2547 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2548 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2549 image_create_info.flags = 0;
2550
2551 VkMemoryAllocateInfo mem_alloc = {};
2552 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2553 mem_alloc.pNext = NULL;
2554 mem_alloc.allocationSize = 0;
2555 mem_alloc.memoryTypeIndex = 0;
2556
2557 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2558 ASSERT_VK_SUCCESS(err);
2559
2560 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2561 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002562
2563 // Introduce Failure, select invalid TypeIndex
2564 VkPhysicalDeviceMemoryProperties memory_info;
2565
2566 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2567 unsigned int i;
2568 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2569 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2570 mem_alloc.memoryTypeIndex = i;
2571 break;
2572 }
2573 }
2574 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002575 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002576 vkDestroyImage(m_device->device(), image, NULL);
2577 return;
2578 }
2579
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002580 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 -06002581
2582 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2583 ASSERT_VK_SUCCESS(err);
2584
2585 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2586 (void)err;
2587
2588 m_errorMonitor->VerifyFound();
2589
2590 vkDestroyImage(m_device->device(), image, NULL);
2591 vkFreeMemory(m_device->device(), mem, NULL);
2592}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002593
Karl Schultz6addd812016-02-02 17:17:23 -07002594TEST_F(VkLayerTest, BindInvalidMemory) {
2595 VkResult err;
2596 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002597
2598 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002599
Cortf801b982017-01-17 18:10:21 -08002600 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002601 const int32_t tex_width = 256;
2602 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002603
2604 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002605 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2606 image_create_info.pNext = NULL;
2607 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2608 image_create_info.format = tex_format;
2609 image_create_info.extent.width = tex_width;
2610 image_create_info.extent.height = tex_height;
2611 image_create_info.extent.depth = 1;
2612 image_create_info.mipLevels = 1;
2613 image_create_info.arrayLayers = 1;
2614 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002615 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002616 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2617 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002618
Cortf801b982017-01-17 18:10:21 -08002619 VkBufferCreateInfo buffer_create_info = {};
2620 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2621 buffer_create_info.pNext = NULL;
2622 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002623 buffer_create_info.size = 4 * 1024 * 1024;
2624 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002625 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002626
Cortf801b982017-01-17 18:10:21 -08002627 // Create an image/buffer, allocate memory, free it, and then try to bind it
2628 {
2629 VkImage image = VK_NULL_HANDLE;
2630 VkBuffer buffer = VK_NULL_HANDLE;
2631 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2632 ASSERT_VK_SUCCESS(err);
2633 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2634 ASSERT_VK_SUCCESS(err);
2635 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2636 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2637 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002638
Cortf801b982017-01-17 18:10:21 -08002639 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2640 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2641 image_mem_alloc.allocationSize = image_mem_reqs.size;
2642 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2643 ASSERT_TRUE(pass);
2644 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2645 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2646 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2647 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002648
Cortf801b982017-01-17 18:10:21 -08002649 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2650 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2651 ASSERT_VK_SUCCESS(err);
2652 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2653 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002654
Cortf801b982017-01-17 18:10:21 -08002655 vkFreeMemory(device(), image_mem, NULL);
2656 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002657
Cortf801b982017-01-17 18:10:21 -08002658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2659 err = vkBindImageMemory(device(), image, image_mem, 0);
2660 (void)err; // This may very well return an error.
2661 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002662
Cortf801b982017-01-17 18:10:21 -08002663 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2664 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2665 (void)err; // This may very well return an error.
2666 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002667
Cortf801b982017-01-17 18:10:21 -08002668 vkDestroyImage(m_device->device(), image, NULL);
2669 vkDestroyBuffer(m_device->device(), buffer, NULL);
2670 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002671
2672 // Try to bind memory to an object that already has a memory binding
2673 {
2674 VkImage image = VK_NULL_HANDLE;
2675 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2676 ASSERT_VK_SUCCESS(err);
2677 VkBuffer buffer = VK_NULL_HANDLE;
2678 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2679 ASSERT_VK_SUCCESS(err);
2680 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2681 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2682 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2683 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2684 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2685 image_alloc_info.allocationSize = image_mem_reqs.size;
2686 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2687 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2688 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2689 ASSERT_TRUE(pass);
2690 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2691 ASSERT_TRUE(pass);
2692 VkDeviceMemory image_mem, buffer_mem;
2693 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2694 ASSERT_VK_SUCCESS(err);
2695 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2696 ASSERT_VK_SUCCESS(err);
2697
2698 err = vkBindImageMemory(device(), image, image_mem, 0);
2699 ASSERT_VK_SUCCESS(err);
2700 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2701 err = vkBindImageMemory(device(), image, image_mem, 0);
2702 (void)err; // This may very well return an error.
2703 m_errorMonitor->VerifyFound();
2704
2705 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2706 ASSERT_VK_SUCCESS(err);
2707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2708 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2709 (void)err; // This may very well return an error.
2710 m_errorMonitor->VerifyFound();
2711
2712 vkFreeMemory(device(), image_mem, NULL);
2713 vkFreeMemory(device(), buffer_mem, NULL);
2714 vkDestroyImage(device(), image, NULL);
2715 vkDestroyBuffer(device(), buffer, NULL);
2716 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002717
Cort Strattonde748202017-02-17 12:50:01 -08002718 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002719 {
2720 VkImage image = VK_NULL_HANDLE;
2721 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2722 ASSERT_VK_SUCCESS(err);
2723 VkBuffer buffer = VK_NULL_HANDLE;
2724 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2725 ASSERT_VK_SUCCESS(err);
2726 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2727 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2728 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2729 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2730 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002731 // Leave some extra space for alignment wiggle room
2732 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002733 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002734 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002735 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2736 ASSERT_TRUE(pass);
2737 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2738 ASSERT_TRUE(pass);
2739 VkDeviceMemory image_mem, buffer_mem;
2740 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2741 ASSERT_VK_SUCCESS(err);
2742 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2743 ASSERT_VK_SUCCESS(err);
2744
Cort Strattonde748202017-02-17 12:50:01 -08002745 // Test unaligned memory offset
2746 {
2747 if (image_mem_reqs.alignment > 1) {
2748 VkDeviceSize image_offset = 1;
2749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2750 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2751 (void)err; // This may very well return an error.
2752 m_errorMonitor->VerifyFound();
2753 }
Cort6c7dff72017-01-27 18:34:50 -08002754
Cort Strattonde748202017-02-17 12:50:01 -08002755 if (buffer_mem_reqs.alignment > 1) {
2756 VkDeviceSize buffer_offset = 1;
2757 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2758 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2759 (void)err; // This may very well return an error.
2760 m_errorMonitor->VerifyFound();
2761 }
2762 }
2763
2764 // Test memory offsets outside the memory allocation
2765 {
2766 VkDeviceSize image_offset =
2767 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2769 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2770 (void)err; // This may very well return an error.
2771 m_errorMonitor->VerifyFound();
2772
2773 VkDeviceSize buffer_offset =
2774 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2776 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2777 (void)err; // This may very well return an error.
2778 m_errorMonitor->VerifyFound();
2779 }
2780
2781 // Test memory offsets within the memory allocation, but which leave too little memory for
2782 // the resource.
2783 {
2784 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2785 if (image_offset > 0) {
2786 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2787 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2788 (void)err; // This may very well return an error.
2789 m_errorMonitor->VerifyFound();
2790 }
2791
2792 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2793 if (buffer_offset > 0) {
2794 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2795 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2796 (void)err; // This may very well return an error.
2797 m_errorMonitor->VerifyFound();
2798 }
2799 }
Cort6c7dff72017-01-27 18:34:50 -08002800
2801 vkFreeMemory(device(), image_mem, NULL);
2802 vkFreeMemory(device(), buffer_mem, NULL);
2803 vkDestroyImage(device(), image, NULL);
2804 vkDestroyBuffer(device(), buffer, NULL);
2805 }
2806
Cort Stratton4c38bb52017-01-28 13:33:10 -08002807 // Try to bind memory to an object with an invalid memory type
2808 {
2809 VkImage image = VK_NULL_HANDLE;
2810 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2811 ASSERT_VK_SUCCESS(err);
2812 VkBuffer buffer = VK_NULL_HANDLE;
2813 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2814 ASSERT_VK_SUCCESS(err);
2815 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2816 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2817 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2818 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2819 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2820 image_alloc_info.allocationSize = image_mem_reqs.size;
2821 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2822 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002823 // Create a mask of available memory types *not* supported by these resources,
2824 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002825 VkPhysicalDeviceMemoryProperties memory_properties = {};
2826 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002827 VkDeviceMemory image_mem, buffer_mem;
2828
Cort Stratton4c38bb52017-01-28 13:33:10 -08002829 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002831 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2832 ASSERT_TRUE(pass);
2833 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2834 ASSERT_VK_SUCCESS(err);
2835 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2836 err = vkBindImageMemory(device(), image, image_mem, 0);
2837 (void)err; // This may very well return an error.
2838 m_errorMonitor->VerifyFound();
2839 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002840 }
2841
Cort Stratton4c38bb52017-01-28 13:33:10 -08002842 uint32_t buffer_unsupported_mem_type_bits =
2843 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002844 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002845 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2846 ASSERT_TRUE(pass);
2847 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2848 ASSERT_VK_SUCCESS(err);
2849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2850 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2851 (void)err; // This may very well return an error.
2852 m_errorMonitor->VerifyFound();
2853 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002854 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002855
Cort Stratton4c38bb52017-01-28 13:33:10 -08002856 vkDestroyImage(device(), image, NULL);
2857 vkDestroyBuffer(device(), buffer, NULL);
2858 }
2859
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002860 // Try to bind memory to an image created with sparse memory flags
2861 {
2862 VkImageCreateInfo sparse_image_create_info = image_create_info;
2863 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2864 VkImageFormatProperties image_format_properties = {};
2865 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2866 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2867 sparse_image_create_info.usage, sparse_image_create_info.flags,
2868 &image_format_properties);
2869 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2870 // most likely means sparse formats aren't supported here; skip this test.
2871 } else {
2872 ASSERT_VK_SUCCESS(err);
2873 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002874 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002875 return;
2876 } else {
2877 VkImage sparse_image = VK_NULL_HANDLE;
2878 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2879 ASSERT_VK_SUCCESS(err);
2880 VkMemoryRequirements sparse_mem_reqs = {};
2881 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2882 if (sparse_mem_reqs.memoryTypeBits != 0) {
2883 VkMemoryAllocateInfo sparse_mem_alloc = {};
2884 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2885 sparse_mem_alloc.pNext = NULL;
2886 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2887 sparse_mem_alloc.memoryTypeIndex = 0;
2888 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2889 ASSERT_TRUE(pass);
2890 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2891 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2892 ASSERT_VK_SUCCESS(err);
2893 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2894 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2895 // This may very well return an error.
2896 (void)err;
2897 m_errorMonitor->VerifyFound();
2898 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2899 }
2900 vkDestroyImage(m_device->device(), sparse_image, NULL);
2901 }
2902 }
2903 }
2904
2905 // Try to bind memory to a buffer created with sparse memory flags
2906 {
2907 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2908 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2909 if (!m_device->phy().features().sparseResidencyBuffer) {
2910 // most likely means sparse formats aren't supported here; skip this test.
2911 } else {
2912 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2913 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2914 ASSERT_VK_SUCCESS(err);
2915 VkMemoryRequirements sparse_mem_reqs = {};
2916 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2917 if (sparse_mem_reqs.memoryTypeBits != 0) {
2918 VkMemoryAllocateInfo sparse_mem_alloc = {};
2919 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2920 sparse_mem_alloc.pNext = NULL;
2921 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2922 sparse_mem_alloc.memoryTypeIndex = 0;
2923 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2924 ASSERT_TRUE(pass);
2925 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2926 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2927 ASSERT_VK_SUCCESS(err);
2928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2929 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2930 // This may very well return an error.
2931 (void)err;
2932 m_errorMonitor->VerifyFound();
2933 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2934 }
2935 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2936 }
2937 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002938}
2939
Karl Schultz6addd812016-02-02 17:17:23 -07002940TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2941 VkResult err;
2942 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002945
Tobin Ehlisec598302015-09-15 15:02:17 -06002946 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002947
Karl Schultz6addd812016-02-02 17:17:23 -07002948 // Create an image object, allocate memory, destroy the object and then try
2949 // to bind it
2950 VkImage image;
2951 VkDeviceMemory mem;
2952 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002953
Karl Schultz6addd812016-02-02 17:17:23 -07002954 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2955 const int32_t tex_width = 32;
2956 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002957
2958 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002959 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2960 image_create_info.pNext = NULL;
2961 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2962 image_create_info.format = tex_format;
2963 image_create_info.extent.width = tex_width;
2964 image_create_info.extent.height = tex_height;
2965 image_create_info.extent.depth = 1;
2966 image_create_info.mipLevels = 1;
2967 image_create_info.arrayLayers = 1;
2968 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2969 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2970 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2971 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002972
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002973 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002974 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2975 mem_alloc.pNext = NULL;
2976 mem_alloc.allocationSize = 0;
2977 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002978
Chia-I Wuf7458c52015-10-26 21:10:41 +08002979 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
Karl Schultz6addd812016-02-02 17:17:23 -07002982 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002983
2984 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002985 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002986 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002987
2988 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002989 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002990 ASSERT_VK_SUCCESS(err);
2991
2992 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002993 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002994 ASSERT_VK_SUCCESS(err);
2995
2996 // Now Try to bind memory to this destroyed object
2997 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2998 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002999 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06003000
Chris Forbes8f36a8a2016-04-07 13:21:07 +12003001 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06003002
Chia-I Wuf7458c52015-10-26 21:10:41 +08003003 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06003004}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06003005
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003006TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
3007 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
3008
3009 ASSERT_NO_FATAL_FAILURE(InitState());
3010 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3011
3012 VkVertexInputBindingDescription input_binding;
3013 memset(&input_binding, 0, sizeof(input_binding));
3014
3015 VkVertexInputAttributeDescription input_attribs;
3016 memset(&input_attribs, 0, sizeof(input_attribs));
3017
3018 // Pick a really bad format for this purpose and make sure it should fail
3019 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3020 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3021 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003022 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003023 return;
3024 }
3025
3026 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003027 char const *vsSource =
3028 "#version 450\n"
3029 "\n"
3030 "out gl_PerVertex {\n"
3031 " vec4 gl_Position;\n"
3032 "};\n"
3033 "void main(){\n"
3034 " gl_Position = vec4(1);\n"
3035 "}\n";
3036 char const *fsSource =
3037 "#version 450\n"
3038 "\n"
3039 "layout(location=0) out vec4 color;\n"
3040 "void main(){\n"
3041 " color = vec4(1);\n"
3042 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003043
3044 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3045 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3046 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3047
3048 VkPipelineObj pipe(m_device);
3049 pipe.AddColorAttachment();
3050 pipe.AddShader(&vs);
3051 pipe.AddShader(&fs);
3052
3053 pipe.AddVertexInputBindings(&input_binding, 1);
3054 pipe.AddVertexInputAttribs(&input_attribs, 1);
3055
3056 VkDescriptorSetObj descriptorSet(m_device);
3057 descriptorSet.AppendDummy();
3058 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3059
3060 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3061
3062 m_errorMonitor->VerifyFound();
3063}
3064
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003065TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003066 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3067 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003068
3069 VkMemoryPropertyFlags reqs = 0;
3070 VkImageCreateInfo image_create_info = {};
3071 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3072 image_create_info.pNext = NULL;
3073 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3074 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3075 image_create_info.extent.width = 256;
3076 image_create_info.extent.height = 256;
3077 image_create_info.extent.depth = 1;
3078 image_create_info.mipLevels = 1;
3079 image_create_info.arrayLayers = 1;
3080 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3081 image_create_info.flags = 0;
3082
3083 VkImageBlit blit_region = {};
3084 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3085 blit_region.srcSubresource.baseArrayLayer = 0;
3086 blit_region.srcSubresource.layerCount = 1;
3087 blit_region.srcSubresource.mipLevel = 0;
3088 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3089 blit_region.dstSubresource.baseArrayLayer = 0;
3090 blit_region.dstSubresource.layerCount = 1;
3091 blit_region.dstSubresource.mipLevel = 0;
3092
3093 // Create two images, the source with sampleCount = 2, and attempt to blit
3094 // between them
3095 {
3096 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003097 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003098 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003099 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003101 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003102 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003103 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003104 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003105 m_errorMonitor->SetDesiredFailureMsg(
3106 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3107 "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 -06003108 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3109 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003110 m_errorMonitor->VerifyFound();
3111 m_commandBuffer->EndCommandBuffer();
3112 }
3113
3114 // Create two images, the dest with sampleCount = 4, and attempt to blit
3115 // between them
3116 {
3117 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003118 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003119 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003120 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003121 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003122 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003123 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003124 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003125 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003126 m_errorMonitor->SetDesiredFailureMsg(
3127 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3128 "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 -06003129 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3130 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003131 m_errorMonitor->VerifyFound();
3132 m_commandBuffer->EndCommandBuffer();
3133 }
3134
3135 VkBufferImageCopy copy_region = {};
3136 copy_region.bufferRowLength = 128;
3137 copy_region.bufferImageHeight = 128;
3138 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3139 copy_region.imageSubresource.layerCount = 1;
3140 copy_region.imageExtent.height = 64;
3141 copy_region.imageExtent.width = 64;
3142 copy_region.imageExtent.depth = 1;
3143
3144 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3145 // buffer to image
3146 {
3147 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003148 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3149 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003150 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003151 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003152 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003153 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003154 m_errorMonitor->SetDesiredFailureMsg(
3155 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3156 "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 -06003157 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3158 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003159 m_errorMonitor->VerifyFound();
3160 m_commandBuffer->EndCommandBuffer();
3161 }
3162
3163 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3164 // image to buffer
3165 {
3166 vk_testing::Buffer dst_buffer;
3167 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3168 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003169 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003170 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003171 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003172 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003173 m_errorMonitor->SetDesiredFailureMsg(
3174 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3175 "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 -06003176 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003177 dst_buffer.handle(), 1, &copy_region);
3178 m_errorMonitor->VerifyFound();
3179 m_commandBuffer->EndCommandBuffer();
3180 }
3181}
3182
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003183TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003184 ASSERT_NO_FATAL_FAILURE(InitState());
3185
3186 VkImageObj src_image(m_device);
3187 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3188 VkImageObj dst_image(m_device);
3189 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3190 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003191 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 -06003192
3193 VkImageBlit blitRegion = {};
3194 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3195 blitRegion.srcSubresource.baseArrayLayer = 0;
3196 blitRegion.srcSubresource.layerCount = 1;
3197 blitRegion.srcSubresource.mipLevel = 0;
3198 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3199 blitRegion.dstSubresource.baseArrayLayer = 0;
3200 blitRegion.dstSubresource.layerCount = 1;
3201 blitRegion.dstSubresource.mipLevel = 0;
3202
Dave Houlton34df4cb2016-12-01 16:43:06 -07003203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3204
3205 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3206 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003207
3208 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003209 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003210 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3211 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
3213 m_errorMonitor->VerifyFound();
3214
Dave Houlton34df4cb2016-12-01 16:43:06 -07003215 // Test should generate 2 VU failures
3216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3217 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003218
3219 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003220 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3221 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003222
Dave Houlton34df4cb2016-12-01 16:43:06 -07003223 // TODO: Note that this only verifies that at least one of the VU enums was found
3224 // 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 -06003225 m_errorMonitor->VerifyFound();
3226
Tony Barbour552f6c02016-12-21 14:34:07 -07003227 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003228}
3229
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003230TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3231 VkResult err;
3232 bool pass;
3233
3234 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3235 ASSERT_NO_FATAL_FAILURE(InitState());
3236
3237 // If w/d/h granularity is 1, test is not meaningful
3238 // TODO: When virtual device limits are available, create a set of limits for this test that
3239 // will always have a granularity of > 1 for w, h, and d
3240 auto index = m_device->graphics_queue_node_index_;
3241 auto queue_family_properties = m_device->phy().queue_properties();
3242
3243 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3244 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3245 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3246 return;
3247 }
3248
3249 // Create two images of different types and try to copy between them
3250 VkImage srcImage;
3251 VkImage dstImage;
3252 VkDeviceMemory srcMem;
3253 VkDeviceMemory destMem;
3254 VkMemoryRequirements memReqs;
3255
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003256 VkImageCreateInfo image_create_info = {};
3257 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3258 image_create_info.pNext = NULL;
3259 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3260 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3261 image_create_info.extent.width = 32;
3262 image_create_info.extent.height = 32;
3263 image_create_info.extent.depth = 1;
3264 image_create_info.mipLevels = 1;
3265 image_create_info.arrayLayers = 4;
3266 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3267 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3268 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3269 image_create_info.flags = 0;
3270
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003271 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003272 ASSERT_VK_SUCCESS(err);
3273
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003274 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003275 ASSERT_VK_SUCCESS(err);
3276
3277 // Allocate memory
3278 VkMemoryAllocateInfo memAlloc = {};
3279 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3280 memAlloc.pNext = NULL;
3281 memAlloc.allocationSize = 0;
3282 memAlloc.memoryTypeIndex = 0;
3283
3284 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3285 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003286 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003287 ASSERT_TRUE(pass);
3288 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3289 ASSERT_VK_SUCCESS(err);
3290
3291 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3292 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003293 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003294 ASSERT_VK_SUCCESS(err);
3295 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3296 ASSERT_VK_SUCCESS(err);
3297
3298 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3299 ASSERT_VK_SUCCESS(err);
3300 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3301 ASSERT_VK_SUCCESS(err);
3302
Tony Barbour552f6c02016-12-21 14:34:07 -07003303 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003304 VkImageCopy copyRegion;
3305 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3306 copyRegion.srcSubresource.mipLevel = 0;
3307 copyRegion.srcSubresource.baseArrayLayer = 0;
3308 copyRegion.srcSubresource.layerCount = 1;
3309 copyRegion.srcOffset.x = 0;
3310 copyRegion.srcOffset.y = 0;
3311 copyRegion.srcOffset.z = 0;
3312 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3313 copyRegion.dstSubresource.mipLevel = 0;
3314 copyRegion.dstSubresource.baseArrayLayer = 0;
3315 copyRegion.dstSubresource.layerCount = 1;
3316 copyRegion.dstOffset.x = 0;
3317 copyRegion.dstOffset.y = 0;
3318 copyRegion.dstOffset.z = 0;
3319 copyRegion.extent.width = 1;
3320 copyRegion.extent.height = 1;
3321 copyRegion.extent.depth = 1;
3322
3323 // Introduce failure by setting srcOffset to a bad granularity value
3324 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3326 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003327 m_errorMonitor->VerifyFound();
3328
3329 // Introduce failure by setting extent to a bad granularity value
3330 copyRegion.srcOffset.y = 0;
3331 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003332 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3333 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003334 m_errorMonitor->VerifyFound();
3335
3336 // Now do some buffer/image copies
3337 vk_testing::Buffer buffer;
3338 VkMemoryPropertyFlags reqs = 0;
3339 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3340 VkBufferImageCopy region = {};
3341 region.bufferOffset = 0;
3342 region.bufferRowLength = 3;
3343 region.bufferImageHeight = 128;
3344 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3345 region.imageSubresource.layerCount = 1;
3346 region.imageExtent.height = 16;
3347 region.imageExtent.width = 16;
3348 region.imageExtent.depth = 1;
3349 region.imageOffset.x = 0;
3350 region.imageOffset.y = 0;
3351 region.imageOffset.z = 0;
3352
3353 // Introduce failure by setting bufferRowLength to a bad granularity value
3354 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3356 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3357 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003358 m_errorMonitor->VerifyFound();
3359 region.bufferRowLength = 128;
3360
3361 // Introduce failure by setting bufferOffset to a bad granularity value
3362 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003363 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3364 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3365 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003366 m_errorMonitor->VerifyFound();
3367 region.bufferOffset = 0;
3368
3369 // Introduce failure by setting bufferImageHeight to a bad granularity value
3370 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3372 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3373 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003374 m_errorMonitor->VerifyFound();
3375 region.bufferImageHeight = 128;
3376
3377 // Introduce failure by setting imageExtent to a bad granularity value
3378 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3380 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3381 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003382 m_errorMonitor->VerifyFound();
3383 region.imageExtent.width = 16;
3384
3385 // Introduce failure by setting imageOffset to a bad granularity value
3386 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3388 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3389 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003390 m_errorMonitor->VerifyFound();
3391
Tony Barbour552f6c02016-12-21 14:34:07 -07003392 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003393
3394 vkDestroyImage(m_device->device(), srcImage, NULL);
3395 vkDestroyImage(m_device->device(), dstImage, NULL);
3396 vkFreeMemory(m_device->device(), srcMem, NULL);
3397 vkFreeMemory(m_device->device(), destMem, NULL);
3398}
3399
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003400TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003401 TEST_DESCRIPTION(
3402 "Submit command buffer created using one queue family and "
3403 "attempt to submit them on a queue created in a different "
3404 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003405
Cody Northropc31a84f2016-08-22 10:41:47 -06003406 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003407
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003408 // This test is meaningless unless we have multiple queue families
3409 auto queue_family_properties = m_device->phy().queue_properties();
3410 if (queue_family_properties.size() < 2) {
3411 return;
3412 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003413 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003414 // Get safe index of another queue family
3415 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3416 ASSERT_NO_FATAL_FAILURE(InitState());
3417 // Create a second queue using a different queue family
3418 VkQueue other_queue;
3419 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3420
3421 // Record an empty cmd buffer
3422 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3423 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3424 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3425 vkEndCommandBuffer(m_commandBuffer->handle());
3426
3427 // And submit on the wrong queue
3428 VkSubmitInfo submit_info = {};
3429 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3430 submit_info.commandBufferCount = 1;
3431 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003432 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003433
3434 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003435}
3436
Chris Forbes4c24a922016-11-16 08:59:10 +13003437TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3438 ASSERT_NO_FATAL_FAILURE(InitState());
3439
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003440 // There are no attachments, but refer to attachment 0.
3441 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003442 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003443 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003444 };
3445
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003446 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003447 VkRenderPass rp;
3448
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003449 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003450 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003451 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3452 m_errorMonitor->VerifyFound();
3453}
3454
Chris Forbesa58c4522016-09-28 15:19:39 +13003455TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3456 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3457 ASSERT_NO_FATAL_FAILURE(InitState());
3458
3459 // A renderpass with two subpasses, both writing the same attachment.
3460 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003461 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3462 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3463 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003464 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003465 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003466 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003467 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3468 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003469 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003470 VkSubpassDependency dep = {0,
3471 1,
3472 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3473 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3474 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3475 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3476 VK_DEPENDENCY_BY_REGION_BIT};
3477 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003478 VkRenderPass rp;
3479 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3480 ASSERT_VK_SUCCESS(err);
3481
3482 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003483 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 +13003484 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3485
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003486 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003487 VkFramebuffer fb;
3488 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3489 ASSERT_VK_SUCCESS(err);
3490
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003491 char const *vsSource =
3492 "#version 450\n"
3493 "void main() { gl_Position = vec4(1); }\n";
3494 char const *fsSource =
3495 "#version 450\n"
3496 "layout(location=0) out vec4 color;\n"
3497 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003498
3499 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3500 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3501 VkPipelineObj pipe(m_device);
3502 pipe.AddColorAttachment();
3503 pipe.AddShader(&vs);
3504 pipe.AddShader(&fs);
3505 VkViewport view_port = {};
3506 m_viewports.push_back(view_port);
3507 pipe.SetViewport(m_viewports);
3508 VkRect2D rect = {};
3509 m_scissors.push_back(rect);
3510 pipe.SetScissor(m_scissors);
3511
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003512 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003513 VkPipelineLayout pl;
3514 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3515 ASSERT_VK_SUCCESS(err);
3516 pipe.CreateVKPipeline(pl, rp);
3517
Tony Barbour552f6c02016-12-21 14:34:07 -07003518 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003519
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003520 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3521 nullptr,
3522 rp,
3523 fb,
3524 {{
3525 0, 0,
3526 },
3527 {32, 32}},
3528 0,
3529 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003530
3531 // subtest 1: bind in the wrong subpass
3532 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3533 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003534 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 +13003535 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3536 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3537 m_errorMonitor->VerifyFound();
3538
3539 vkCmdEndRenderPass(m_commandBuffer->handle());
3540
3541 // subtest 2: bind in correct subpass, then transition to next subpass
3542 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3543 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3544 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003545 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 +13003546 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3547 m_errorMonitor->VerifyFound();
3548
3549 vkCmdEndRenderPass(m_commandBuffer->handle());
3550
Tony Barbour552f6c02016-12-21 14:34:07 -07003551 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003552
3553 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3554 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3555 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3556}
3557
Tony Barbour4e919972016-08-09 13:27:40 -06003558TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003559 TEST_DESCRIPTION(
3560 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3561 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003562 ASSERT_NO_FATAL_FAILURE(InitState());
3563 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3564
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3566 "Cannot execute a render pass with renderArea "
3567 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003568
3569 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3570 m_renderPassBeginInfo.renderArea.extent.width = 257;
3571 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003572 m_commandBuffer->BeginCommandBuffer();
3573 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003574 m_errorMonitor->VerifyFound();
3575}
3576
3577TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003578 TEST_DESCRIPTION(
3579 "Generate INDEPENDENT_BLEND by disabling independent "
3580 "blend and then specifying different blend states for two "
3581 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003582 VkPhysicalDeviceFeatures features = {};
3583 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003585
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3587 "Invalid Pipeline CreateInfo: If independent blend feature not "
3588 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003589
Cody Northropc31a84f2016-08-22 10:41:47 -06003590 VkDescriptorSetObj descriptorSet(m_device);
3591 descriptorSet.AppendDummy();
3592 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003593
Cody Northropc31a84f2016-08-22 10:41:47 -06003594 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003595 // Create a renderPass with two color attachments
3596 VkAttachmentReference attachments[2] = {};
3597 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003598 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003599 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3600
3601 VkSubpassDescription subpass = {};
3602 subpass.pColorAttachments = attachments;
3603 subpass.colorAttachmentCount = 2;
3604
3605 VkRenderPassCreateInfo rpci = {};
3606 rpci.subpassCount = 1;
3607 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003608 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609
Tony Barbourffd60bd2017-03-09 12:04:55 -07003610 VkAttachmentDescription attach_desc[2] = {};
3611 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3612 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3613 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3614 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3615 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3616 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3617 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3618 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003619
Tony Barbourffd60bd2017-03-09 12:04:55 -07003620 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003621 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3622
3623 VkRenderPass renderpass;
3624 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003625 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003626 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003627
Cody Northropc31a84f2016-08-22 10:41:47 -06003628 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3629 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3630 att_state1.blendEnable = VK_TRUE;
3631 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3632 att_state2.blendEnable = VK_FALSE;
3633 pipeline.AddColorAttachment(0, &att_state1);
3634 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003635 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003636 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003637 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003638}
3639
Mike Weiblen40b160e2017-02-06 19:21:52 -07003640// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3641TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3642 TEST_DESCRIPTION(
3643 "Create a graphics pipeline that is incompatible with the requirements "
3644 "of its contained Renderpass/subpasses.");
3645 ASSERT_NO_FATAL_FAILURE(InitState());
3646
3647 VkDescriptorSetObj ds_obj(m_device);
3648 ds_obj.AppendDummy();
3649 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3650
3651 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3652
3653 VkPipelineColorBlendAttachmentState att_state1 = {};
3654 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3655 att_state1.blendEnable = VK_TRUE;
3656
3657 VkRenderpassObj rp_obj(m_device);
3658
3659 {
3660 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3661 VkPipelineObj pipeline(m_device);
3662 pipeline.AddShader(&vs_obj);
3663 pipeline.AddColorAttachment(0, &att_state1);
3664
3665 VkGraphicsPipelineCreateInfo info = {};
3666 pipeline.InitGraphicsPipelineCreateInfo(&info);
3667 info.pColorBlendState = nullptr;
3668
3669 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3670 m_errorMonitor->VerifyFound();
3671 }
3672}
3673
Chris Forbes26ec2122016-11-29 08:58:33 +13003674#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003675TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3676 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3677 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003678 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003679
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3681 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003682
3683 // Create a renderPass with a single color attachment
3684 VkAttachmentReference attach = {};
3685 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3686 VkSubpassDescription subpass = {};
3687 VkRenderPassCreateInfo rpci = {};
3688 rpci.subpassCount = 1;
3689 rpci.pSubpasses = &subpass;
3690 rpci.attachmentCount = 1;
3691 VkAttachmentDescription attach_desc = {};
3692 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3693 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3694 rpci.pAttachments = &attach_desc;
3695 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3696 VkRenderPass rp;
3697 subpass.pDepthStencilAttachment = &attach;
3698 subpass.pColorAttachments = NULL;
3699 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3700 m_errorMonitor->VerifyFound();
3701}
Chris Forbes26ec2122016-11-29 08:58:33 +13003702#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003703
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003704TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003705 TEST_DESCRIPTION(
3706 "Create a framebuffer where a subpass has a preserve "
3707 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003708
3709 ASSERT_NO_FATAL_FAILURE(InitState());
3710 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3711
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003712 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003713
3714 VkAttachmentReference color_attach = {};
3715 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3716 color_attach.attachment = 0;
3717 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3718 VkSubpassDescription subpass = {};
3719 subpass.colorAttachmentCount = 1;
3720 subpass.pColorAttachments = &color_attach;
3721 subpass.preserveAttachmentCount = 1;
3722 subpass.pPreserveAttachments = &preserve_attachment;
3723
3724 VkRenderPassCreateInfo rpci = {};
3725 rpci.subpassCount = 1;
3726 rpci.pSubpasses = &subpass;
3727 rpci.attachmentCount = 1;
3728 VkAttachmentDescription attach_desc = {};
3729 attach_desc.format = VK_FORMAT_UNDEFINED;
3730 rpci.pAttachments = &attach_desc;
3731 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3732 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003733 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003734
3735 m_errorMonitor->VerifyFound();
3736
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003737 if (result == VK_SUCCESS) {
3738 vkDestroyRenderPass(m_device->device(), rp, NULL);
3739 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003740}
3741
Chris Forbesc5389742016-06-29 11:49:23 +12003742TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003743 TEST_DESCRIPTION(
3744 "Ensure that CreateRenderPass produces a validation error "
3745 "when the source of a subpass multisample resolve "
3746 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003747
Chris Forbesc5389742016-06-29 11:49:23 +12003748 ASSERT_NO_FATAL_FAILURE(InitState());
3749
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003750 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3751 "Subpass 0 requests multisample resolve from attachment 0 which has "
3752 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003753
3754 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003755 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3756 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3757 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3758 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3759 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3760 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003761 };
3762
3763 VkAttachmentReference color = {
3764 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3765 };
3766
3767 VkAttachmentReference resolve = {
3768 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3769 };
3770
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003771 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003772
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003773 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003774
3775 VkRenderPass rp;
3776 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3777
3778 m_errorMonitor->VerifyFound();
3779
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003780 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003781}
3782
3783TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003784 TEST_DESCRIPTION(
3785 "Ensure CreateRenderPass produces a validation error "
3786 "when a subpass multisample resolve operation is "
3787 "requested, and the destination of that resolve has "
3788 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003789
Chris Forbesc5389742016-06-29 11:49:23 +12003790 ASSERT_NO_FATAL_FAILURE(InitState());
3791
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003792 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3793 "Subpass 0 requests multisample resolve into attachment 1, which "
3794 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003795
3796 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003797 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3798 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3799 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3800 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3801 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3802 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003803 };
3804
3805 VkAttachmentReference color = {
3806 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3807 };
3808
3809 VkAttachmentReference resolve = {
3810 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3811 };
3812
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003813 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003814
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003815 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003816
3817 VkRenderPass rp;
3818 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3819
3820 m_errorMonitor->VerifyFound();
3821
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003822 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003823}
3824
Chris Forbes3f128ef2016-06-29 14:58:53 +12003825TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003826 TEST_DESCRIPTION(
3827 "Ensure CreateRenderPass produces a validation error "
3828 "when the color and depth attachments used by a subpass "
3829 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003830
Chris Forbes3f128ef2016-06-29 14:58:53 +12003831 ASSERT_NO_FATAL_FAILURE(InitState());
3832
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3834 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003835
3836 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003837 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3838 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3839 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3840 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3841 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3842 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003843 };
3844
3845 VkAttachmentReference color[] = {
3846 {
3847 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3848 },
3849 {
3850 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3851 },
3852 };
3853
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003854 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003855
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003856 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003857
3858 VkRenderPass rp;
3859 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3860
3861 m_errorMonitor->VerifyFound();
3862
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003863 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003864}
3865
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003866TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003867 TEST_DESCRIPTION(
3868 "Hit errors when attempting to create a framebuffer :\n"
3869 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3870 " 2. Use a color image as depthStencil attachment\n"
3871 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3872 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3873 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3874 " 6. Framebuffer attachment where dimensions don't match\n"
3875 " 7. Framebuffer attachment w/o identity swizzle\n"
3876 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003877
3878 ASSERT_NO_FATAL_FAILURE(InitState());
3879 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3880
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003881 m_errorMonitor->SetDesiredFailureMsg(
3882 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3883 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003884
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003885 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003886 VkAttachmentReference attach = {};
3887 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3888 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003889 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003890 VkRenderPassCreateInfo rpci = {};
3891 rpci.subpassCount = 1;
3892 rpci.pSubpasses = &subpass;
3893 rpci.attachmentCount = 1;
3894 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003895 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003896 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003897 rpci.pAttachments = &attach_desc;
3898 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3899 VkRenderPass rp;
3900 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3901 ASSERT_VK_SUCCESS(err);
3902
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003903 VkImageView ivs[2];
3904 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3905 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003906 VkFramebufferCreateInfo fb_info = {};
3907 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3908 fb_info.pNext = NULL;
3909 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003910 // Set mis-matching attachmentCount
3911 fb_info.attachmentCount = 2;
3912 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003913 fb_info.width = 100;
3914 fb_info.height = 100;
3915 fb_info.layers = 1;
3916
3917 VkFramebuffer fb;
3918 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3919
3920 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003921 if (err == VK_SUCCESS) {
3922 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3923 }
3924 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003925
3926 // Create a renderPass with a depth-stencil attachment created with
3927 // IMAGE_USAGE_COLOR_ATTACHMENT
3928 // Add our color attachment to pDepthStencilAttachment
3929 subpass.pDepthStencilAttachment = &attach;
3930 subpass.pColorAttachments = NULL;
3931 VkRenderPass rp_ds;
3932 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3933 ASSERT_VK_SUCCESS(err);
3934 // Set correct attachment count, but attachment has COLOR usage bit set
3935 fb_info.attachmentCount = 1;
3936 fb_info.renderPass = rp_ds;
3937
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003939 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3940
3941 m_errorMonitor->VerifyFound();
3942 if (err == VK_SUCCESS) {
3943 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3944 }
3945 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003946
3947 // Create new renderpass with alternate attachment format from fb
3948 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3949 subpass.pDepthStencilAttachment = NULL;
3950 subpass.pColorAttachments = &attach;
3951 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3952 ASSERT_VK_SUCCESS(err);
3953
3954 // Cause error due to mis-matched formats between rp & fb
3955 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3956 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3958 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003959 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3960
3961 m_errorMonitor->VerifyFound();
3962 if (err == VK_SUCCESS) {
3963 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3964 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003965 vkDestroyRenderPass(m_device->device(), rp, NULL);
3966
3967 // Create new renderpass with alternate sample count from fb
3968 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3969 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3970 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3971 ASSERT_VK_SUCCESS(err);
3972
3973 // Cause error due to mis-matched sample count between rp & fb
3974 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003976 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003977 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3978
3979 m_errorMonitor->VerifyFound();
3980 if (err == VK_SUCCESS) {
3981 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3982 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003983
3984 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003985
3986 // Create a custom imageView with non-1 mip levels
3987 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003988 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 -06003989 ASSERT_TRUE(image.initialized());
3990
3991 VkImageView view;
3992 VkImageViewCreateInfo ivci = {};
3993 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3994 ivci.image = image.handle();
3995 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3996 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3997 ivci.subresourceRange.layerCount = 1;
3998 ivci.subresourceRange.baseMipLevel = 0;
3999 // Set level count 2 (only 1 is allowed for FB attachment)
4000 ivci.subresourceRange.levelCount = 2;
4001 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4002 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4003 ASSERT_VK_SUCCESS(err);
4004 // Re-create renderpass to have matching sample count
4005 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
4006 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
4007 ASSERT_VK_SUCCESS(err);
4008
4009 fb_info.renderPass = rp;
4010 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004012 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4013
4014 m_errorMonitor->VerifyFound();
4015 if (err == VK_SUCCESS) {
4016 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4017 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004018 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004019 // Update view to original color buffer and grow FB dimensions too big
4020 fb_info.pAttachments = ivs;
4021 fb_info.height = 1024;
4022 fb_info.width = 1024;
4023 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004025 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4026
4027 m_errorMonitor->VerifyFound();
4028 if (err == VK_SUCCESS) {
4029 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4030 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004031 // Create view attachment with non-identity swizzle
4032 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4033 ivci.image = image.handle();
4034 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4035 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4036 ivci.subresourceRange.layerCount = 1;
4037 ivci.subresourceRange.baseMipLevel = 0;
4038 ivci.subresourceRange.levelCount = 1;
4039 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4040 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4041 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4042 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4043 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4044 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4045 ASSERT_VK_SUCCESS(err);
4046
4047 fb_info.pAttachments = &view;
4048 fb_info.height = 100;
4049 fb_info.width = 100;
4050 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004051 m_errorMonitor->SetDesiredFailureMsg(
4052 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4053 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004054 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4055
4056 m_errorMonitor->VerifyFound();
4057 if (err == VK_SUCCESS) {
4058 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4059 }
4060 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004061 // reset attachment to color attachment
4062 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004063
4064 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004065 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004066 fb_info.height = 100;
4067 fb_info.layers = 1;
4068 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004069 m_errorMonitor->SetDesiredFailureMsg(
4070 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004071 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4072 "Here are the respective dimensions for attachment");
4073
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4075
4076 m_errorMonitor->VerifyFound();
4077 if (err == VK_SUCCESS) {
4078 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4079 }
4080
4081 // Request fb that exceeds max height
4082 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004083 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004084 fb_info.layers = 1;
4085 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004086 m_errorMonitor->SetDesiredFailureMsg(
4087 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004088 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4089 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004090 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4091
4092 m_errorMonitor->VerifyFound();
4093 if (err == VK_SUCCESS) {
4094 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4095 }
4096
4097 // Request fb that exceeds max layers
4098 fb_info.width = 100;
4099 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004100 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004101 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004102 m_errorMonitor->SetDesiredFailureMsg(
4103 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004104 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4105 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004106 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4107
4108 m_errorMonitor->VerifyFound();
4109 if (err == VK_SUCCESS) {
4110 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4111 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004112
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004113 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004114}
4115
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004116TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004117 TEST_DESCRIPTION(
4118 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4119 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004120
Cody Northropc31a84f2016-08-22 10:41:47 -06004121 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004122 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004123 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4124 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004125 m_errorMonitor->VerifyFound();
4126}
4127
4128TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004129 TEST_DESCRIPTION(
4130 "Run a simple draw calls to validate failure when Line Width dynamic "
4131 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004132
Cody Northropc31a84f2016-08-22 10:41:47 -06004133 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004134 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004135 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4136 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004137 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004138}
4139
4140TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004141 TEST_DESCRIPTION(
4142 "Run a simple draw calls to validate failure when Viewport dynamic "
4143 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004144
Cody Northropc31a84f2016-08-22 10:41:47 -06004145 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004146 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004147 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4148 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004149 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004150 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004151}
4152
4153TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004154 TEST_DESCRIPTION(
4155 "Run a simple draw calls to validate failure when Scissor dynamic "
4156 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004157
Cody Northropc31a84f2016-08-22 10:41:47 -06004158 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004159 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004160 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4161 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004162 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004163 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004164}
4165
Cortd713fe82016-07-27 09:51:27 -07004166TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004167 TEST_DESCRIPTION(
4168 "Run a simple draw calls to validate failure when Blend Constants "
4169 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004170
4171 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004172 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004173 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4174 "Dynamic blend constants state not set for this command buffer");
4175 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004176 m_errorMonitor->VerifyFound();
4177}
4178
4179TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004180 TEST_DESCRIPTION(
4181 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4182 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004183
4184 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004185 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004186 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004187 return;
4188 }
4189 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4191 "Dynamic depth bounds state not set for this command buffer");
4192 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004193 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004194}
4195
4196TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004197 TEST_DESCRIPTION(
4198 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4199 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004200
4201 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004202 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4204 "Dynamic stencil read mask state not set for this command buffer");
4205 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004206 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004207}
4208
4209TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004210 TEST_DESCRIPTION(
4211 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4212 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004213
4214 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004215 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004216 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4217 "Dynamic stencil write mask state not set for this command buffer");
4218 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004219 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004220}
4221
4222TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004223 TEST_DESCRIPTION(
4224 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4225 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004226
4227 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004228 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4230 "Dynamic stencil reference state not set for this command buffer");
4231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004232 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004233}
4234
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004235TEST_F(VkLayerTest, IndexBufferNotBound) {
4236 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004237
4238 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004239 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4240 "Index buffer object not bound to this command buffer when Indexed ");
4241 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004242 m_errorMonitor->VerifyFound();
4243}
4244
Karl Schultz6addd812016-02-02 17:17:23 -07004245TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004246 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4247 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4248 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004249
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004250 ASSERT_NO_FATAL_FAILURE(InitState());
4251 ASSERT_NO_FATAL_FAILURE(InitViewport());
4252 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4253
Karl Schultz6addd812016-02-02 17:17:23 -07004254 // We luck out b/c by default the framework creates CB w/ the
4255 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004256 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004257 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004258 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004259
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004260 // Bypass framework since it does the waits automatically
4261 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004262 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004263 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4264 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004265 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004266 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004267 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004268 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004269 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004270 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004271 submit_info.pSignalSemaphores = NULL;
4272
Chris Forbes40028e22016-06-13 09:59:34 +12004273 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004274 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004275 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004276
Karl Schultz6addd812016-02-02 17:17:23 -07004277 // Cause validation error by re-submitting cmd buffer that should only be
4278 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004279 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004280 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004281
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004282 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004283}
4284
Karl Schultz6addd812016-02-02 17:17:23 -07004285TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004286 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004287 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004288
4289 ASSERT_NO_FATAL_FAILURE(InitState());
4290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004291
Karl Schultz6addd812016-02-02 17:17:23 -07004292 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4293 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004295 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004296 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004297
4298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4300 ds_pool_ci.pNext = NULL;
4301 ds_pool_ci.flags = 0;
4302 ds_pool_ci.maxSets = 1;
4303 ds_pool_ci.poolSizeCount = 1;
4304 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004305
4306 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004307 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004308 ASSERT_VK_SUCCESS(err);
4309
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004310 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4311 dsl_binding_samp.binding = 0;
4312 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4313 dsl_binding_samp.descriptorCount = 1;
4314 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4315 dsl_binding_samp.pImmutableSamplers = NULL;
4316
4317 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4318 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4319 ds_layout_ci.pNext = NULL;
4320 ds_layout_ci.bindingCount = 1;
4321 ds_layout_ci.pBindings = &dsl_binding_samp;
4322
4323 VkDescriptorSetLayout ds_layout_samp;
4324 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4325 ASSERT_VK_SUCCESS(err);
4326
4327 // Try to allocate 2 sets when pool only has 1 set
4328 VkDescriptorSet descriptor_sets[2];
4329 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4330 VkDescriptorSetAllocateInfo alloc_info = {};
4331 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4332 alloc_info.descriptorSetCount = 2;
4333 alloc_info.descriptorPool = ds_pool;
4334 alloc_info.pSetLayouts = set_layouts;
4335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4336 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4337 m_errorMonitor->VerifyFound();
4338
4339 alloc_info.descriptorSetCount = 1;
4340 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004341 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004342 dsl_binding.binding = 0;
4343 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4344 dsl_binding.descriptorCount = 1;
4345 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4346 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004347
Karl Schultz6addd812016-02-02 17:17:23 -07004348 ds_layout_ci.bindingCount = 1;
4349 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004350
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004351 VkDescriptorSetLayout ds_layout_ub;
4352 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004353 ASSERT_VK_SUCCESS(err);
4354
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004355 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004356 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004357 alloc_info.pSetLayouts = &ds_layout_ub;
4358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4359 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004360
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004361 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004362
Karl Schultz2825ab92016-12-02 08:23:14 -07004363 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004366}
4367
Karl Schultz6addd812016-02-02 17:17:23 -07004368TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4369 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004370
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004371 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004372
Tobin Ehlise735c692015-10-08 13:13:50 -06004373 ASSERT_NO_FATAL_FAILURE(InitState());
4374 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004375
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004376 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004377 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4378 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004379
4380 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004381 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4382 ds_pool_ci.pNext = NULL;
4383 ds_pool_ci.maxSets = 1;
4384 ds_pool_ci.poolSizeCount = 1;
4385 ds_pool_ci.flags = 0;
4386 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4387 // app can only call vkResetDescriptorPool on this pool.;
4388 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004389
4390 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004391 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004392 ASSERT_VK_SUCCESS(err);
4393
4394 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004395 dsl_binding.binding = 0;
4396 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4397 dsl_binding.descriptorCount = 1;
4398 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4399 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004400
4401 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004402 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4403 ds_layout_ci.pNext = NULL;
4404 ds_layout_ci.bindingCount = 1;
4405 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004406
4407 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004408 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004409 ASSERT_VK_SUCCESS(err);
4410
4411 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004412 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004413 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004414 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004415 alloc_info.descriptorPool = ds_pool;
4416 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004417 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004418 ASSERT_VK_SUCCESS(err);
4419
4420 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004421 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004422
Chia-I Wuf7458c52015-10-26 21:10:41 +08004423 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4424 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004425}
4426
Karl Schultz6addd812016-02-02 17:17:23 -07004427TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004428 // Attempt to clear Descriptor Pool with bad object.
4429 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004430
4431 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004433 uint64_t fake_pool_handle = 0xbaad6001;
4434 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4435 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004436 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004437}
4438
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004439TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004440 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4441 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004442 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004443 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004444
4445 uint64_t fake_set_handle = 0xbaad6001;
4446 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004447 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004449
4450 ASSERT_NO_FATAL_FAILURE(InitState());
4451
4452 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4453 layout_bindings[0].binding = 0;
4454 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4455 layout_bindings[0].descriptorCount = 1;
4456 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4457 layout_bindings[0].pImmutableSamplers = NULL;
4458
4459 VkDescriptorSetLayout descriptor_set_layout;
4460 VkDescriptorSetLayoutCreateInfo dslci = {};
4461 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4462 dslci.pNext = NULL;
4463 dslci.bindingCount = 1;
4464 dslci.pBindings = layout_bindings;
4465 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004466 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004467
4468 VkPipelineLayout pipeline_layout;
4469 VkPipelineLayoutCreateInfo plci = {};
4470 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4471 plci.pNext = NULL;
4472 plci.setLayoutCount = 1;
4473 plci.pSetLayouts = &descriptor_set_layout;
4474 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004475 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004476
Tony Barbour552f6c02016-12-21 14:34:07 -07004477 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004478 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4479 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004480 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004481 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004482 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4483 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004484}
4485
Karl Schultz6addd812016-02-02 17:17:23 -07004486TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004487 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4488 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004489 uint64_t fake_layout_handle = 0xbaad6001;
4490 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004491 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004492 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004493 VkPipelineLayout pipeline_layout;
4494 VkPipelineLayoutCreateInfo plci = {};
4495 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4496 plci.pNext = NULL;
4497 plci.setLayoutCount = 1;
4498 plci.pSetLayouts = &bad_layout;
4499 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4500
4501 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004502}
4503
Mark Muellerd4914412016-06-13 17:52:06 -06004504TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004505 TEST_DESCRIPTION(
4506 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4507 "1) A uniform buffer update must have a valid buffer index."
4508 "2) When using an array of descriptors in a single WriteDescriptor,"
4509 " the descriptor types and stageflags must all be the same."
4510 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004511
Mike Weiblena6666382017-01-05 15:16:11 -07004512 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004513
4514 ASSERT_NO_FATAL_FAILURE(InitState());
4515 VkDescriptorPoolSize ds_type_count[4] = {};
4516 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4517 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004518 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004519 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004520 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004521 ds_type_count[2].descriptorCount = 1;
4522 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4523 ds_type_count[3].descriptorCount = 1;
4524
4525 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4526 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4527 ds_pool_ci.maxSets = 1;
4528 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4529 ds_pool_ci.pPoolSizes = ds_type_count;
4530
4531 VkDescriptorPool ds_pool;
4532 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4533 ASSERT_VK_SUCCESS(err);
4534
Mark Muellerb9896722016-06-16 09:54:29 -06004535 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004536 layout_binding[0].binding = 0;
4537 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4538 layout_binding[0].descriptorCount = 1;
4539 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4540 layout_binding[0].pImmutableSamplers = NULL;
4541
4542 layout_binding[1].binding = 1;
4543 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4544 layout_binding[1].descriptorCount = 1;
4545 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4546 layout_binding[1].pImmutableSamplers = NULL;
4547
4548 VkSamplerCreateInfo sampler_ci = {};
4549 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4550 sampler_ci.pNext = NULL;
4551 sampler_ci.magFilter = VK_FILTER_NEAREST;
4552 sampler_ci.minFilter = VK_FILTER_NEAREST;
4553 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4554 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4555 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4556 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4557 sampler_ci.mipLodBias = 1.0;
4558 sampler_ci.anisotropyEnable = VK_FALSE;
4559 sampler_ci.maxAnisotropy = 1;
4560 sampler_ci.compareEnable = VK_FALSE;
4561 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4562 sampler_ci.minLod = 1.0;
4563 sampler_ci.maxLod = 1.0;
4564 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4565 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4566 VkSampler sampler;
4567
4568 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4569 ASSERT_VK_SUCCESS(err);
4570
4571 layout_binding[2].binding = 2;
4572 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4573 layout_binding[2].descriptorCount = 1;
4574 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4575 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4576
Mark Muellerd4914412016-06-13 17:52:06 -06004577 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4578 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4579 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4580 ds_layout_ci.pBindings = layout_binding;
4581 VkDescriptorSetLayout ds_layout;
4582 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4583 ASSERT_VK_SUCCESS(err);
4584
4585 VkDescriptorSetAllocateInfo alloc_info = {};
4586 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4587 alloc_info.descriptorSetCount = 1;
4588 alloc_info.descriptorPool = ds_pool;
4589 alloc_info.pSetLayouts = &ds_layout;
4590 VkDescriptorSet descriptorSet;
4591 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4592 ASSERT_VK_SUCCESS(err);
4593
4594 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4595 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4596 pipeline_layout_ci.pNext = NULL;
4597 pipeline_layout_ci.setLayoutCount = 1;
4598 pipeline_layout_ci.pSetLayouts = &ds_layout;
4599
4600 VkPipelineLayout pipeline_layout;
4601 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4602 ASSERT_VK_SUCCESS(err);
4603
Mark Mueller5c838ce2016-06-16 09:54:29 -06004604 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004605 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4606 descriptor_write.dstSet = descriptorSet;
4607 descriptor_write.dstBinding = 0;
4608 descriptor_write.descriptorCount = 1;
4609 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4610
Mark Mueller5c838ce2016-06-16 09:54:29 -06004611 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004612 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4613 m_errorMonitor->VerifyFound();
4614
4615 // Create a buffer to update the descriptor with
4616 uint32_t qfi = 0;
4617 VkBufferCreateInfo buffCI = {};
4618 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4619 buffCI.size = 1024;
4620 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4621 buffCI.queueFamilyIndexCount = 1;
4622 buffCI.pQueueFamilyIndices = &qfi;
4623
4624 VkBuffer dyub;
4625 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4626 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004627
Tony Barboure132c5f2016-12-12 11:50:20 -07004628 VkDeviceMemory mem;
4629 VkMemoryRequirements mem_reqs;
4630 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4631
4632 VkMemoryAllocateInfo mem_alloc_info = {};
4633 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4634 mem_alloc_info.allocationSize = mem_reqs.size;
4635 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4636 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4637 ASSERT_VK_SUCCESS(err);
4638
4639 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4640 ASSERT_VK_SUCCESS(err);
4641
4642 VkDescriptorBufferInfo buffInfo[2] = {};
4643 buffInfo[0].buffer = dyub;
4644 buffInfo[0].offset = 0;
4645 buffInfo[0].range = 1024;
4646 buffInfo[1].buffer = dyub;
4647 buffInfo[1].offset = 0;
4648 buffInfo[1].range = 1024;
4649 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004650 descriptor_write.descriptorCount = 2;
4651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004654 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4655 m_errorMonitor->VerifyFound();
4656
Mark Mueller5c838ce2016-06-16 09:54:29 -06004657 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4658 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004659 descriptor_write.dstBinding = 1;
4660 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004661
Mark Mueller5c838ce2016-06-16 09:54:29 -06004662 // Make pImageInfo index non-null to avoid complaints of it missing
4663 VkDescriptorImageInfo imageInfo = {};
4664 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4665 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004666 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004667 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4668 m_errorMonitor->VerifyFound();
4669
Mark Muellerd4914412016-06-13 17:52:06 -06004670 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004671 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004672 vkDestroySampler(m_device->device(), sampler, NULL);
4673 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4675 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4676}
4677
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004678TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004679 TEST_DESCRIPTION(
4680 "Attempt to draw with a command buffer that is invalid "
4681 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004682 ASSERT_NO_FATAL_FAILURE(InitState());
4683
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004684 VkBuffer buffer;
4685 VkDeviceMemory mem;
4686 VkMemoryRequirements mem_reqs;
4687
4688 VkBufferCreateInfo buf_info = {};
4689 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004690 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004691 buf_info.size = 256;
4692 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4693 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4694 ASSERT_VK_SUCCESS(err);
4695
4696 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4697
4698 VkMemoryAllocateInfo alloc_info = {};
4699 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4700 alloc_info.allocationSize = 256;
4701 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004702 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 -06004703 if (!pass) {
4704 vkDestroyBuffer(m_device->device(), buffer, NULL);
4705 return;
4706 }
4707 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4708 ASSERT_VK_SUCCESS(err);
4709
4710 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4711 ASSERT_VK_SUCCESS(err);
4712
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004713 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004714 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004715 m_commandBuffer->EndCommandBuffer();
4716
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004718 // Destroy buffer dependency prior to submit to cause ERROR
4719 vkDestroyBuffer(m_device->device(), buffer, NULL);
4720
4721 VkSubmitInfo submit_info = {};
4722 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4723 submit_info.commandBufferCount = 1;
4724 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4725 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4726
4727 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004728 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004729 vkFreeMemory(m_device->handle(), mem, NULL);
4730}
4731
Tobin Ehlisea413442016-09-28 10:23:59 -06004732TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4733 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4734
4735 ASSERT_NO_FATAL_FAILURE(InitState());
4736 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4737
4738 VkDescriptorPoolSize ds_type_count;
4739 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4740 ds_type_count.descriptorCount = 1;
4741
4742 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4743 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4744 ds_pool_ci.maxSets = 1;
4745 ds_pool_ci.poolSizeCount = 1;
4746 ds_pool_ci.pPoolSizes = &ds_type_count;
4747
4748 VkDescriptorPool ds_pool;
4749 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4750 ASSERT_VK_SUCCESS(err);
4751
4752 VkDescriptorSetLayoutBinding layout_binding;
4753 layout_binding.binding = 0;
4754 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4755 layout_binding.descriptorCount = 1;
4756 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4757 layout_binding.pImmutableSamplers = NULL;
4758
4759 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4760 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4761 ds_layout_ci.bindingCount = 1;
4762 ds_layout_ci.pBindings = &layout_binding;
4763 VkDescriptorSetLayout ds_layout;
4764 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4765 ASSERT_VK_SUCCESS(err);
4766
4767 VkDescriptorSetAllocateInfo alloc_info = {};
4768 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4769 alloc_info.descriptorSetCount = 1;
4770 alloc_info.descriptorPool = ds_pool;
4771 alloc_info.pSetLayouts = &ds_layout;
4772 VkDescriptorSet descriptor_set;
4773 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4774 ASSERT_VK_SUCCESS(err);
4775
4776 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4777 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4778 pipeline_layout_ci.pNext = NULL;
4779 pipeline_layout_ci.setLayoutCount = 1;
4780 pipeline_layout_ci.pSetLayouts = &ds_layout;
4781
4782 VkPipelineLayout pipeline_layout;
4783 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4784 ASSERT_VK_SUCCESS(err);
4785
4786 VkBuffer buffer;
4787 uint32_t queue_family_index = 0;
4788 VkBufferCreateInfo buffer_create_info = {};
4789 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4790 buffer_create_info.size = 1024;
4791 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4792 buffer_create_info.queueFamilyIndexCount = 1;
4793 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4794
4795 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4796 ASSERT_VK_SUCCESS(err);
4797
4798 VkMemoryRequirements memory_reqs;
4799 VkDeviceMemory buffer_memory;
4800
4801 VkMemoryAllocateInfo memory_info = {};
4802 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4803 memory_info.allocationSize = 0;
4804 memory_info.memoryTypeIndex = 0;
4805
4806 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4807 memory_info.allocationSize = memory_reqs.size;
4808 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4809 ASSERT_TRUE(pass);
4810
4811 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4812 ASSERT_VK_SUCCESS(err);
4813 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 VkBufferView view;
4817 VkBufferViewCreateInfo bvci = {};
4818 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4819 bvci.buffer = buffer;
4820 bvci.format = VK_FORMAT_R8_UNORM;
4821 bvci.range = VK_WHOLE_SIZE;
4822
4823 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4824 ASSERT_VK_SUCCESS(err);
4825
4826 VkWriteDescriptorSet descriptor_write = {};
4827 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4828 descriptor_write.dstSet = descriptor_set;
4829 descriptor_write.dstBinding = 0;
4830 descriptor_write.descriptorCount = 1;
4831 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4832 descriptor_write.pTexelBufferView = &view;
4833
4834 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004836 char const *vsSource =
4837 "#version 450\n"
4838 "\n"
4839 "out gl_PerVertex { \n"
4840 " vec4 gl_Position;\n"
4841 "};\n"
4842 "void main(){\n"
4843 " gl_Position = vec4(1);\n"
4844 "}\n";
4845 char const *fsSource =
4846 "#version 450\n"
4847 "\n"
4848 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4849 "layout(location=0) out vec4 x;\n"
4850 "void main(){\n"
4851 " x = imageLoad(s, 0);\n"
4852 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004853 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4854 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4855 VkPipelineObj pipe(m_device);
4856 pipe.AddShader(&vs);
4857 pipe.AddShader(&fs);
4858 pipe.AddColorAttachment();
4859 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4860
Tobin Ehlisea413442016-09-28 10:23:59 -06004861 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4862
Tony Barbour552f6c02016-12-21 14:34:07 -07004863 m_commandBuffer->BeginCommandBuffer();
4864 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4865
Tobin Ehlisea413442016-09-28 10:23:59 -06004866 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4867 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4868 VkRect2D scissor = {{0, 0}, {16, 16}};
4869 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4870 // Bind pipeline to cmd buffer
4871 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4872 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4873 &descriptor_set, 0, nullptr);
4874 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004875 m_commandBuffer->EndRenderPass();
4876 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004877
4878 // Delete BufferView in order to invalidate cmd buffer
4879 vkDestroyBufferView(m_device->device(), view, NULL);
4880 // Now attempt submit of cmd buffer
4881 VkSubmitInfo submit_info = {};
4882 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4883 submit_info.commandBufferCount = 1;
4884 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4885 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4886 m_errorMonitor->VerifyFound();
4887
4888 // Clean-up
4889 vkDestroyBuffer(m_device->device(), buffer, NULL);
4890 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4892 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4893 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4894}
4895
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004896TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004897 TEST_DESCRIPTION(
4898 "Attempt to draw with a command buffer that is invalid "
4899 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004900 ASSERT_NO_FATAL_FAILURE(InitState());
4901
4902 VkImage image;
4903 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4904 VkImageCreateInfo image_create_info = {};
4905 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4906 image_create_info.pNext = NULL;
4907 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4908 image_create_info.format = tex_format;
4909 image_create_info.extent.width = 32;
4910 image_create_info.extent.height = 32;
4911 image_create_info.extent.depth = 1;
4912 image_create_info.mipLevels = 1;
4913 image_create_info.arrayLayers = 1;
4914 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4915 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004916 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004917 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004918 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004919 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004920 // Have to bind memory to image before recording cmd in cmd buffer using it
4921 VkMemoryRequirements mem_reqs;
4922 VkDeviceMemory image_mem;
4923 bool pass;
4924 VkMemoryAllocateInfo mem_alloc = {};
4925 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4926 mem_alloc.pNext = NULL;
4927 mem_alloc.memoryTypeIndex = 0;
4928 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4929 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004930 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004931 ASSERT_TRUE(pass);
4932 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4933 ASSERT_VK_SUCCESS(err);
4934 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4935 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004936
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004937 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004938 VkClearColorValue ccv;
4939 ccv.float32[0] = 1.0f;
4940 ccv.float32[1] = 1.0f;
4941 ccv.float32[2] = 1.0f;
4942 ccv.float32[3] = 1.0f;
4943 VkImageSubresourceRange isr = {};
4944 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004945 isr.baseArrayLayer = 0;
4946 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004947 isr.layerCount = 1;
4948 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004949 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004950 m_commandBuffer->EndCommandBuffer();
4951
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004953 // Destroy image dependency prior to submit to cause ERROR
4954 vkDestroyImage(m_device->device(), image, NULL);
4955
4956 VkSubmitInfo submit_info = {};
4957 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4958 submit_info.commandBufferCount = 1;
4959 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4961
4962 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004963 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004964}
4965
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004966TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004967 TEST_DESCRIPTION(
4968 "Attempt to draw with a command buffer that is invalid "
4969 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004970 VkFormatProperties format_properties;
4971 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004972 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4973 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004974 return;
4975 }
4976
4977 ASSERT_NO_FATAL_FAILURE(InitState());
4978 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4979
4980 VkImageCreateInfo image_ci = {};
4981 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4982 image_ci.pNext = NULL;
4983 image_ci.imageType = VK_IMAGE_TYPE_2D;
4984 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4985 image_ci.extent.width = 32;
4986 image_ci.extent.height = 32;
4987 image_ci.extent.depth = 1;
4988 image_ci.mipLevels = 1;
4989 image_ci.arrayLayers = 1;
4990 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4991 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004992 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004993 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4994 image_ci.flags = 0;
4995 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004996 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004997
4998 VkMemoryRequirements memory_reqs;
4999 VkDeviceMemory image_memory;
5000 bool pass;
5001 VkMemoryAllocateInfo memory_info = {};
5002 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5003 memory_info.pNext = NULL;
5004 memory_info.allocationSize = 0;
5005 memory_info.memoryTypeIndex = 0;
5006 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5007 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005008 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005009 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005010 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005011 ASSERT_VK_SUCCESS(err);
5012 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5013 ASSERT_VK_SUCCESS(err);
5014
5015 VkImageViewCreateInfo ivci = {
5016 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5017 nullptr,
5018 0,
5019 image,
5020 VK_IMAGE_VIEW_TYPE_2D,
5021 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005022 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005023 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5024 };
5025 VkImageView view;
5026 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5027 ASSERT_VK_SUCCESS(err);
5028
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005029 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005030 VkFramebuffer fb;
5031 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5032 ASSERT_VK_SUCCESS(err);
5033
5034 // Just use default renderpass with our framebuffer
5035 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005036 m_renderPassBeginInfo.renderArea.extent.width = 32;
5037 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005038 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005039 m_commandBuffer->BeginCommandBuffer();
5040 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5041 m_commandBuffer->EndRenderPass();
5042 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005043 // Destroy image attached to framebuffer to invalidate cmd buffer
5044 vkDestroyImage(m_device->device(), image, NULL);
5045 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005046 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005047 QueueCommandBuffer(false);
5048 m_errorMonitor->VerifyFound();
5049
5050 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5051 vkDestroyImageView(m_device->device(), view, nullptr);
5052 vkFreeMemory(m_device->device(), image_memory, nullptr);
5053}
5054
Tobin Ehlisb329f992016-10-12 13:20:29 -06005055TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5056 TEST_DESCRIPTION("Delete in-use framebuffer.");
5057 VkFormatProperties format_properties;
5058 VkResult err = VK_SUCCESS;
5059 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5060
5061 ASSERT_NO_FATAL_FAILURE(InitState());
5062 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5063
5064 VkImageObj image(m_device);
5065 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5066 ASSERT_TRUE(image.initialized());
5067 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5068
5069 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5070 VkFramebuffer fb;
5071 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5072 ASSERT_VK_SUCCESS(err);
5073
5074 // Just use default renderpass with our framebuffer
5075 m_renderPassBeginInfo.framebuffer = fb;
5076 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005077 m_commandBuffer->BeginCommandBuffer();
5078 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5079 m_commandBuffer->EndRenderPass();
5080 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005081 // Submit cmd buffer to put it in-flight
5082 VkSubmitInfo submit_info = {};
5083 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5084 submit_info.commandBufferCount = 1;
5085 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5086 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5087 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005088 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005089 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5090 m_errorMonitor->VerifyFound();
5091 // Wait for queue to complete so we can safely destroy everything
5092 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005093 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5094 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005095 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5096}
5097
Tobin Ehlis88becd72016-09-21 14:33:41 -06005098TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5099 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5100 VkFormatProperties format_properties;
5101 VkResult err = VK_SUCCESS;
5102 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005103
5104 ASSERT_NO_FATAL_FAILURE(InitState());
5105 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5106
5107 VkImageCreateInfo image_ci = {};
5108 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5109 image_ci.pNext = NULL;
5110 image_ci.imageType = VK_IMAGE_TYPE_2D;
5111 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5112 image_ci.extent.width = 256;
5113 image_ci.extent.height = 256;
5114 image_ci.extent.depth = 1;
5115 image_ci.mipLevels = 1;
5116 image_ci.arrayLayers = 1;
5117 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5118 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005119 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005120 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5121 image_ci.flags = 0;
5122 VkImage image;
5123 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5124
5125 VkMemoryRequirements memory_reqs;
5126 VkDeviceMemory image_memory;
5127 bool pass;
5128 VkMemoryAllocateInfo memory_info = {};
5129 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5130 memory_info.pNext = NULL;
5131 memory_info.allocationSize = 0;
5132 memory_info.memoryTypeIndex = 0;
5133 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5134 memory_info.allocationSize = memory_reqs.size;
5135 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5136 ASSERT_TRUE(pass);
5137 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5138 ASSERT_VK_SUCCESS(err);
5139 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5140 ASSERT_VK_SUCCESS(err);
5141
5142 VkImageViewCreateInfo ivci = {
5143 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5144 nullptr,
5145 0,
5146 image,
5147 VK_IMAGE_VIEW_TYPE_2D,
5148 VK_FORMAT_B8G8R8A8_UNORM,
5149 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5150 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5151 };
5152 VkImageView view;
5153 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5154 ASSERT_VK_SUCCESS(err);
5155
5156 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5157 VkFramebuffer fb;
5158 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5159 ASSERT_VK_SUCCESS(err);
5160
5161 // Just use default renderpass with our framebuffer
5162 m_renderPassBeginInfo.framebuffer = fb;
5163 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005164 m_commandBuffer->BeginCommandBuffer();
5165 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5166 m_commandBuffer->EndRenderPass();
5167 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005168 // Submit cmd buffer to put it (and attached imageView) in-flight
5169 VkSubmitInfo submit_info = {};
5170 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5171 submit_info.commandBufferCount = 1;
5172 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5173 // Submit cmd buffer to put framebuffer and children in-flight
5174 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5175 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005176 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005177 vkDestroyImage(m_device->device(), image, NULL);
5178 m_errorMonitor->VerifyFound();
5179 // Wait for queue to complete so we can safely destroy image and other objects
5180 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005181 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5182 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005183 vkDestroyImage(m_device->device(), image, NULL);
5184 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5185 vkDestroyImageView(m_device->device(), view, nullptr);
5186 vkFreeMemory(m_device->device(), image_memory, nullptr);
5187}
5188
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005189TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5190 TEST_DESCRIPTION("Delete in-use renderPass.");
5191
5192 ASSERT_NO_FATAL_FAILURE(InitState());
5193 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5194
5195 // Create simple renderpass
5196 VkAttachmentReference attach = {};
5197 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5198 VkSubpassDescription subpass = {};
5199 subpass.pColorAttachments = &attach;
5200 VkRenderPassCreateInfo rpci = {};
5201 rpci.subpassCount = 1;
5202 rpci.pSubpasses = &subpass;
5203 rpci.attachmentCount = 1;
5204 VkAttachmentDescription attach_desc = {};
5205 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5206 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5207 rpci.pAttachments = &attach_desc;
5208 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5209 VkRenderPass rp;
5210 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5211 ASSERT_VK_SUCCESS(err);
5212
5213 // Create a pipeline that uses the given renderpass
5214 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5215 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5216
5217 VkPipelineLayout pipeline_layout;
5218 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5219 ASSERT_VK_SUCCESS(err);
5220
5221 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5222 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005224 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005225 vp_state_ci.pViewports = &vp;
5226 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005227 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005228 vp_state_ci.pScissors = &scissors;
5229
5230 VkPipelineShaderStageCreateInfo shaderStages[2];
5231 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5232
5233 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005234 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 -06005235 // but add it to be able to run on more devices
5236 shaderStages[0] = vs.GetStageCreateInfo();
5237 shaderStages[1] = fs.GetStageCreateInfo();
5238
5239 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5240 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5241
5242 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5243 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5244 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5245
5246 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5247 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5248 rs_ci.rasterizerDiscardEnable = true;
5249 rs_ci.lineWidth = 1.0f;
5250
5251 VkPipelineColorBlendAttachmentState att = {};
5252 att.blendEnable = VK_FALSE;
5253 att.colorWriteMask = 0xf;
5254
5255 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5256 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5257 cb_ci.attachmentCount = 1;
5258 cb_ci.pAttachments = &att;
5259
5260 VkGraphicsPipelineCreateInfo gp_ci = {};
5261 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5262 gp_ci.stageCount = 2;
5263 gp_ci.pStages = shaderStages;
5264 gp_ci.pVertexInputState = &vi_ci;
5265 gp_ci.pInputAssemblyState = &ia_ci;
5266 gp_ci.pViewportState = &vp_state_ci;
5267 gp_ci.pRasterizationState = &rs_ci;
5268 gp_ci.pColorBlendState = &cb_ci;
5269 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5270 gp_ci.layout = pipeline_layout;
5271 gp_ci.renderPass = rp;
5272
5273 VkPipelineCacheCreateInfo pc_ci = {};
5274 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5275
5276 VkPipeline pipeline;
5277 VkPipelineCache pipe_cache;
5278 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5279 ASSERT_VK_SUCCESS(err);
5280
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005281 m_errorMonitor->SetUnexpectedError(
5282 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5283 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005284 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5285 ASSERT_VK_SUCCESS(err);
5286 // Bind pipeline to cmd buffer, will also bind renderpass
5287 m_commandBuffer->BeginCommandBuffer();
5288 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5289 m_commandBuffer->EndCommandBuffer();
5290
5291 VkSubmitInfo submit_info = {};
5292 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5293 submit_info.commandBufferCount = 1;
5294 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5295 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5296
5297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5298 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5299 m_errorMonitor->VerifyFound();
5300
5301 // Wait for queue to complete so we can safely destroy everything
5302 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005303 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5304 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005305 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5306 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5307 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5308 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5309}
5310
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005311TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005312 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005313 ASSERT_NO_FATAL_FAILURE(InitState());
5314
5315 VkImage image;
5316 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5317 VkImageCreateInfo image_create_info = {};
5318 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5319 image_create_info.pNext = NULL;
5320 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5321 image_create_info.format = tex_format;
5322 image_create_info.extent.width = 32;
5323 image_create_info.extent.height = 32;
5324 image_create_info.extent.depth = 1;
5325 image_create_info.mipLevels = 1;
5326 image_create_info.arrayLayers = 1;
5327 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5328 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005329 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005330 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005331 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005332 ASSERT_VK_SUCCESS(err);
5333 // Have to bind memory to image before recording cmd in cmd buffer using it
5334 VkMemoryRequirements mem_reqs;
5335 VkDeviceMemory image_mem;
5336 bool pass;
5337 VkMemoryAllocateInfo mem_alloc = {};
5338 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5339 mem_alloc.pNext = NULL;
5340 mem_alloc.memoryTypeIndex = 0;
5341 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5342 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005343 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005344 ASSERT_TRUE(pass);
5345 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5346 ASSERT_VK_SUCCESS(err);
5347
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005348 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005350 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005351
5352 m_commandBuffer->BeginCommandBuffer();
5353 VkClearColorValue ccv;
5354 ccv.float32[0] = 1.0f;
5355 ccv.float32[1] = 1.0f;
5356 ccv.float32[2] = 1.0f;
5357 ccv.float32[3] = 1.0f;
5358 VkImageSubresourceRange isr = {};
5359 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5360 isr.baseArrayLayer = 0;
5361 isr.baseMipLevel = 0;
5362 isr.layerCount = 1;
5363 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005364 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005365 m_commandBuffer->EndCommandBuffer();
5366
5367 m_errorMonitor->VerifyFound();
5368 vkDestroyImage(m_device->device(), image, NULL);
5369 vkFreeMemory(m_device->device(), image_mem, nullptr);
5370}
5371
5372TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005373 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005374 ASSERT_NO_FATAL_FAILURE(InitState());
5375
5376 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005377 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 -06005378 VK_IMAGE_TILING_OPTIMAL, 0);
5379 ASSERT_TRUE(image.initialized());
5380
5381 VkBuffer buffer;
5382 VkDeviceMemory mem;
5383 VkMemoryRequirements mem_reqs;
5384
5385 VkBufferCreateInfo buf_info = {};
5386 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005387 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005388 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005389 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5390 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5391 ASSERT_VK_SUCCESS(err);
5392
5393 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5394
5395 VkMemoryAllocateInfo alloc_info = {};
5396 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005397 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005398 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005399 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 -06005400 if (!pass) {
5401 vkDestroyBuffer(m_device->device(), buffer, NULL);
5402 return;
5403 }
5404 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5405 ASSERT_VK_SUCCESS(err);
5406
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005407 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005409 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005410 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005411 region.bufferRowLength = 16;
5412 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005413 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5414
5415 region.imageSubresource.layerCount = 1;
5416 region.imageExtent.height = 4;
5417 region.imageExtent.width = 4;
5418 region.imageExtent.depth = 1;
5419 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005420 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5421 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005422 m_commandBuffer->EndCommandBuffer();
5423
5424 m_errorMonitor->VerifyFound();
5425
5426 vkDestroyBuffer(m_device->device(), buffer, NULL);
5427 vkFreeMemory(m_device->handle(), mem, NULL);
5428}
5429
Tobin Ehlis85940f52016-07-07 16:57:21 -06005430TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005431 TEST_DESCRIPTION(
5432 "Attempt to draw with a command buffer that is invalid "
5433 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005434 ASSERT_NO_FATAL_FAILURE(InitState());
5435
5436 VkEvent event;
5437 VkEventCreateInfo evci = {};
5438 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5439 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5440 ASSERT_VK_SUCCESS(result);
5441
5442 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005443 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005444 m_commandBuffer->EndCommandBuffer();
5445
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005447 // Destroy event dependency prior to submit to cause ERROR
5448 vkDestroyEvent(m_device->device(), event, NULL);
5449
5450 VkSubmitInfo submit_info = {};
5451 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5452 submit_info.commandBufferCount = 1;
5453 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5454 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5455
5456 m_errorMonitor->VerifyFound();
5457}
5458
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005459TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005460 TEST_DESCRIPTION(
5461 "Attempt to draw with a command buffer that is invalid "
5462 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005463 ASSERT_NO_FATAL_FAILURE(InitState());
5464
5465 VkQueryPool query_pool;
5466 VkQueryPoolCreateInfo qpci{};
5467 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5468 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5469 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005470 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005471 ASSERT_VK_SUCCESS(result);
5472
5473 m_commandBuffer->BeginCommandBuffer();
5474 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5475 m_commandBuffer->EndCommandBuffer();
5476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005478 // Destroy query pool dependency prior to submit to cause ERROR
5479 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5480
5481 VkSubmitInfo submit_info = {};
5482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5483 submit_info.commandBufferCount = 1;
5484 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5485 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5486
5487 m_errorMonitor->VerifyFound();
5488}
5489
Tobin Ehlis24130d92016-07-08 15:50:53 -06005490TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005491 TEST_DESCRIPTION(
5492 "Attempt to draw with a command buffer that is invalid "
5493 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494 ASSERT_NO_FATAL_FAILURE(InitState());
5495 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5496
5497 VkResult err;
5498
5499 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5500 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5501
5502 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005503 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005504 ASSERT_VK_SUCCESS(err);
5505
5506 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5507 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5508 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005509 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005510 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005511 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005512 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005513 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005514
5515 VkPipelineShaderStageCreateInfo shaderStages[2];
5516 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5517
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005518 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005519 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 -06005520 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005521 shaderStages[0] = vs.GetStageCreateInfo();
5522 shaderStages[1] = fs.GetStageCreateInfo();
5523
5524 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5525 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5526
5527 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5528 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5529 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5530
5531 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5532 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005533 rs_ci.rasterizerDiscardEnable = true;
5534 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005535
5536 VkPipelineColorBlendAttachmentState att = {};
5537 att.blendEnable = VK_FALSE;
5538 att.colorWriteMask = 0xf;
5539
5540 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5541 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5542 cb_ci.attachmentCount = 1;
5543 cb_ci.pAttachments = &att;
5544
5545 VkGraphicsPipelineCreateInfo gp_ci = {};
5546 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5547 gp_ci.stageCount = 2;
5548 gp_ci.pStages = shaderStages;
5549 gp_ci.pVertexInputState = &vi_ci;
5550 gp_ci.pInputAssemblyState = &ia_ci;
5551 gp_ci.pViewportState = &vp_state_ci;
5552 gp_ci.pRasterizationState = &rs_ci;
5553 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005554 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5555 gp_ci.layout = pipeline_layout;
5556 gp_ci.renderPass = renderPass();
5557
5558 VkPipelineCacheCreateInfo pc_ci = {};
5559 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5560
5561 VkPipeline pipeline;
5562 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005563 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005564 ASSERT_VK_SUCCESS(err);
5565
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005566 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005567 ASSERT_VK_SUCCESS(err);
5568
5569 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005570 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005571 m_commandBuffer->EndCommandBuffer();
5572 // Now destroy pipeline in order to cause error when submitting
5573 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5574
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005575 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005576
5577 VkSubmitInfo submit_info = {};
5578 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5579 submit_info.commandBufferCount = 1;
5580 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5581 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5582
5583 m_errorMonitor->VerifyFound();
5584 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5585 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5586}
5587
Tobin Ehlis31289162016-08-17 14:57:58 -06005588TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005589 TEST_DESCRIPTION(
5590 "Attempt to draw with a command buffer that is invalid "
5591 "due to a bound descriptor set with a buffer dependency "
5592 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005593 ASSERT_NO_FATAL_FAILURE(InitState());
5594 ASSERT_NO_FATAL_FAILURE(InitViewport());
5595 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5596
5597 VkDescriptorPoolSize ds_type_count = {};
5598 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5599 ds_type_count.descriptorCount = 1;
5600
5601 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5602 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5603 ds_pool_ci.pNext = NULL;
5604 ds_pool_ci.maxSets = 1;
5605 ds_pool_ci.poolSizeCount = 1;
5606 ds_pool_ci.pPoolSizes = &ds_type_count;
5607
5608 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005609 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005610 ASSERT_VK_SUCCESS(err);
5611
5612 VkDescriptorSetLayoutBinding dsl_binding = {};
5613 dsl_binding.binding = 0;
5614 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5615 dsl_binding.descriptorCount = 1;
5616 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5617 dsl_binding.pImmutableSamplers = NULL;
5618
5619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5621 ds_layout_ci.pNext = NULL;
5622 ds_layout_ci.bindingCount = 1;
5623 ds_layout_ci.pBindings = &dsl_binding;
5624 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005625 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005626 ASSERT_VK_SUCCESS(err);
5627
5628 VkDescriptorSet descriptorSet;
5629 VkDescriptorSetAllocateInfo alloc_info = {};
5630 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5631 alloc_info.descriptorSetCount = 1;
5632 alloc_info.descriptorPool = ds_pool;
5633 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005634 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005635 ASSERT_VK_SUCCESS(err);
5636
5637 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5638 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5639 pipeline_layout_ci.pNext = NULL;
5640 pipeline_layout_ci.setLayoutCount = 1;
5641 pipeline_layout_ci.pSetLayouts = &ds_layout;
5642
5643 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005644 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005645 ASSERT_VK_SUCCESS(err);
5646
5647 // Create a buffer to update the descriptor with
5648 uint32_t qfi = 0;
5649 VkBufferCreateInfo buffCI = {};
5650 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5651 buffCI.size = 1024;
5652 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5653 buffCI.queueFamilyIndexCount = 1;
5654 buffCI.pQueueFamilyIndices = &qfi;
5655
5656 VkBuffer buffer;
5657 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5658 ASSERT_VK_SUCCESS(err);
5659 // Allocate memory and bind to buffer so we can make it to the appropriate
5660 // error
5661 VkMemoryAllocateInfo mem_alloc = {};
5662 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5663 mem_alloc.pNext = NULL;
5664 mem_alloc.allocationSize = 1024;
5665 mem_alloc.memoryTypeIndex = 0;
5666
5667 VkMemoryRequirements memReqs;
5668 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005669 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005670 if (!pass) {
5671 vkDestroyBuffer(m_device->device(), buffer, NULL);
5672 return;
5673 }
5674
5675 VkDeviceMemory mem;
5676 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5677 ASSERT_VK_SUCCESS(err);
5678 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5679 ASSERT_VK_SUCCESS(err);
5680 // Correctly update descriptor to avoid "NOT_UPDATED" error
5681 VkDescriptorBufferInfo buffInfo = {};
5682 buffInfo.buffer = buffer;
5683 buffInfo.offset = 0;
5684 buffInfo.range = 1024;
5685
5686 VkWriteDescriptorSet descriptor_write;
5687 memset(&descriptor_write, 0, sizeof(descriptor_write));
5688 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5689 descriptor_write.dstSet = descriptorSet;
5690 descriptor_write.dstBinding = 0;
5691 descriptor_write.descriptorCount = 1;
5692 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5693 descriptor_write.pBufferInfo = &buffInfo;
5694
5695 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5696
5697 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005698 char const *vsSource =
5699 "#version 450\n"
5700 "\n"
5701 "out gl_PerVertex { \n"
5702 " vec4 gl_Position;\n"
5703 "};\n"
5704 "void main(){\n"
5705 " gl_Position = vec4(1);\n"
5706 "}\n";
5707 char const *fsSource =
5708 "#version 450\n"
5709 "\n"
5710 "layout(location=0) out vec4 x;\n"
5711 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5712 "void main(){\n"
5713 " x = vec4(bar.y);\n"
5714 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005715 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5716 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5717 VkPipelineObj pipe(m_device);
5718 pipe.AddShader(&vs);
5719 pipe.AddShader(&fs);
5720 pipe.AddColorAttachment();
5721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5722
Tony Barbour552f6c02016-12-21 14:34:07 -07005723 m_commandBuffer->BeginCommandBuffer();
5724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005725 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5726 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5727 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005728
5729 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5730 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5731
Tobin Ehlis31289162016-08-17 14:57:58 -06005732 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005733 m_commandBuffer->EndRenderPass();
5734 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005735 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005736 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5737 vkDestroyBuffer(m_device->device(), buffer, NULL);
5738 // Attempt to submit cmd buffer
5739 VkSubmitInfo submit_info = {};
5740 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5741 submit_info.commandBufferCount = 1;
5742 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5743 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5744 m_errorMonitor->VerifyFound();
5745 // Cleanup
5746 vkFreeMemory(m_device->device(), mem, NULL);
5747
5748 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5749 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5750 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5751}
5752
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005753TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005754 TEST_DESCRIPTION(
5755 "Attempt to draw with a command buffer that is invalid "
5756 "due to a bound descriptor sets with a combined image "
5757 "sampler having their image, sampler, and descriptor set "
5758 "each respectively destroyed and then attempting to "
5759 "submit associated cmd buffers. Attempt to destroy a "
5760 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005761 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005762 ASSERT_NO_FATAL_FAILURE(InitViewport());
5763 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5764
5765 VkDescriptorPoolSize ds_type_count = {};
5766 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5767 ds_type_count.descriptorCount = 1;
5768
5769 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5770 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5771 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005772 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005773 ds_pool_ci.maxSets = 1;
5774 ds_pool_ci.poolSizeCount = 1;
5775 ds_pool_ci.pPoolSizes = &ds_type_count;
5776
5777 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005778 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005779 ASSERT_VK_SUCCESS(err);
5780
5781 VkDescriptorSetLayoutBinding dsl_binding = {};
5782 dsl_binding.binding = 0;
5783 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5784 dsl_binding.descriptorCount = 1;
5785 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5786 dsl_binding.pImmutableSamplers = NULL;
5787
5788 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5789 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5790 ds_layout_ci.pNext = NULL;
5791 ds_layout_ci.bindingCount = 1;
5792 ds_layout_ci.pBindings = &dsl_binding;
5793 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005794 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005795 ASSERT_VK_SUCCESS(err);
5796
5797 VkDescriptorSet descriptorSet;
5798 VkDescriptorSetAllocateInfo alloc_info = {};
5799 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5800 alloc_info.descriptorSetCount = 1;
5801 alloc_info.descriptorPool = ds_pool;
5802 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005804 ASSERT_VK_SUCCESS(err);
5805
5806 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5807 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5808 pipeline_layout_ci.pNext = NULL;
5809 pipeline_layout_ci.setLayoutCount = 1;
5810 pipeline_layout_ci.pSetLayouts = &ds_layout;
5811
5812 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005813 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005814 ASSERT_VK_SUCCESS(err);
5815
5816 // Create images to update the descriptor with
5817 VkImage image;
5818 VkImage image2;
5819 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5820 const int32_t tex_width = 32;
5821 const int32_t tex_height = 32;
5822 VkImageCreateInfo image_create_info = {};
5823 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5824 image_create_info.pNext = NULL;
5825 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5826 image_create_info.format = tex_format;
5827 image_create_info.extent.width = tex_width;
5828 image_create_info.extent.height = tex_height;
5829 image_create_info.extent.depth = 1;
5830 image_create_info.mipLevels = 1;
5831 image_create_info.arrayLayers = 1;
5832 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5833 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5834 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5835 image_create_info.flags = 0;
5836 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5837 ASSERT_VK_SUCCESS(err);
5838 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5839 ASSERT_VK_SUCCESS(err);
5840
5841 VkMemoryRequirements memory_reqs;
5842 VkDeviceMemory image_memory;
5843 bool pass;
5844 VkMemoryAllocateInfo memory_info = {};
5845 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5846 memory_info.pNext = NULL;
5847 memory_info.allocationSize = 0;
5848 memory_info.memoryTypeIndex = 0;
5849 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5850 // Allocate enough memory for both images
5851 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005852 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005853 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005854 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005855 ASSERT_VK_SUCCESS(err);
5856 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5857 ASSERT_VK_SUCCESS(err);
5858 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005859 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005860 ASSERT_VK_SUCCESS(err);
5861
5862 VkImageViewCreateInfo image_view_create_info = {};
5863 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5864 image_view_create_info.image = image;
5865 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5866 image_view_create_info.format = tex_format;
5867 image_view_create_info.subresourceRange.layerCount = 1;
5868 image_view_create_info.subresourceRange.baseMipLevel = 0;
5869 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005870 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005871
5872 VkImageView view;
5873 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005874 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005875 ASSERT_VK_SUCCESS(err);
5876 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005877 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005878 ASSERT_VK_SUCCESS(err);
5879 // Create Samplers
5880 VkSamplerCreateInfo sampler_ci = {};
5881 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5882 sampler_ci.pNext = NULL;
5883 sampler_ci.magFilter = VK_FILTER_NEAREST;
5884 sampler_ci.minFilter = VK_FILTER_NEAREST;
5885 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5886 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5887 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5888 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5889 sampler_ci.mipLodBias = 1.0;
5890 sampler_ci.anisotropyEnable = VK_FALSE;
5891 sampler_ci.maxAnisotropy = 1;
5892 sampler_ci.compareEnable = VK_FALSE;
5893 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5894 sampler_ci.minLod = 1.0;
5895 sampler_ci.maxLod = 1.0;
5896 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5897 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5898 VkSampler sampler;
5899 VkSampler sampler2;
5900 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5901 ASSERT_VK_SUCCESS(err);
5902 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5903 ASSERT_VK_SUCCESS(err);
5904 // Update descriptor with image and sampler
5905 VkDescriptorImageInfo img_info = {};
5906 img_info.sampler = sampler;
5907 img_info.imageView = view;
5908 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5909
5910 VkWriteDescriptorSet descriptor_write;
5911 memset(&descriptor_write, 0, sizeof(descriptor_write));
5912 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5913 descriptor_write.dstSet = descriptorSet;
5914 descriptor_write.dstBinding = 0;
5915 descriptor_write.descriptorCount = 1;
5916 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5917 descriptor_write.pImageInfo = &img_info;
5918
5919 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5920
5921 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005922 char const *vsSource =
5923 "#version 450\n"
5924 "\n"
5925 "out gl_PerVertex { \n"
5926 " vec4 gl_Position;\n"
5927 "};\n"
5928 "void main(){\n"
5929 " gl_Position = vec4(1);\n"
5930 "}\n";
5931 char const *fsSource =
5932 "#version 450\n"
5933 "\n"
5934 "layout(set=0, binding=0) uniform sampler2D s;\n"
5935 "layout(location=0) out vec4 x;\n"
5936 "void main(){\n"
5937 " x = texture(s, vec2(1));\n"
5938 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005939 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5940 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5941 VkPipelineObj pipe(m_device);
5942 pipe.AddShader(&vs);
5943 pipe.AddShader(&fs);
5944 pipe.AddColorAttachment();
5945 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5946
5947 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005948 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005949 m_commandBuffer->BeginCommandBuffer();
5950 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005951 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5952 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5953 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005954 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5955 VkRect2D scissor = {{0, 0}, {16, 16}};
5956 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5957 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005958 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005959 m_commandBuffer->EndRenderPass();
5960 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005961 // Destroy sampler invalidates the cmd buffer, causing error on submit
5962 vkDestroySampler(m_device->device(), sampler, NULL);
5963 // Attempt to submit cmd buffer
5964 VkSubmitInfo submit_info = {};
5965 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5966 submit_info.commandBufferCount = 1;
5967 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5968 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5969 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005970
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005971 // Now re-update descriptor with valid sampler and delete image
5972 img_info.sampler = sampler2;
5973 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005974
5975 VkCommandBufferBeginInfo info = {};
5976 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5977 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005980 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005981 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005982 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5983 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5984 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005985 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5986 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005987 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005988 m_commandBuffer->EndRenderPass();
5989 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005990 // Destroy image invalidates the cmd buffer, causing error on submit
5991 vkDestroyImage(m_device->device(), image, NULL);
5992 // Attempt to submit cmd buffer
5993 submit_info = {};
5994 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5995 submit_info.commandBufferCount = 1;
5996 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5997 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5998 m_errorMonitor->VerifyFound();
5999 // Now update descriptor to be valid, but then free descriptor
6000 img_info.imageView = view2;
6001 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07006002 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07006003 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006004 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6005 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6006 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07006007 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6008 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006009 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006010 m_commandBuffer->EndRenderPass();
6011 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006012 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006013
6014 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006015 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006016 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006017 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006018
6019 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006020 // 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 -07006021 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006022 m_errorMonitor->SetUnexpectedError(
6023 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6024 "either be a valid handle or VK_NULL_HANDLE");
6025 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006026 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6027
6028 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006029 submit_info = {};
6030 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6031 submit_info.commandBufferCount = 1;
6032 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006034 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6035 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006036
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006037 // Cleanup
6038 vkFreeMemory(m_device->device(), image_memory, NULL);
6039 vkDestroySampler(m_device->device(), sampler2, NULL);
6040 vkDestroyImage(m_device->device(), image2, NULL);
6041 vkDestroyImageView(m_device->device(), view, NULL);
6042 vkDestroyImageView(m_device->device(), view2, NULL);
6043 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6044 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6045 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6046}
6047
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006048TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6049 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6050 ASSERT_NO_FATAL_FAILURE(InitState());
6051 ASSERT_NO_FATAL_FAILURE(InitViewport());
6052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6053
6054 VkDescriptorPoolSize ds_type_count = {};
6055 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6056 ds_type_count.descriptorCount = 1;
6057
6058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6060 ds_pool_ci.pNext = NULL;
6061 ds_pool_ci.maxSets = 1;
6062 ds_pool_ci.poolSizeCount = 1;
6063 ds_pool_ci.pPoolSizes = &ds_type_count;
6064
6065 VkDescriptorPool ds_pool;
6066 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6067 ASSERT_VK_SUCCESS(err);
6068
6069 VkDescriptorSetLayoutBinding dsl_binding = {};
6070 dsl_binding.binding = 0;
6071 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6072 dsl_binding.descriptorCount = 1;
6073 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6074 dsl_binding.pImmutableSamplers = NULL;
6075
6076 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6077 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6078 ds_layout_ci.pNext = NULL;
6079 ds_layout_ci.bindingCount = 1;
6080 ds_layout_ci.pBindings = &dsl_binding;
6081 VkDescriptorSetLayout ds_layout;
6082 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6083 ASSERT_VK_SUCCESS(err);
6084
6085 VkDescriptorSet descriptor_set;
6086 VkDescriptorSetAllocateInfo alloc_info = {};
6087 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6088 alloc_info.descriptorSetCount = 1;
6089 alloc_info.descriptorPool = ds_pool;
6090 alloc_info.pSetLayouts = &ds_layout;
6091 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6092 ASSERT_VK_SUCCESS(err);
6093
6094 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6095 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6096 pipeline_layout_ci.pNext = NULL;
6097 pipeline_layout_ci.setLayoutCount = 1;
6098 pipeline_layout_ci.pSetLayouts = &ds_layout;
6099
6100 VkPipelineLayout pipeline_layout;
6101 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6102 ASSERT_VK_SUCCESS(err);
6103
6104 // Create image to update the descriptor with
6105 VkImageObj image(m_device);
6106 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6107 ASSERT_TRUE(image.initialized());
6108
6109 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6110 // Create Sampler
6111 VkSamplerCreateInfo sampler_ci = {};
6112 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6113 sampler_ci.pNext = NULL;
6114 sampler_ci.magFilter = VK_FILTER_NEAREST;
6115 sampler_ci.minFilter = VK_FILTER_NEAREST;
6116 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6117 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6118 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6119 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6120 sampler_ci.mipLodBias = 1.0;
6121 sampler_ci.anisotropyEnable = VK_FALSE;
6122 sampler_ci.maxAnisotropy = 1;
6123 sampler_ci.compareEnable = VK_FALSE;
6124 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6125 sampler_ci.minLod = 1.0;
6126 sampler_ci.maxLod = 1.0;
6127 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6128 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6129 VkSampler sampler;
6130 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6131 ASSERT_VK_SUCCESS(err);
6132 // Update descriptor with image and sampler
6133 VkDescriptorImageInfo img_info = {};
6134 img_info.sampler = sampler;
6135 img_info.imageView = view;
6136 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6137
6138 VkWriteDescriptorSet descriptor_write;
6139 memset(&descriptor_write, 0, sizeof(descriptor_write));
6140 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6141 descriptor_write.dstSet = descriptor_set;
6142 descriptor_write.dstBinding = 0;
6143 descriptor_write.descriptorCount = 1;
6144 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6145 descriptor_write.pImageInfo = &img_info;
6146
6147 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6148
6149 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006150 char const *vsSource =
6151 "#version 450\n"
6152 "\n"
6153 "out gl_PerVertex { \n"
6154 " vec4 gl_Position;\n"
6155 "};\n"
6156 "void main(){\n"
6157 " gl_Position = vec4(1);\n"
6158 "}\n";
6159 char const *fsSource =
6160 "#version 450\n"
6161 "\n"
6162 "layout(set=0, binding=0) uniform sampler2D s;\n"
6163 "layout(location=0) out vec4 x;\n"
6164 "void main(){\n"
6165 " x = texture(s, vec2(1));\n"
6166 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006167 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6168 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6169 VkPipelineObj pipe(m_device);
6170 pipe.AddShader(&vs);
6171 pipe.AddShader(&fs);
6172 pipe.AddColorAttachment();
6173 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6174
Tony Barbour552f6c02016-12-21 14:34:07 -07006175 m_commandBuffer->BeginCommandBuffer();
6176 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006177 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6178 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6179 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006180
6181 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6182 VkRect2D scissor = {{0, 0}, {16, 16}};
6183 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6184 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6185
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006186 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006187 m_commandBuffer->EndRenderPass();
6188 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006189 // Submit cmd buffer to put pool in-flight
6190 VkSubmitInfo submit_info = {};
6191 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6192 submit_info.commandBufferCount = 1;
6193 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6194 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6195 // Destroy pool while in-flight, causing error
6196 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6198 m_errorMonitor->VerifyFound();
6199 vkQueueWaitIdle(m_device->m_queue);
6200 // Cleanup
6201 vkDestroySampler(m_device->device(), sampler, NULL);
6202 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6203 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006204 m_errorMonitor->SetUnexpectedError(
6205 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6206 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006207 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006208 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006209}
6210
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006211TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6212 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6213 ASSERT_NO_FATAL_FAILURE(InitState());
6214 ASSERT_NO_FATAL_FAILURE(InitViewport());
6215 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6216
6217 VkDescriptorPoolSize ds_type_count = {};
6218 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6219 ds_type_count.descriptorCount = 1;
6220
6221 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6222 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6223 ds_pool_ci.pNext = NULL;
6224 ds_pool_ci.maxSets = 1;
6225 ds_pool_ci.poolSizeCount = 1;
6226 ds_pool_ci.pPoolSizes = &ds_type_count;
6227
6228 VkDescriptorPool ds_pool;
6229 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6230 ASSERT_VK_SUCCESS(err);
6231
6232 VkDescriptorSetLayoutBinding dsl_binding = {};
6233 dsl_binding.binding = 0;
6234 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6235 dsl_binding.descriptorCount = 1;
6236 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6237 dsl_binding.pImmutableSamplers = NULL;
6238
6239 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6240 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6241 ds_layout_ci.pNext = NULL;
6242 ds_layout_ci.bindingCount = 1;
6243 ds_layout_ci.pBindings = &dsl_binding;
6244 VkDescriptorSetLayout ds_layout;
6245 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6246 ASSERT_VK_SUCCESS(err);
6247
6248 VkDescriptorSet descriptorSet;
6249 VkDescriptorSetAllocateInfo alloc_info = {};
6250 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6251 alloc_info.descriptorSetCount = 1;
6252 alloc_info.descriptorPool = ds_pool;
6253 alloc_info.pSetLayouts = &ds_layout;
6254 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6255 ASSERT_VK_SUCCESS(err);
6256
6257 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6258 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6259 pipeline_layout_ci.pNext = NULL;
6260 pipeline_layout_ci.setLayoutCount = 1;
6261 pipeline_layout_ci.pSetLayouts = &ds_layout;
6262
6263 VkPipelineLayout pipeline_layout;
6264 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6265 ASSERT_VK_SUCCESS(err);
6266
6267 // Create images to update the descriptor with
6268 VkImage image;
6269 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6270 const int32_t tex_width = 32;
6271 const int32_t tex_height = 32;
6272 VkImageCreateInfo image_create_info = {};
6273 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6274 image_create_info.pNext = NULL;
6275 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6276 image_create_info.format = tex_format;
6277 image_create_info.extent.width = tex_width;
6278 image_create_info.extent.height = tex_height;
6279 image_create_info.extent.depth = 1;
6280 image_create_info.mipLevels = 1;
6281 image_create_info.arrayLayers = 1;
6282 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6283 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6284 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6285 image_create_info.flags = 0;
6286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6287 ASSERT_VK_SUCCESS(err);
6288 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6289 VkMemoryRequirements memory_reqs;
6290 VkDeviceMemory image_memory;
6291 bool pass;
6292 VkMemoryAllocateInfo memory_info = {};
6293 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6294 memory_info.pNext = NULL;
6295 memory_info.allocationSize = 0;
6296 memory_info.memoryTypeIndex = 0;
6297 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6298 // Allocate enough memory for image
6299 memory_info.allocationSize = memory_reqs.size;
6300 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6301 ASSERT_TRUE(pass);
6302 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6303 ASSERT_VK_SUCCESS(err);
6304 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6305 ASSERT_VK_SUCCESS(err);
6306
6307 VkImageViewCreateInfo image_view_create_info = {};
6308 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6309 image_view_create_info.image = image;
6310 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6311 image_view_create_info.format = tex_format;
6312 image_view_create_info.subresourceRange.layerCount = 1;
6313 image_view_create_info.subresourceRange.baseMipLevel = 0;
6314 image_view_create_info.subresourceRange.levelCount = 1;
6315 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6316
6317 VkImageView view;
6318 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6319 ASSERT_VK_SUCCESS(err);
6320 // Create Samplers
6321 VkSamplerCreateInfo sampler_ci = {};
6322 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6323 sampler_ci.pNext = NULL;
6324 sampler_ci.magFilter = VK_FILTER_NEAREST;
6325 sampler_ci.minFilter = VK_FILTER_NEAREST;
6326 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6327 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6328 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6329 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6330 sampler_ci.mipLodBias = 1.0;
6331 sampler_ci.anisotropyEnable = VK_FALSE;
6332 sampler_ci.maxAnisotropy = 1;
6333 sampler_ci.compareEnable = VK_FALSE;
6334 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6335 sampler_ci.minLod = 1.0;
6336 sampler_ci.maxLod = 1.0;
6337 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6338 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6339 VkSampler sampler;
6340 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6341 ASSERT_VK_SUCCESS(err);
6342 // Update descriptor with image and sampler
6343 VkDescriptorImageInfo img_info = {};
6344 img_info.sampler = sampler;
6345 img_info.imageView = view;
6346 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6347
6348 VkWriteDescriptorSet descriptor_write;
6349 memset(&descriptor_write, 0, sizeof(descriptor_write));
6350 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6351 descriptor_write.dstSet = descriptorSet;
6352 descriptor_write.dstBinding = 0;
6353 descriptor_write.descriptorCount = 1;
6354 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6355 descriptor_write.pImageInfo = &img_info;
6356 // Break memory binding and attempt update
6357 vkFreeMemory(m_device->device(), image_memory, nullptr);
6358 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006359 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006360 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6361 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6362 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6363 m_errorMonitor->VerifyFound();
6364 // Cleanup
6365 vkDestroyImage(m_device->device(), image, NULL);
6366 vkDestroySampler(m_device->device(), sampler, NULL);
6367 vkDestroyImageView(m_device->device(), view, NULL);
6368 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6369 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6370 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6371}
6372
Karl Schultz6addd812016-02-02 17:17:23 -07006373TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006374 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6375 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006376 // Create a valid cmd buffer
6377 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006378 uint64_t fake_pipeline_handle = 0xbaad6001;
6379 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006380 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6382
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006383 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006384 m_commandBuffer->BeginCommandBuffer();
6385 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006386 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006387 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006388
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006389 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006390 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 -06006391 Draw(1, 0, 0, 0);
6392 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006393
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006394 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 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 -07006396 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006397 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6398 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006399}
6400
Karl Schultz6addd812016-02-02 17:17:23 -07006401TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006402 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006403 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006406
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006407 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006408 ASSERT_NO_FATAL_FAILURE(InitViewport());
6409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006410 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006411 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6412 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006413
6414 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006415 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6416 ds_pool_ci.pNext = NULL;
6417 ds_pool_ci.maxSets = 1;
6418 ds_pool_ci.poolSizeCount = 1;
6419 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006420
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006421 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006422 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006423 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006424
Tony Barboureb254902015-07-15 12:50:33 -06006425 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006426 dsl_binding.binding = 0;
6427 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6428 dsl_binding.descriptorCount = 1;
6429 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6430 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006431
Tony Barboureb254902015-07-15 12:50:33 -06006432 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006433 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6434 ds_layout_ci.pNext = NULL;
6435 ds_layout_ci.bindingCount = 1;
6436 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006437 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006438 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006439 ASSERT_VK_SUCCESS(err);
6440
6441 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006442 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006443 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006444 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006445 alloc_info.descriptorPool = ds_pool;
6446 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006447 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006448 ASSERT_VK_SUCCESS(err);
6449
Tony Barboureb254902015-07-15 12:50:33 -06006450 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006451 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6452 pipeline_layout_ci.pNext = NULL;
6453 pipeline_layout_ci.setLayoutCount = 1;
6454 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006455
6456 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006457 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006458 ASSERT_VK_SUCCESS(err);
6459
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006460 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006461 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006462 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006463 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006464
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006465 VkPipelineObj pipe(m_device);
6466 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006467 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006468 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006469 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006470
Tony Barbour552f6c02016-12-21 14:34:07 -07006471 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006472 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6473 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6474 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006475
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006476 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006477
Chia-I Wuf7458c52015-10-26 21:10:41 +08006478 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6479 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6480 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006481}
6482
Karl Schultz6addd812016-02-02 17:17:23 -07006483TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006484 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006485 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006486
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006488
6489 ASSERT_NO_FATAL_FAILURE(InitState());
6490 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006491 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6492 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006493
6494 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006495 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6496 ds_pool_ci.pNext = NULL;
6497 ds_pool_ci.maxSets = 1;
6498 ds_pool_ci.poolSizeCount = 1;
6499 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006500
6501 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006502 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006503 ASSERT_VK_SUCCESS(err);
6504
6505 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006506 dsl_binding.binding = 0;
6507 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6508 dsl_binding.descriptorCount = 1;
6509 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6510 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006511
6512 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006513 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6514 ds_layout_ci.pNext = NULL;
6515 ds_layout_ci.bindingCount = 1;
6516 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006517 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006518 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006519 ASSERT_VK_SUCCESS(err);
6520
6521 VkDescriptorSet descriptorSet;
6522 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006523 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006524 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006525 alloc_info.descriptorPool = ds_pool;
6526 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006527 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006528 ASSERT_VK_SUCCESS(err);
6529
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006530 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006531 VkWriteDescriptorSet descriptor_write;
6532 memset(&descriptor_write, 0, sizeof(descriptor_write));
6533 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6534 descriptor_write.dstSet = descriptorSet;
6535 descriptor_write.dstBinding = 0;
6536 descriptor_write.descriptorCount = 1;
6537 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6538 descriptor_write.pTexelBufferView = &view;
6539
6540 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6541
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006542 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006543
6544 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6545 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6546}
6547
Mark Youngd339ba32016-05-30 13:28:35 -06006548TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006549 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 -06006550
6551 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006552 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006553 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006554
6555 ASSERT_NO_FATAL_FAILURE(InitState());
6556
6557 // Create a buffer with no bound memory and then attempt to create
6558 // a buffer view.
6559 VkBufferCreateInfo buff_ci = {};
6560 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006561 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006562 buff_ci.size = 256;
6563 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6564 VkBuffer buffer;
6565 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6566 ASSERT_VK_SUCCESS(err);
6567
6568 VkBufferViewCreateInfo buff_view_ci = {};
6569 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6570 buff_view_ci.buffer = buffer;
6571 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6572 buff_view_ci.range = VK_WHOLE_SIZE;
6573 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006574 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006575
6576 m_errorMonitor->VerifyFound();
6577 vkDestroyBuffer(m_device->device(), buffer, NULL);
6578 // If last error is success, it still created the view, so delete it.
6579 if (err == VK_SUCCESS) {
6580 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6581 }
6582}
6583
Karl Schultz6addd812016-02-02 17:17:23 -07006584TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6585 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6586 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006587 // 1. No dynamicOffset supplied
6588 // 2. Too many dynamicOffsets supplied
6589 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006590 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6592 " requires 1 dynamicOffsets, but only "
6593 "0 dynamicOffsets are left in "
6594 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006595
6596 ASSERT_NO_FATAL_FAILURE(InitState());
6597 ASSERT_NO_FATAL_FAILURE(InitViewport());
6598 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6599
6600 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006601 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6602 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006603
6604 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006605 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6606 ds_pool_ci.pNext = NULL;
6607 ds_pool_ci.maxSets = 1;
6608 ds_pool_ci.poolSizeCount = 1;
6609 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006610
6611 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006612 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006613 ASSERT_VK_SUCCESS(err);
6614
6615 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006616 dsl_binding.binding = 0;
6617 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6618 dsl_binding.descriptorCount = 1;
6619 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6620 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006621
6622 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006623 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6624 ds_layout_ci.pNext = NULL;
6625 ds_layout_ci.bindingCount = 1;
6626 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006627 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006628 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006629 ASSERT_VK_SUCCESS(err);
6630
6631 VkDescriptorSet descriptorSet;
6632 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006633 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006634 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006635 alloc_info.descriptorPool = ds_pool;
6636 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006637 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638 ASSERT_VK_SUCCESS(err);
6639
6640 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006641 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6642 pipeline_layout_ci.pNext = NULL;
6643 pipeline_layout_ci.setLayoutCount = 1;
6644 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006645
6646 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006647 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006648 ASSERT_VK_SUCCESS(err);
6649
6650 // Create a buffer to update the descriptor with
6651 uint32_t qfi = 0;
6652 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006653 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6654 buffCI.size = 1024;
6655 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6656 buffCI.queueFamilyIndexCount = 1;
6657 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006658
6659 VkBuffer dyub;
6660 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6661 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006662 // Allocate memory and bind to buffer so we can make it to the appropriate
6663 // error
6664 VkMemoryAllocateInfo mem_alloc = {};
6665 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6666 mem_alloc.pNext = NULL;
6667 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006668 mem_alloc.memoryTypeIndex = 0;
6669
6670 VkMemoryRequirements memReqs;
6671 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006672 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006673 if (!pass) {
6674 vkDestroyBuffer(m_device->device(), dyub, NULL);
6675 return;
6676 }
6677
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006678 VkDeviceMemory mem;
6679 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6680 ASSERT_VK_SUCCESS(err);
6681 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6682 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006683 // Correctly update descriptor to avoid "NOT_UPDATED" error
6684 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006685 buffInfo.buffer = dyub;
6686 buffInfo.offset = 0;
6687 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006688
6689 VkWriteDescriptorSet descriptor_write;
6690 memset(&descriptor_write, 0, sizeof(descriptor_write));
6691 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6692 descriptor_write.dstSet = descriptorSet;
6693 descriptor_write.dstBinding = 0;
6694 descriptor_write.descriptorCount = 1;
6695 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6696 descriptor_write.pBufferInfo = &buffInfo;
6697
6698 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6699
Tony Barbour552f6c02016-12-21 14:34:07 -07006700 m_commandBuffer->BeginCommandBuffer();
6701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006702 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6703 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006704 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006705 uint32_t pDynOff[2] = {512, 756};
6706 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6708 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6709 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6710 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006711 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006712 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006713 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6714 " dynamic offset 512 combined with "
6715 "offset 0 and range 1024 that "
6716 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006717 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006718 char const *vsSource =
6719 "#version 450\n"
6720 "\n"
6721 "out gl_PerVertex { \n"
6722 " vec4 gl_Position;\n"
6723 "};\n"
6724 "void main(){\n"
6725 " gl_Position = vec4(1);\n"
6726 "}\n";
6727 char const *fsSource =
6728 "#version 450\n"
6729 "\n"
6730 "layout(location=0) out vec4 x;\n"
6731 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6732 "void main(){\n"
6733 " x = vec4(bar.y);\n"
6734 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006735 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6736 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6737 VkPipelineObj pipe(m_device);
6738 pipe.AddShader(&vs);
6739 pipe.AddShader(&fs);
6740 pipe.AddColorAttachment();
6741 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6742
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006743 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6744 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6745 VkRect2D scissor = {{0, 0}, {16, 16}};
6746 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6747
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006748 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006749 // This update should succeed, but offset size of 512 will overstep buffer
6750 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006751 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6752 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006753 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006754 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006755
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006756 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006757 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006758
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006759 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006760 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006761 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6762}
6763
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006764TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006765 TEST_DESCRIPTION(
6766 "Attempt to update a descriptor with a non-sparse buffer "
6767 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006768 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006770 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6772 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006773
6774 ASSERT_NO_FATAL_FAILURE(InitState());
6775 ASSERT_NO_FATAL_FAILURE(InitViewport());
6776 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6777
6778 VkDescriptorPoolSize ds_type_count = {};
6779 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6780 ds_type_count.descriptorCount = 1;
6781
6782 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6783 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6784 ds_pool_ci.pNext = NULL;
6785 ds_pool_ci.maxSets = 1;
6786 ds_pool_ci.poolSizeCount = 1;
6787 ds_pool_ci.pPoolSizes = &ds_type_count;
6788
6789 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006790 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006791 ASSERT_VK_SUCCESS(err);
6792
6793 VkDescriptorSetLayoutBinding dsl_binding = {};
6794 dsl_binding.binding = 0;
6795 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6796 dsl_binding.descriptorCount = 1;
6797 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6798 dsl_binding.pImmutableSamplers = NULL;
6799
6800 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6801 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6802 ds_layout_ci.pNext = NULL;
6803 ds_layout_ci.bindingCount = 1;
6804 ds_layout_ci.pBindings = &dsl_binding;
6805 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006806 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006807 ASSERT_VK_SUCCESS(err);
6808
6809 VkDescriptorSet descriptorSet;
6810 VkDescriptorSetAllocateInfo alloc_info = {};
6811 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6812 alloc_info.descriptorSetCount = 1;
6813 alloc_info.descriptorPool = ds_pool;
6814 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006815 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006816 ASSERT_VK_SUCCESS(err);
6817
6818 // Create a buffer to update the descriptor with
6819 uint32_t qfi = 0;
6820 VkBufferCreateInfo buffCI = {};
6821 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6822 buffCI.size = 1024;
6823 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6824 buffCI.queueFamilyIndexCount = 1;
6825 buffCI.pQueueFamilyIndices = &qfi;
6826
6827 VkBuffer dyub;
6828 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6829 ASSERT_VK_SUCCESS(err);
6830
6831 // Attempt to update descriptor without binding memory to it
6832 VkDescriptorBufferInfo buffInfo = {};
6833 buffInfo.buffer = dyub;
6834 buffInfo.offset = 0;
6835 buffInfo.range = 1024;
6836
6837 VkWriteDescriptorSet descriptor_write;
6838 memset(&descriptor_write, 0, sizeof(descriptor_write));
6839 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6840 descriptor_write.dstSet = descriptorSet;
6841 descriptor_write.dstBinding = 0;
6842 descriptor_write.descriptorCount = 1;
6843 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6844 descriptor_write.pBufferInfo = &buffInfo;
6845
6846 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6847 m_errorMonitor->VerifyFound();
6848
6849 vkDestroyBuffer(m_device->device(), dyub, NULL);
6850 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6851 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6852}
6853
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006854TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006855 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006856 ASSERT_NO_FATAL_FAILURE(InitState());
6857 ASSERT_NO_FATAL_FAILURE(InitViewport());
6858 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6859
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006860 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006861 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006862 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6863 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6864 pipeline_layout_ci.pushConstantRangeCount = 1;
6865 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6866
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006867 //
6868 // Check for invalid push constant ranges in pipeline layouts.
6869 //
6870 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006871 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006872 char const *msg;
6873 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006874
Karl Schultzc81037d2016-05-12 08:11:23 -06006875 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6876 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6877 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6878 "vkCreatePipelineLayout() call has push constants index 0 with "
6879 "size 0."},
6880 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6881 "vkCreatePipelineLayout() call has push constants index 0 with "
6882 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006883 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006884 "vkCreatePipelineLayout() call has push constants index 0 with "
6885 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006886 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006887 "vkCreatePipelineLayout() call has push constants index 0 with "
6888 "size 0."},
6889 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6890 "vkCreatePipelineLayout() call has push constants index 0 with "
6891 "offset 1. Offset must"},
6892 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6893 "vkCreatePipelineLayout() call has push constants index 0 "
6894 "with offset "},
6895 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6896 "vkCreatePipelineLayout() call has push constants "
6897 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006898 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006899 "vkCreatePipelineLayout() call has push constants index 0 "
6900 "with offset "},
6901 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6902 "vkCreatePipelineLayout() call has push "
6903 "constants index 0 with offset "},
6904 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6905 "vkCreatePipelineLayout() call has push "
6906 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006907 }};
6908
6909 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006910 for (const auto &iter : range_tests) {
6911 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6913 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006914 m_errorMonitor->VerifyFound();
6915 if (VK_SUCCESS == err) {
6916 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6917 }
6918 }
6919
6920 // Check for invalid stage flag
6921 pc_range.offset = 0;
6922 pc_range.size = 16;
6923 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006924 m_errorMonitor->SetDesiredFailureMsg(
6925 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6926 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006927 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006928 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006929 if (VK_SUCCESS == err) {
6930 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6931 }
6932
Karl Schultzc59b72d2017-02-24 15:45:05 -07006933 // Check for duplicate stage flags in a list of push constant ranges.
6934 // A shader can only have one push constant block and that block is mapped
6935 // to the push constant range that has that shader's stage flag set.
6936 // The shader's stage flag can only appear once in all the ranges, so the
6937 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006938 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006939 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006940 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006941 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006942 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006943 // Overlapping ranges are OK, but a stage flag can appear only once.
6944 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6945 {
6946 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6947 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6948 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6949 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006950 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006951 {
6952 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6953 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6954 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6955 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6956 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6957 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6958 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6959 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6960 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6961 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6962 }},
6963 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6964 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6965 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6966 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6967 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6968 {
6969 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6970 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6971 }},
6972 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6973 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6974 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6975 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6976 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6977 {
6978 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6979 }},
6980 },
6981 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006982
Karl Schultzc59b72d2017-02-24 15:45:05 -07006983 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006984 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006985 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006987 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006988 m_errorMonitor->VerifyFound();
6989 if (VK_SUCCESS == err) {
6990 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6991 }
6992 }
6993
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006994 //
6995 // CmdPushConstants tests
6996 //
6997
Karl Schultzc59b72d2017-02-24 15:45:05 -07006998 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006999 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07007000 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007001 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007002 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007003 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007004 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007005 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07007006
7007 const uint8_t dummy_values[100] = {};
7008
7009 m_commandBuffer->BeginCommandBuffer();
7010 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007011
7012 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007013 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007015 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007016 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007017
Karl Schultzc59b72d2017-02-24 15:45:05 -07007018 m_errorMonitor->ExpectSuccess();
7019 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7020 m_errorMonitor->VerifyNotFound();
7021 m_errorMonitor->ExpectSuccess();
7022 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7023 m_errorMonitor->VerifyNotFound();
7024 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7025 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7026 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7027 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7028 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7029 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7030 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007031 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007032 for (const auto &iter : cmd_range_tests) {
7033 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7034 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7035 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007036 m_errorMonitor->VerifyFound();
7037 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007038
Tony Barbour552f6c02016-12-21 14:34:07 -07007039 m_commandBuffer->EndRenderPass();
7040 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007041 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007042}
7043
Karl Schultz6addd812016-02-02 17:17:23 -07007044TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007045 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007046 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007047
7048 ASSERT_NO_FATAL_FAILURE(InitState());
7049 ASSERT_NO_FATAL_FAILURE(InitViewport());
7050 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7051
7052 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7053 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007054 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7055 ds_type_count[0].descriptorCount = 10;
7056 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7057 ds_type_count[1].descriptorCount = 2;
7058 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7059 ds_type_count[2].descriptorCount = 2;
7060 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7061 ds_type_count[3].descriptorCount = 5;
7062 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7063 // type
7064 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7065 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7066 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007067
7068 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007069 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7070 ds_pool_ci.pNext = NULL;
7071 ds_pool_ci.maxSets = 5;
7072 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7073 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007074
7075 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007076 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007077 ASSERT_VK_SUCCESS(err);
7078
7079 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7080 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007081 dsl_binding[0].binding = 0;
7082 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7083 dsl_binding[0].descriptorCount = 5;
7084 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7085 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007086
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007087 // Create layout identical to set0 layout but w/ different stageFlags
7088 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007089 dsl_fs_stage_only.binding = 0;
7090 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7091 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007092 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7093 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007094 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007095 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007096 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7097 ds_layout_ci.pNext = NULL;
7098 ds_layout_ci.bindingCount = 1;
7099 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 static const uint32_t NUM_LAYOUTS = 4;
7101 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007102 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007103 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7104 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007105 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007106 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007107 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007108 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007109 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007110 dsl_binding[0].binding = 0;
7111 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007112 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007113 dsl_binding[1].binding = 1;
7114 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7115 dsl_binding[1].descriptorCount = 2;
7116 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7117 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007118 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007119 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ASSERT_VK_SUCCESS(err);
7122 dsl_binding[0].binding = 0;
7123 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007124 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007125 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007126 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007127 ASSERT_VK_SUCCESS(err);
7128 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007129 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131 ASSERT_VK_SUCCESS(err);
7132
7133 static const uint32_t NUM_SETS = 4;
7134 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7135 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007136 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007137 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007138 alloc_info.descriptorPool = ds_pool;
7139 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007140 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007141 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007142 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007143 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007144 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007147
7148 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007149 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7150 pipeline_layout_ci.pNext = NULL;
7151 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7152 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007153
7154 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007156 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007157 // Create pipelineLayout with only one setLayout
7158 pipeline_layout_ci.setLayoutCount = 1;
7159 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007161 ASSERT_VK_SUCCESS(err);
7162 // Create pipelineLayout with 2 descriptor setLayout at index 0
7163 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7164 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007166 ASSERT_VK_SUCCESS(err);
7167 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7168 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7169 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007170 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007171 ASSERT_VK_SUCCESS(err);
7172 // Create pipelineLayout with UB type, but stageFlags for FS only
7173 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7174 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007175 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007176 ASSERT_VK_SUCCESS(err);
7177 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7178 VkDescriptorSetLayout pl_bad_s0[2] = {};
7179 pl_bad_s0[0] = ds_layout_fs_only;
7180 pl_bad_s0[1] = ds_layout[1];
7181 pipeline_layout_ci.setLayoutCount = 2;
7182 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7183 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007184 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007185 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007186
Tobin Ehlis88452832015-12-03 09:40:56 -07007187 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007188 char const *vsSource =
7189 "#version 450\n"
7190 "\n"
7191 "out gl_PerVertex {\n"
7192 " vec4 gl_Position;\n"
7193 "};\n"
7194 "void main(){\n"
7195 " gl_Position = vec4(1);\n"
7196 "}\n";
7197 char const *fsSource =
7198 "#version 450\n"
7199 "\n"
7200 "layout(location=0) out vec4 x;\n"
7201 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7202 "void main(){\n"
7203 " x = vec4(bar.y);\n"
7204 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007205 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7206 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007207 VkPipelineObj pipe(m_device);
7208 pipe.AddShader(&vs);
7209 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007210 pipe.AddColorAttachment();
7211 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007212
Tony Barbour552f6c02016-12-21 14:34:07 -07007213 m_commandBuffer->BeginCommandBuffer();
7214 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007215
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007216 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007217 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7218 // of PSO
7219 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7220 // cmd_pipeline.c
7221 // due to the fact that cmd_alloc_dset_data() has not been called in
7222 // cmd_bind_graphics_pipeline()
7223 // TODO : Want to cause various binding incompatibility issues here to test
7224 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007225 // First cause various verify_layout_compatibility() fails
7226 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007227 // verify_set_layout_compatibility fail cases:
7228 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007230 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7231 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007232 m_errorMonitor->VerifyFound();
7233
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007234 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7236 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7237 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007238 m_errorMonitor->VerifyFound();
7239
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007240 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007241 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7242 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007243 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7244 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7245 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007246 m_errorMonitor->VerifyFound();
7247
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007248 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7249 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007250 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7251 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7252 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007253 m_errorMonitor->VerifyFound();
7254
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007255 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7256 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007257 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7258 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7260 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
7262
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007263 // Cause INFO messages due to disturbing previously bound Sets
7264 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007265 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7266 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007267 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7270 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007271 m_errorMonitor->VerifyFound();
7272
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007273 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7274 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007275 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007276 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7277 " newly bound as set #0 so set #1 and "
7278 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007279 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7280 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007281 m_errorMonitor->VerifyFound();
7282
Tobin Ehlis10fad692016-07-07 12:00:36 -06007283 // Now that we're done actively using the pipelineLayout that gfx pipeline
7284 // was created with, we should be able to delete it. Do that now to verify
7285 // that validation obeys pipelineLayout lifetime
7286 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7287
Tobin Ehlis88452832015-12-03 09:40:56 -07007288 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007289 // 1. Error due to not binding required set (we actually use same code as
7290 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007291 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7292 &descriptorSet[0], 0, NULL);
7293 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7294 &descriptorSet[1], 0, NULL);
7295 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 -07007296
7297 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7298 VkRect2D scissor = {{0, 0}, {16, 16}};
7299 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7300 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7301
Tobin Ehlis88452832015-12-03 09:40:56 -07007302 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007303 m_errorMonitor->VerifyFound();
7304
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007305 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007306 // 2. Error due to bound set not being compatible with PSO's
7307 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007308 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7309 &descriptorSet[0], 0, NULL);
7310 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007311 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007312 m_errorMonitor->VerifyFound();
7313
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007314 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007315 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007316 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7317 }
7318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007319 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7320 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7321}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007322
Karl Schultz6addd812016-02-02 17:17:23 -07007323TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007324 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7325 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007326
7327 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007328 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007329 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007330 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007331
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007332 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007333}
7334
Karl Schultz6addd812016-02-02 17:17:23 -07007335TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7336 VkResult err;
7337 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007338
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007340
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007341 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007342
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007343 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007344 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007345 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007346 cmd.commandPool = m_commandPool;
7347 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007348 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007349
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007350 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007351 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007352
7353 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007354 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007355 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7356
7357 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007358 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007359 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007360 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 -07007361 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007362
7363 // The error should be caught by validation of the BeginCommandBuffer call
7364 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7365
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007366 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007367 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007368}
7369
Karl Schultz6addd812016-02-02 17:17:23 -07007370TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007371 // Cause error due to Begin while recording CB
7372 // Then cause 2 errors for attempting to reset CB w/o having
7373 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7374 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007375 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007376
7377 ASSERT_NO_FATAL_FAILURE(InitState());
7378
7379 // Calls AllocateCommandBuffers
7380 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7381
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007382 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007383 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007384 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7385 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007386 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7387 cmd_buf_info.pNext = NULL;
7388 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007389 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007390
7391 // Begin CB to transition to recording state
7392 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7393 // Can't re-begin. This should trigger error
7394 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007395 m_errorMonitor->VerifyFound();
7396
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007397 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007398 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007399 // Reset attempt will trigger error due to incorrect CommandPool state
7400 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007401 m_errorMonitor->VerifyFound();
7402
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007404 // Transition CB to RECORDED state
7405 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7406 // Now attempting to Begin will implicitly reset, which triggers error
7407 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007408 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007409}
7410
Karl Schultz6addd812016-02-02 17:17:23 -07007411TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007412 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007413 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007414
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7416 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007417
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007418 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007419 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007420
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007421 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007422 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7423 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007424
7425 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007426 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7427 ds_pool_ci.pNext = NULL;
7428 ds_pool_ci.maxSets = 1;
7429 ds_pool_ci.poolSizeCount = 1;
7430 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007431
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007432 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007433 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007434 ASSERT_VK_SUCCESS(err);
7435
Tony Barboureb254902015-07-15 12:50:33 -06007436 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007437 dsl_binding.binding = 0;
7438 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7439 dsl_binding.descriptorCount = 1;
7440 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7441 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007442
Tony Barboureb254902015-07-15 12:50:33 -06007443 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007444 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7445 ds_layout_ci.pNext = NULL;
7446 ds_layout_ci.bindingCount = 1;
7447 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007448
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007449 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007450 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007451 ASSERT_VK_SUCCESS(err);
7452
7453 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007454 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007455 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007456 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007457 alloc_info.descriptorPool = ds_pool;
7458 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007459 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007460 ASSERT_VK_SUCCESS(err);
7461
Tony Barboureb254902015-07-15 12:50:33 -06007462 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007463 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7464 pipeline_layout_ci.setLayoutCount = 1;
7465 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007466
7467 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007468 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007469 ASSERT_VK_SUCCESS(err);
7470
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007471 VkViewport vp = {}; // Just need dummy vp to point to
7472 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007473
7474 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007475 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7476 vp_state_ci.scissorCount = 1;
7477 vp_state_ci.pScissors = &sc;
7478 vp_state_ci.viewportCount = 1;
7479 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007480
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007481 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7482 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7483 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7484 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7485 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7486 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007487 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007488 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007489 rs_state_ci.lineWidth = 1.0f;
7490
7491 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7492 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7493 vi_ci.pNext = nullptr;
7494 vi_ci.vertexBindingDescriptionCount = 0;
7495 vi_ci.pVertexBindingDescriptions = nullptr;
7496 vi_ci.vertexAttributeDescriptionCount = 0;
7497 vi_ci.pVertexAttributeDescriptions = nullptr;
7498
7499 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7500 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7501 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7502
7503 VkPipelineShaderStageCreateInfo shaderStages[2];
7504 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7505
7506 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7507 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007508 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007509 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007510
Tony Barboureb254902015-07-15 12:50:33 -06007511 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007512 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7513 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007514 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007515 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7516 gp_ci.layout = pipeline_layout;
7517 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007518 gp_ci.pVertexInputState = &vi_ci;
7519 gp_ci.pInputAssemblyState = &ia_ci;
7520
7521 gp_ci.stageCount = 1;
7522 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007523
7524 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007525 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7526 pc_ci.initialDataSize = 0;
7527 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007528
7529 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007530 VkPipelineCache pipelineCache;
7531
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007532 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007533 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007534 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007535 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007536
Chia-I Wuf7458c52015-10-26 21:10:41 +08007537 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7538 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7539 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7540 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007541}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007542
Tobin Ehlis912df022015-09-17 08:46:18 -06007543/*// TODO : This test should be good, but needs Tess support in compiler to run
7544TEST_F(VkLayerTest, InvalidPatchControlPoints)
7545{
7546 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007547 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007548
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007549 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007550 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7551primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007552
Tobin Ehlis912df022015-09-17 08:46:18 -06007553 ASSERT_NO_FATAL_FAILURE(InitState());
7554 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007555
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007556 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007557 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007558 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007559
7560 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7561 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7562 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007563 ds_pool_ci.poolSizeCount = 1;
7564 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007565
7566 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007567 err = vkCreateDescriptorPool(m_device->device(),
7568VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007569 ASSERT_VK_SUCCESS(err);
7570
7571 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007572 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007573 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007574 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007575 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7576 dsl_binding.pImmutableSamplers = NULL;
7577
7578 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007579 ds_layout_ci.sType =
7580VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007581 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007582 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007583 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007584
7585 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007586 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7587&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007588 ASSERT_VK_SUCCESS(err);
7589
7590 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007591 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7592VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007593 ASSERT_VK_SUCCESS(err);
7594
7595 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007596 pipeline_layout_ci.sType =
7597VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007598 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007599 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007600 pipeline_layout_ci.pSetLayouts = &ds_layout;
7601
7602 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007603 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7604&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007605 ASSERT_VK_SUCCESS(err);
7606
7607 VkPipelineShaderStageCreateInfo shaderStages[3];
7608 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7609
Karl Schultz6addd812016-02-02 17:17:23 -07007610 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7611this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007612 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007613 VkShaderObj
7614tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7615this);
7616 VkShaderObj
7617te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7618this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007619
Karl Schultz6addd812016-02-02 17:17:23 -07007620 shaderStages[0].sType =
7621VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007622 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007623 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007624 shaderStages[1].sType =
7625VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007626 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007627 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007628 shaderStages[2].sType =
7629VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007630 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007631 shaderStages[2].shader = te.handle();
7632
7633 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007634 iaCI.sType =
7635VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007636 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007637
7638 VkPipelineTessellationStateCreateInfo tsCI = {};
7639 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7640 tsCI.patchControlPoints = 0; // This will cause an error
7641
7642 VkGraphicsPipelineCreateInfo gp_ci = {};
7643 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7644 gp_ci.pNext = NULL;
7645 gp_ci.stageCount = 3;
7646 gp_ci.pStages = shaderStages;
7647 gp_ci.pVertexInputState = NULL;
7648 gp_ci.pInputAssemblyState = &iaCI;
7649 gp_ci.pTessellationState = &tsCI;
7650 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007651 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007652 gp_ci.pMultisampleState = NULL;
7653 gp_ci.pDepthStencilState = NULL;
7654 gp_ci.pColorBlendState = NULL;
7655 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7656 gp_ci.layout = pipeline_layout;
7657 gp_ci.renderPass = renderPass();
7658
7659 VkPipelineCacheCreateInfo pc_ci = {};
7660 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7661 pc_ci.pNext = NULL;
7662 pc_ci.initialSize = 0;
7663 pc_ci.initialData = 0;
7664 pc_ci.maxSize = 0;
7665
7666 VkPipeline pipeline;
7667 VkPipelineCache pipelineCache;
7668
Karl Schultz6addd812016-02-02 17:17:23 -07007669 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7670&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007671 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007672 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7673&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007674
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007675 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007676
Chia-I Wuf7458c52015-10-26 21:10:41 +08007677 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7678 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7679 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7680 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007681}
7682*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007683
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007684TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007685 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007686
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007687 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007688
Tobin Ehlise68360f2015-10-01 11:15:13 -06007689 ASSERT_NO_FATAL_FAILURE(InitState());
7690 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007692 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007693 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7694 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007695
7696 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007697 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7698 ds_pool_ci.maxSets = 1;
7699 ds_pool_ci.poolSizeCount = 1;
7700 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007701
7702 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007703 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007704 ASSERT_VK_SUCCESS(err);
7705
7706 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007707 dsl_binding.binding = 0;
7708 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7709 dsl_binding.descriptorCount = 1;
7710 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007711
7712 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007713 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7714 ds_layout_ci.bindingCount = 1;
7715 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007716
7717 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007718 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007719 ASSERT_VK_SUCCESS(err);
7720
7721 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007722 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007723 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007724 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007725 alloc_info.descriptorPool = ds_pool;
7726 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007727 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007728 ASSERT_VK_SUCCESS(err);
7729
7730 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007731 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7732 pipeline_layout_ci.setLayoutCount = 1;
7733 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007734
7735 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007736 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007737 ASSERT_VK_SUCCESS(err);
7738
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007739 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007740 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007741 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007742 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007743 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007744 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007745
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007746 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7747 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7748 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7749 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7750 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7751 rs_state_ci.depthClampEnable = VK_FALSE;
7752 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7753 rs_state_ci.depthBiasEnable = VK_FALSE;
7754
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007755 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7756 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7757 vi_ci.pNext = nullptr;
7758 vi_ci.vertexBindingDescriptionCount = 0;
7759 vi_ci.pVertexBindingDescriptions = nullptr;
7760 vi_ci.vertexAttributeDescriptionCount = 0;
7761 vi_ci.pVertexAttributeDescriptions = nullptr;
7762
7763 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7764 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7765 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7766
7767 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7768 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7769 pipe_ms_state_ci.pNext = NULL;
7770 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7771 pipe_ms_state_ci.sampleShadingEnable = 0;
7772 pipe_ms_state_ci.minSampleShading = 1.0;
7773 pipe_ms_state_ci.pSampleMask = NULL;
7774
Cody Northropeb3a6c12015-10-05 14:44:45 -06007775 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007776 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007777
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007778 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007779 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007780 shaderStages[0] = vs.GetStageCreateInfo();
7781 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007782
7783 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007784 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7785 gp_ci.stageCount = 2;
7786 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007787 gp_ci.pVertexInputState = &vi_ci;
7788 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007789 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007790 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007791 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007792 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7793 gp_ci.layout = pipeline_layout;
7794 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007795
7796 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007797 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007798
7799 VkPipeline pipeline;
7800 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007801 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007802 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007803
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007804 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007805 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007806
7807 // Check case where multiViewport is disabled and viewport count is not 1
7808 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7810 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7811 vp_state_ci.scissorCount = 0;
7812 vp_state_ci.viewportCount = 0;
7813 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7814 m_errorMonitor->VerifyFound();
7815 } else {
7816 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007817 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007818 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007819 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007820
7821 // Check is that viewportcount and scissorcount match
7822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7823 vp_state_ci.scissorCount = 1;
7824 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7825 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7826 m_errorMonitor->VerifyFound();
7827
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007828 // Check case where multiViewport is enabled and viewport count is greater than max
7829 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7832 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7833 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7834 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7835 m_errorMonitor->VerifyFound();
7836 }
7837 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007838
Chia-I Wuf7458c52015-10-26 21:10:41 +08007839 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7840 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7841 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7842 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007843}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007844
7845// 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
7846// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007847TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007848 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007849
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007850 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7851
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007853
Tobin Ehlise68360f2015-10-01 11:15:13 -06007854 ASSERT_NO_FATAL_FAILURE(InitState());
7855 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007857 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007858 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7859 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007860
7861 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007862 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7863 ds_pool_ci.maxSets = 1;
7864 ds_pool_ci.poolSizeCount = 1;
7865 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007866
7867 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007868 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007869 ASSERT_VK_SUCCESS(err);
7870
7871 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007872 dsl_binding.binding = 0;
7873 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7874 dsl_binding.descriptorCount = 1;
7875 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007876
7877 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007878 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7879 ds_layout_ci.bindingCount = 1;
7880 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007881
7882 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007883 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007884 ASSERT_VK_SUCCESS(err);
7885
7886 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007887 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007888 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007889 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007890 alloc_info.descriptorPool = ds_pool;
7891 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007892 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007893 ASSERT_VK_SUCCESS(err);
7894
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007895 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7896 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7897 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7898
7899 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7900 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7901 vi_ci.pNext = nullptr;
7902 vi_ci.vertexBindingDescriptionCount = 0;
7903 vi_ci.pVertexBindingDescriptions = nullptr;
7904 vi_ci.vertexAttributeDescriptionCount = 0;
7905 vi_ci.pVertexAttributeDescriptions = nullptr;
7906
7907 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7908 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7909 pipe_ms_state_ci.pNext = NULL;
7910 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7911 pipe_ms_state_ci.sampleShadingEnable = 0;
7912 pipe_ms_state_ci.minSampleShading = 1.0;
7913 pipe_ms_state_ci.pSampleMask = NULL;
7914
Tobin Ehlise68360f2015-10-01 11:15:13 -06007915 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007916 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7917 pipeline_layout_ci.setLayoutCount = 1;
7918 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007919
7920 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007921 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007922 ASSERT_VK_SUCCESS(err);
7923
7924 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7925 // Set scissor as dynamic to avoid second error
7926 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007927 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7928 dyn_state_ci.dynamicStateCount = 1;
7929 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007930
Cody Northropeb3a6c12015-10-05 14:44:45 -06007931 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007932 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007934 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007935 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7936 // 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 +08007937 shaderStages[0] = vs.GetStageCreateInfo();
7938 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007939
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007940 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7941 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7942 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7943 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7944 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7945 rs_state_ci.depthClampEnable = VK_FALSE;
7946 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7947 rs_state_ci.depthBiasEnable = VK_FALSE;
7948
Tobin Ehlise68360f2015-10-01 11:15:13 -06007949 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007950 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7951 gp_ci.stageCount = 2;
7952 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007953 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007954 // Not setting VP state w/o dynamic vp state should cause validation error
7955 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007956 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007957 gp_ci.pVertexInputState = &vi_ci;
7958 gp_ci.pInputAssemblyState = &ia_ci;
7959 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007960 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7961 gp_ci.layout = pipeline_layout;
7962 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007963
7964 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007965 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007966
7967 VkPipeline pipeline;
7968 VkPipelineCache pipelineCache;
7969
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007970 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007971 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007972 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007973
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007974 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007975
Chia-I Wuf7458c52015-10-26 21:10:41 +08007976 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7977 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7978 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7979 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007980}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007981
7982// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7983// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007984TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7985 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007986
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007987 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007988
Tobin Ehlise68360f2015-10-01 11:15:13 -06007989 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007990
7991 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007992 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007993 return;
7994 }
7995
Tobin Ehlise68360f2015-10-01 11:15:13 -06007996 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007998 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007999 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8000 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008001
8002 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008003 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8004 ds_pool_ci.maxSets = 1;
8005 ds_pool_ci.poolSizeCount = 1;
8006 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008007
8008 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008009 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008010 ASSERT_VK_SUCCESS(err);
8011
8012 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008013 dsl_binding.binding = 0;
8014 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8015 dsl_binding.descriptorCount = 1;
8016 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008017
8018 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008019 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8020 ds_layout_ci.bindingCount = 1;
8021 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008022
8023 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008024 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008025 ASSERT_VK_SUCCESS(err);
8026
8027 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008028 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008029 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008030 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008031 alloc_info.descriptorPool = ds_pool;
8032 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008033 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008034 ASSERT_VK_SUCCESS(err);
8035
8036 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008037 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8038 pipeline_layout_ci.setLayoutCount = 1;
8039 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008040
8041 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008043 ASSERT_VK_SUCCESS(err);
8044
8045 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008046 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8047 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008048 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008049 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008050 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008051
8052 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8053 // Set scissor as dynamic to avoid that error
8054 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008055 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8056 dyn_state_ci.dynamicStateCount = 1;
8057 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008058
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008059 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8060 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8061 pipe_ms_state_ci.pNext = NULL;
8062 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8063 pipe_ms_state_ci.sampleShadingEnable = 0;
8064 pipe_ms_state_ci.minSampleShading = 1.0;
8065 pipe_ms_state_ci.pSampleMask = NULL;
8066
Cody Northropeb3a6c12015-10-05 14:44:45 -06008067 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008068 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008069
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008070 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008071 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8072 // 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 +08008073 shaderStages[0] = vs.GetStageCreateInfo();
8074 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008075
Cody Northropf6622dc2015-10-06 10:33:21 -06008076 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8077 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8078 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008079 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008080 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008081 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008082 vi_ci.pVertexAttributeDescriptions = nullptr;
8083
8084 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8085 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8086 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8087
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008088 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008089 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008090 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008091 rs_ci.pNext = nullptr;
8092
Mark Youngc89c6312016-03-31 16:03:20 -06008093 VkPipelineColorBlendAttachmentState att = {};
8094 att.blendEnable = VK_FALSE;
8095 att.colorWriteMask = 0xf;
8096
Cody Northropf6622dc2015-10-06 10:33:21 -06008097 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8098 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8099 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008100 cb_ci.attachmentCount = 1;
8101 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008102
Tobin Ehlise68360f2015-10-01 11:15:13 -06008103 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008104 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8105 gp_ci.stageCount = 2;
8106 gp_ci.pStages = shaderStages;
8107 gp_ci.pVertexInputState = &vi_ci;
8108 gp_ci.pInputAssemblyState = &ia_ci;
8109 gp_ci.pViewportState = &vp_state_ci;
8110 gp_ci.pRasterizationState = &rs_ci;
8111 gp_ci.pColorBlendState = &cb_ci;
8112 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008113 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008114 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8115 gp_ci.layout = pipeline_layout;
8116 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008117
8118 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008119 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008120
8121 VkPipeline pipeline;
8122 VkPipelineCache pipelineCache;
8123
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008124 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008125 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008126 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008127
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008128 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008129
Tobin Ehlisd332f282015-10-02 11:00:56 -06008130 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008131 // First need to successfully create the PSO from above by setting
8132 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008133 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 -07008134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008135 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008136 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008137 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008138 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008139 m_commandBuffer->BeginCommandBuffer();
8140 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008141 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008142 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008143 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008144 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008145 Draw(1, 0, 0, 0);
8146
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008147 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008148
8149 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8150 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8151 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8152 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008153 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008154}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008155
8156// 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 -07008157// viewportCount
8158TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8159 VkResult err;
8160
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008161 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008162
8163 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008164
8165 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008166 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008167 return;
8168 }
8169
Karl Schultz6addd812016-02-02 17:17:23 -07008170 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8171
8172 VkDescriptorPoolSize ds_type_count = {};
8173 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8174 ds_type_count.descriptorCount = 1;
8175
8176 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8177 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8178 ds_pool_ci.maxSets = 1;
8179 ds_pool_ci.poolSizeCount = 1;
8180 ds_pool_ci.pPoolSizes = &ds_type_count;
8181
8182 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008183 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008184 ASSERT_VK_SUCCESS(err);
8185
8186 VkDescriptorSetLayoutBinding dsl_binding = {};
8187 dsl_binding.binding = 0;
8188 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8189 dsl_binding.descriptorCount = 1;
8190 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8191
8192 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8193 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8194 ds_layout_ci.bindingCount = 1;
8195 ds_layout_ci.pBindings = &dsl_binding;
8196
8197 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008198 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008199 ASSERT_VK_SUCCESS(err);
8200
8201 VkDescriptorSet descriptorSet;
8202 VkDescriptorSetAllocateInfo alloc_info = {};
8203 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8204 alloc_info.descriptorSetCount = 1;
8205 alloc_info.descriptorPool = ds_pool;
8206 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008207 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008208 ASSERT_VK_SUCCESS(err);
8209
8210 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8211 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8212 pipeline_layout_ci.setLayoutCount = 1;
8213 pipeline_layout_ci.pSetLayouts = &ds_layout;
8214
8215 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008216 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008217 ASSERT_VK_SUCCESS(err);
8218
8219 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8220 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8221 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008222 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008223 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008224 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008225
8226 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8227 // Set scissor as dynamic to avoid that error
8228 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8229 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8230 dyn_state_ci.dynamicStateCount = 1;
8231 dyn_state_ci.pDynamicStates = &vp_state;
8232
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008233 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8234 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8235 pipe_ms_state_ci.pNext = NULL;
8236 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8237 pipe_ms_state_ci.sampleShadingEnable = 0;
8238 pipe_ms_state_ci.minSampleShading = 1.0;
8239 pipe_ms_state_ci.pSampleMask = NULL;
8240
Karl Schultz6addd812016-02-02 17:17:23 -07008241 VkPipelineShaderStageCreateInfo shaderStages[2];
8242 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8243
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008244 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008245 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8246 // 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 -07008247 shaderStages[0] = vs.GetStageCreateInfo();
8248 shaderStages[1] = fs.GetStageCreateInfo();
8249
8250 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8251 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8252 vi_ci.pNext = nullptr;
8253 vi_ci.vertexBindingDescriptionCount = 0;
8254 vi_ci.pVertexBindingDescriptions = nullptr;
8255 vi_ci.vertexAttributeDescriptionCount = 0;
8256 vi_ci.pVertexAttributeDescriptions = nullptr;
8257
8258 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8259 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8260 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8261
8262 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8263 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008264 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008265 rs_ci.pNext = nullptr;
8266
Mark Youngc89c6312016-03-31 16:03:20 -06008267 VkPipelineColorBlendAttachmentState att = {};
8268 att.blendEnable = VK_FALSE;
8269 att.colorWriteMask = 0xf;
8270
Karl Schultz6addd812016-02-02 17:17:23 -07008271 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8272 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8273 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008274 cb_ci.attachmentCount = 1;
8275 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008276
8277 VkGraphicsPipelineCreateInfo gp_ci = {};
8278 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8279 gp_ci.stageCount = 2;
8280 gp_ci.pStages = shaderStages;
8281 gp_ci.pVertexInputState = &vi_ci;
8282 gp_ci.pInputAssemblyState = &ia_ci;
8283 gp_ci.pViewportState = &vp_state_ci;
8284 gp_ci.pRasterizationState = &rs_ci;
8285 gp_ci.pColorBlendState = &cb_ci;
8286 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008287 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008288 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8289 gp_ci.layout = pipeline_layout;
8290 gp_ci.renderPass = renderPass();
8291
8292 VkPipelineCacheCreateInfo pc_ci = {};
8293 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8294
8295 VkPipeline pipeline;
8296 VkPipelineCache pipelineCache;
8297
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008298 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008299 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008300 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008301
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008302 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008303
8304 // Now hit second fail case where we set scissor w/ different count than PSO
8305 // First need to successfully create the PSO from above by setting
8306 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008307 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8308 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008309
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008310 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008311 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008312 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008313 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008314 m_commandBuffer->BeginCommandBuffer();
8315 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008316 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008317 VkViewport viewports[1] = {};
8318 viewports[0].width = 8;
8319 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008320 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008321 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008322 Draw(1, 0, 0, 0);
8323
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008324 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008325
Chia-I Wuf7458c52015-10-26 21:10:41 +08008326 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8327 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8328 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8329 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008330 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008331}
8332
Mark Young7394fdd2016-03-31 14:56:43 -06008333TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8334 VkResult err;
8335
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008337
8338 ASSERT_NO_FATAL_FAILURE(InitState());
8339 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8340
8341 VkDescriptorPoolSize ds_type_count = {};
8342 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8343 ds_type_count.descriptorCount = 1;
8344
8345 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8346 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8347 ds_pool_ci.maxSets = 1;
8348 ds_pool_ci.poolSizeCount = 1;
8349 ds_pool_ci.pPoolSizes = &ds_type_count;
8350
8351 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008352 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008353 ASSERT_VK_SUCCESS(err);
8354
8355 VkDescriptorSetLayoutBinding dsl_binding = {};
8356 dsl_binding.binding = 0;
8357 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8358 dsl_binding.descriptorCount = 1;
8359 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8360
8361 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8362 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8363 ds_layout_ci.bindingCount = 1;
8364 ds_layout_ci.pBindings = &dsl_binding;
8365
8366 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008367 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008368 ASSERT_VK_SUCCESS(err);
8369
8370 VkDescriptorSet descriptorSet;
8371 VkDescriptorSetAllocateInfo alloc_info = {};
8372 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8373 alloc_info.descriptorSetCount = 1;
8374 alloc_info.descriptorPool = ds_pool;
8375 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008376 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008377 ASSERT_VK_SUCCESS(err);
8378
8379 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8380 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8381 pipeline_layout_ci.setLayoutCount = 1;
8382 pipeline_layout_ci.pSetLayouts = &ds_layout;
8383
8384 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008386 ASSERT_VK_SUCCESS(err);
8387
8388 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8389 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8390 vp_state_ci.scissorCount = 1;
8391 vp_state_ci.pScissors = NULL;
8392 vp_state_ci.viewportCount = 1;
8393 vp_state_ci.pViewports = NULL;
8394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008396 // Set scissor as dynamic to avoid that error
8397 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8398 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8399 dyn_state_ci.dynamicStateCount = 2;
8400 dyn_state_ci.pDynamicStates = dynamic_states;
8401
8402 VkPipelineShaderStageCreateInfo shaderStages[2];
8403 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8404
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008405 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8406 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008407 this); // TODO - We shouldn't need a fragment shader
8408 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008409 shaderStages[0] = vs.GetStageCreateInfo();
8410 shaderStages[1] = fs.GetStageCreateInfo();
8411
8412 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8413 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8414 vi_ci.pNext = nullptr;
8415 vi_ci.vertexBindingDescriptionCount = 0;
8416 vi_ci.pVertexBindingDescriptions = nullptr;
8417 vi_ci.vertexAttributeDescriptionCount = 0;
8418 vi_ci.pVertexAttributeDescriptions = nullptr;
8419
8420 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8421 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8422 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8423
8424 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8425 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8426 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008427 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008428
Mark Young47107952016-05-02 15:59:55 -06008429 // Check too low (line width of -1.0f).
8430 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008431
8432 VkPipelineColorBlendAttachmentState att = {};
8433 att.blendEnable = VK_FALSE;
8434 att.colorWriteMask = 0xf;
8435
8436 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8437 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8438 cb_ci.pNext = nullptr;
8439 cb_ci.attachmentCount = 1;
8440 cb_ci.pAttachments = &att;
8441
8442 VkGraphicsPipelineCreateInfo gp_ci = {};
8443 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8444 gp_ci.stageCount = 2;
8445 gp_ci.pStages = shaderStages;
8446 gp_ci.pVertexInputState = &vi_ci;
8447 gp_ci.pInputAssemblyState = &ia_ci;
8448 gp_ci.pViewportState = &vp_state_ci;
8449 gp_ci.pRasterizationState = &rs_ci;
8450 gp_ci.pColorBlendState = &cb_ci;
8451 gp_ci.pDynamicState = &dyn_state_ci;
8452 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8453 gp_ci.layout = pipeline_layout;
8454 gp_ci.renderPass = renderPass();
8455
8456 VkPipelineCacheCreateInfo pc_ci = {};
8457 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8458
8459 VkPipeline pipeline;
8460 VkPipelineCache pipelineCache;
8461
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008462 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008463 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008465
8466 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008467 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008468
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008469 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008470
8471 // Check too high (line width of 65536.0f).
8472 rs_ci.lineWidth = 65536.0f;
8473
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008474 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008475 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008476 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008477
8478 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008479 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008480
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 dyn_state_ci.dynamicStateCount = 3;
8484
8485 rs_ci.lineWidth = 1.0f;
8486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008488 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008489 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008490 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008491 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008492
8493 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008494 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008495 m_errorMonitor->VerifyFound();
8496
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008497 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008498
8499 // Check too high with dynamic setting.
8500 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8501 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008502 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008503
8504 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8505 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8506 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8507 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008508 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008509}
8510
Karl Schultz6addd812016-02-02 17:17:23 -07008511TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008512 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008513 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008514 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008515
8516 ASSERT_NO_FATAL_FAILURE(InitState());
8517 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008518
Tony Barbour552f6c02016-12-21 14:34:07 -07008519 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008520 // Don't care about RenderPass handle b/c error should be flagged before
8521 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008522 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008523
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008524 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008525}
8526
Karl Schultz6addd812016-02-02 17:17:23 -07008527TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008528 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8530 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008531
8532 ASSERT_NO_FATAL_FAILURE(InitState());
8533 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008534
Tony Barbour552f6c02016-12-21 14:34:07 -07008535 m_commandBuffer->BeginCommandBuffer();
8536 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008537 // Just create a dummy Renderpass that's non-NULL so we can get to the
8538 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008539 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008540
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008541 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008542}
8543
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008544TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008545 TEST_DESCRIPTION(
8546 "Begin a renderPass where clearValueCount is less than"
8547 "the number of renderPass attachments that use loadOp"
8548 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008549
8550 ASSERT_NO_FATAL_FAILURE(InitState());
8551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8552
8553 // Create a renderPass with a single attachment that uses loadOp CLEAR
8554 VkAttachmentReference attach = {};
8555 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8556 VkSubpassDescription subpass = {};
8557 subpass.inputAttachmentCount = 1;
8558 subpass.pInputAttachments = &attach;
8559 VkRenderPassCreateInfo rpci = {};
8560 rpci.subpassCount = 1;
8561 rpci.pSubpasses = &subpass;
8562 rpci.attachmentCount = 1;
8563 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008564 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008565 // Set loadOp to CLEAR
8566 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8567 rpci.pAttachments = &attach_desc;
8568 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8569 VkRenderPass rp;
8570 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8571
8572 VkCommandBufferInheritanceInfo hinfo = {};
8573 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8574 hinfo.renderPass = VK_NULL_HANDLE;
8575 hinfo.subpass = 0;
8576 hinfo.framebuffer = VK_NULL_HANDLE;
8577 hinfo.occlusionQueryEnable = VK_FALSE;
8578 hinfo.queryFlags = 0;
8579 hinfo.pipelineStatistics = 0;
8580 VkCommandBufferBeginInfo info = {};
8581 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8582 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8583 info.pInheritanceInfo = &hinfo;
8584
8585 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8586 VkRenderPassBeginInfo rp_begin = {};
8587 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8588 rp_begin.pNext = NULL;
8589 rp_begin.renderPass = renderPass();
8590 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008591 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008592
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008594
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008595 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008596
8597 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008598
8599 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008600}
8601
Slawomir Cygan0808f392016-11-28 17:53:23 +01008602TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008603 TEST_DESCRIPTION(
8604 "Begin a renderPass where clearValueCount is greater than"
8605 "the number of renderPass attachments that use loadOp"
8606 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008607
8608 ASSERT_NO_FATAL_FAILURE(InitState());
8609 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8610
8611 // Create a renderPass with a single attachment that uses loadOp CLEAR
8612 VkAttachmentReference attach = {};
8613 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8614 VkSubpassDescription subpass = {};
8615 subpass.inputAttachmentCount = 1;
8616 subpass.pInputAttachments = &attach;
8617 VkRenderPassCreateInfo rpci = {};
8618 rpci.subpassCount = 1;
8619 rpci.pSubpasses = &subpass;
8620 rpci.attachmentCount = 1;
8621 VkAttachmentDescription attach_desc = {};
8622 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8623 // Set loadOp to CLEAR
8624 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8625 rpci.pAttachments = &attach_desc;
8626 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8627 VkRenderPass rp;
8628 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8629
8630 VkCommandBufferBeginInfo info = {};
8631 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8632 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8633
8634 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8635 VkRenderPassBeginInfo rp_begin = {};
8636 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8637 rp_begin.pNext = NULL;
8638 rp_begin.renderPass = renderPass();
8639 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008640 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008641
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008642 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8643 " has a clearValueCount of"
8644 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008645
8646 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8647
8648 m_errorMonitor->VerifyFound();
8649
8650 vkDestroyRenderPass(m_device->device(), rp, NULL);
8651}
8652
Cody Northrop3bb4d962016-05-09 16:15:57 -06008653TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008654 TEST_DESCRIPTION("End a command buffer with an active render pass");
8655
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8657 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008658
8659 ASSERT_NO_FATAL_FAILURE(InitState());
8660 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8661
Tony Barbour552f6c02016-12-21 14:34:07 -07008662 m_commandBuffer->BeginCommandBuffer();
8663 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8664 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008665
8666 m_errorMonitor->VerifyFound();
8667
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008668 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8669 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008670}
8671
Karl Schultz6addd812016-02-02 17:17:23 -07008672TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008673 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8675 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008676
8677 ASSERT_NO_FATAL_FAILURE(InitState());
8678 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008679
Tony Barbour552f6c02016-12-21 14:34:07 -07008680 m_commandBuffer->BeginCommandBuffer();
8681 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008682
8683 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008684 vk_testing::Buffer dstBuffer;
8685 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008686
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008687 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008688
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008689 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008690}
8691
Karl Schultz6addd812016-02-02 17:17:23 -07008692TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008693 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8695 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696
8697 ASSERT_NO_FATAL_FAILURE(InitState());
8698 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008699
Tony Barbour552f6c02016-12-21 14:34:07 -07008700 m_commandBuffer->BeginCommandBuffer();
8701 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008702
8703 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008704 vk_testing::Buffer dstBuffer;
8705 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008706
Karl Schultz6addd812016-02-02 17:17:23 -07008707 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008708 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8709 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8710 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008711
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008712 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008713}
8714
Karl Schultz6addd812016-02-02 17:17:23 -07008715TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008716 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8718 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008719
8720 ASSERT_NO_FATAL_FAILURE(InitState());
8721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008722
Tony Barbour552f6c02016-12-21 14:34:07 -07008723 m_commandBuffer->BeginCommandBuffer();
8724 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008725
Michael Lentine0a369f62016-02-03 16:51:46 -06008726 VkClearColorValue clear_color;
8727 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008728 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8729 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8730 const int32_t tex_width = 32;
8731 const int32_t tex_height = 32;
8732 VkImageCreateInfo image_create_info = {};
8733 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8734 image_create_info.pNext = NULL;
8735 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8736 image_create_info.format = tex_format;
8737 image_create_info.extent.width = tex_width;
8738 image_create_info.extent.height = tex_height;
8739 image_create_info.extent.depth = 1;
8740 image_create_info.mipLevels = 1;
8741 image_create_info.arrayLayers = 1;
8742 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8743 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07008744 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008745
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008746 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008747 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008749 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008751 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008752
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008753 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008754}
8755
Karl Schultz6addd812016-02-02 17:17:23 -07008756TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008757 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8759 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008760
8761 ASSERT_NO_FATAL_FAILURE(InitState());
8762 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008763
Tony Barbourf887b162017-03-09 10:06:46 -07008764 auto depth_format = find_depth_stencil_format(m_device);
8765 if (!depth_format) {
8766 printf(" No Depth + Stencil format found. Skipped.\n");
8767 return;
8768 }
8769
Tony Barbour552f6c02016-12-21 14:34:07 -07008770 m_commandBuffer->BeginCommandBuffer();
8771 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
8773 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008774 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008775 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8776 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07008777 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07008778 image_create_info.extent.width = 64;
8779 image_create_info.extent.height = 64;
8780 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8781 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008783 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008784 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008785
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008786 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008788 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8789 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008790
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008791 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008792}
8793
Karl Schultz6addd812016-02-02 17:17:23 -07008794TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008795 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008796 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008797
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8799 "vkCmdClearAttachments(): This call "
8800 "must be issued inside an active "
8801 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008802
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008803 ASSERT_NO_FATAL_FAILURE(InitState());
8804 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008805
8806 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008807 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008808 ASSERT_VK_SUCCESS(err);
8809
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008810 VkClearAttachment color_attachment;
8811 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8812 color_attachment.clearValue.color.float32[0] = 0;
8813 color_attachment.clearValue.color.float32[1] = 0;
8814 color_attachment.clearValue.color.float32[2] = 0;
8815 color_attachment.clearValue.color.float32[3] = 0;
8816 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008817 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008818 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008819
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008820 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008821}
8822
Chris Forbes3b97e932016-09-07 11:29:24 +12008823TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008824 TEST_DESCRIPTION(
8825 "Test that an error is produced when CmdNextSubpass is "
8826 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008827
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008828 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8829 "vkCmdNextSubpass(): Attempted to advance "
8830 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008831
8832 ASSERT_NO_FATAL_FAILURE(InitState());
8833 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8834
Tony Barbour552f6c02016-12-21 14:34:07 -07008835 m_commandBuffer->BeginCommandBuffer();
8836 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008837
8838 // error here.
8839 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8840 m_errorMonitor->VerifyFound();
8841
Tony Barbour552f6c02016-12-21 14:34:07 -07008842 m_commandBuffer->EndRenderPass();
8843 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008844}
8845
Chris Forbes6d624702016-09-07 13:57:05 +12008846TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008847 TEST_DESCRIPTION(
8848 "Test that an error is produced when CmdEndRenderPass is "
8849 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008850
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8852 "vkCmdEndRenderPass(): Called before reaching "
8853 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008854
8855 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008856 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8857 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008858
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008859 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008860
8861 VkRenderPass rp;
8862 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8863 ASSERT_VK_SUCCESS(err);
8864
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008865 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008866
8867 VkFramebuffer fb;
8868 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8869 ASSERT_VK_SUCCESS(err);
8870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008871 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008872
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008873 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 +12008874
8875 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8876
8877 // Error here.
8878 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8879 m_errorMonitor->VerifyFound();
8880
8881 // Clean up.
8882 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8883 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8884}
8885
Karl Schultz9e66a292016-04-21 15:57:51 -06008886TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8887 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8889 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008890
8891 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008892 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008893
8894 VkBufferMemoryBarrier buf_barrier = {};
8895 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8896 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8897 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8898 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8899 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8900 buf_barrier.buffer = VK_NULL_HANDLE;
8901 buf_barrier.offset = 0;
8902 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008903 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8904 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008905
8906 m_errorMonitor->VerifyFound();
8907}
8908
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008909TEST_F(VkLayerTest, InvalidBarriers) {
8910 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8911
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008913
8914 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07008915 auto depth_format = find_depth_stencil_format(m_device);
8916 if (!depth_format) {
8917 printf(" No Depth + Stencil format found. Skipped.\n");
8918 return;
8919 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008920 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8921
8922 VkMemoryBarrier mem_barrier = {};
8923 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8924 mem_barrier.pNext = NULL;
8925 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8926 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008927 m_commandBuffer->BeginCommandBuffer();
8928 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008929 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008930 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008931 &mem_barrier, 0, nullptr, 0, nullptr);
8932 m_errorMonitor->VerifyFound();
8933
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008935 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008936 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 -06008937 ASSERT_TRUE(image.initialized());
8938 VkImageMemoryBarrier img_barrier = {};
8939 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8940 img_barrier.pNext = NULL;
8941 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8942 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8943 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8944 // New layout can't be UNDEFINED
8945 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8946 img_barrier.image = image.handle();
8947 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8948 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8949 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8950 img_barrier.subresourceRange.baseArrayLayer = 0;
8951 img_barrier.subresourceRange.baseMipLevel = 0;
8952 img_barrier.subresourceRange.layerCount = 1;
8953 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008954 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8955 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008956 m_errorMonitor->VerifyFound();
8957 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8958
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8960 "Subresource must have the sum of the "
8961 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008962 // baseArrayLayer + layerCount must be <= image's arrayLayers
8963 img_barrier.subresourceRange.baseArrayLayer = 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.baseArrayLayer = 0;
8968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008970 // baseMipLevel + levelCount must be <= image's mipLevels
8971 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008972 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8973 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008974 m_errorMonitor->VerifyFound();
8975 img_barrier.subresourceRange.baseMipLevel = 0;
8976
Mike Weiblen7053aa32017-01-25 15:21:10 -07008977 // levelCount must be non-zero.
8978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8979 img_barrier.subresourceRange.levelCount = 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.levelCount = 1;
8984
8985 // layerCount must be non-zero.
8986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8987 img_barrier.subresourceRange.layerCount = 0;
8988 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8989 nullptr, 0, nullptr, 1, &img_barrier);
8990 m_errorMonitor->VerifyFound();
8991 img_barrier.subresourceRange.layerCount = 1;
8992
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008993 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 -06008994 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008995 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8996 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008997 VkBufferMemoryBarrier buf_barrier = {};
8998 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8999 buf_barrier.pNext = NULL;
9000 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
9001 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
9002 buf_barrier.buffer = buffer.handle();
9003 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9004 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
9005 buf_barrier.offset = 0;
9006 buf_barrier.size = VK_WHOLE_SIZE;
9007 // Can't send buffer barrier during a render pass
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 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9012
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009013 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009014 buf_barrier.offset = 257;
9015 // Offset 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();
9019 buf_barrier.offset = 0;
9020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009022 buf_barrier.size = 257;
9023 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009024 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9025 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009026 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009027
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009028 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009029 m_errorMonitor->SetDesiredFailureMsg(
9030 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009031 "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 -06009032 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009033 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009034 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009035 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9036 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009037 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009038
9039 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009040 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009041 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9042 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009043 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009044
9045 // Having anything other than DEPTH or STENCIL is an error
9046 m_errorMonitor->SetDesiredFailureMsg(
9047 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9048 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9049 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9050 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9051 nullptr, 0, nullptr, 1, &img_barrier);
9052 m_errorMonitor->VerifyFound();
9053
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009054 // Now test depth-only
9055 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009056 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9057 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009058 VkDepthStencilObj d_image(m_device);
9059 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9060 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009061 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009062 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009063 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009064
9065 // DEPTH bit must be set
9066 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9067 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009068 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009069 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9070 0, nullptr, 0, nullptr, 1, &img_barrier);
9071 m_errorMonitor->VerifyFound();
9072
9073 // No bits other than DEPTH may be set
9074 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9075 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9076 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009077 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9078 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009079 m_errorMonitor->VerifyFound();
9080 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009081
9082 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009083 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9084 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009085 VkDepthStencilObj s_image(m_device);
9086 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9087 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009088 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009089 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009091 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009092 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9093 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009094 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009095 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9096 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009097 m_errorMonitor->VerifyFound();
9098 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009099
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009100 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009101 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009102 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 -06009103 ASSERT_TRUE(c_image.initialized());
9104 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9105 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9106 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009107
9108 // COLOR bit must be set
9109 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9110 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009111 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009112 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9113 nullptr, 0, nullptr, 1, &img_barrier);
9114 m_errorMonitor->VerifyFound();
9115
9116 // No bits other than COLOR may be set
9117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9118 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9119 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009120 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9121 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009122 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009123
Mike Weiblene6e01172017-03-07 22:18:40 -07009124 // A barrier's new and old VkImageLayout must be compatible with an image's VkImageUsageFlags.
9125 {
9126 VkImageObj img_color(m_device);
9127 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9128 ASSERT_TRUE(img_color.initialized());
9129
9130 VkImageObj img_ds(m_device);
9131 img_ds.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9132 ASSERT_TRUE(img_ds.initialized());
9133
9134 VkImageObj img_xfer_src(m_device);
9135 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
9136 ASSERT_TRUE(img_xfer_src.initialized());
9137
9138 VkImageObj img_xfer_dst(m_device);
9139 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
9140 ASSERT_TRUE(img_xfer_dst.initialized());
9141
9142 VkImageObj img_sampled(m_device);
9143 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
9144 ASSERT_TRUE(img_sampled.initialized());
9145
9146 VkImageObj img_input(m_device);
9147 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
9148 ASSERT_TRUE(img_input.initialized());
9149
9150 const struct {
9151 VkImageObj &image_obj;
9152 VkImageLayout bad_layout;
9153 UNIQUE_VALIDATION_ERROR_CODE msg_code;
9154 } bad_buffer_layouts[] = {
9155 // clang-format off
9156 // images _without_ VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
9157 {img_ds, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9158 {img_xfer_src, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9159 {img_xfer_dst, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9160 {img_sampled, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9161 {img_input, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00303},
9162 // images _without_ VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
9163 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9164 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9165 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9166 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9167 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VALIDATION_ERROR_00304},
9168 {img_color, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9169 {img_xfer_src, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9170 {img_xfer_dst, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9171 {img_sampled, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9172 {img_input, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00305},
9173 // images _without_ VK_IMAGE_USAGE_SAMPLED_BIT or VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
9174 {img_color, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9175 {img_ds, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9176 {img_xfer_src, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9177 {img_xfer_dst, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VALIDATION_ERROR_00306},
9178 // images _without_ VK_IMAGE_USAGE_TRANSFER_SRC_BIT
9179 {img_color, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9180 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9181 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9182 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9183 {img_input, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VALIDATION_ERROR_00307},
9184 // images _without_ VK_IMAGE_USAGE_TRANSFER_DST_BIT
9185 {img_color, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9186 {img_ds, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9187 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9188 {img_sampled, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9189 {img_input, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VALIDATION_ERROR_00308},
9190 // clang-format on
9191 };
9192 const uint32_t layout_count = sizeof(bad_buffer_layouts) / sizeof(bad_buffer_layouts[0]);
9193
9194 for (uint32_t i = 0; i < layout_count; ++i) {
9195 img_barrier.image = bad_buffer_layouts[i].image_obj.handle();
9196 const VkImageUsageFlags usage = bad_buffer_layouts[i].image_obj.usage();
9197 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
9198 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
9199 : VK_IMAGE_ASPECT_COLOR_BIT;
9200
9201 img_barrier.oldLayout = bad_buffer_layouts[i].bad_layout;
9202 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9203 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9204 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9205 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9206 m_errorMonitor->VerifyFound();
9207
9208 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9209 img_barrier.newLayout = bad_buffer_layouts[i].bad_layout;
9210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_buffer_layouts[i].msg_code);
9211 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
9212 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
9213 m_errorMonitor->VerifyFound();
9214 }
9215
9216 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
9217 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9218 }
9219
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009220 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9221
9222 // Create command pool with incompatible queueflags
9223 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9224 uint32_t queue_family_index = UINT32_MAX;
9225 for (uint32_t i = 0; i < queue_props.size(); i++) {
9226 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9227 queue_family_index = i;
9228 break;
9229 }
9230 }
9231 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009232 printf(" No non-compute queue found; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009233 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009234 }
9235 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9236
9237 VkCommandPool command_pool;
9238 VkCommandPoolCreateInfo pool_create_info{};
9239 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9240 pool_create_info.queueFamilyIndex = queue_family_index;
9241 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9242 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9243
9244 // Allocate a command buffer
9245 VkCommandBuffer bad_command_buffer;
9246 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9247 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9248 command_buffer_allocate_info.commandPool = command_pool;
9249 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9250 command_buffer_allocate_info.commandBufferCount = 1;
9251 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9252
9253 VkCommandBufferBeginInfo cbbi = {};
9254 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9255 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9256 buf_barrier.offset = 0;
9257 buf_barrier.size = VK_WHOLE_SIZE;
9258 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9259 &buf_barrier, 0, nullptr);
9260 m_errorMonitor->VerifyFound();
9261
9262 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9263 vkEndCommandBuffer(bad_command_buffer);
9264 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009265 printf(" The non-compute queue does not support graphics; skipped.\n");
Mike Weiblene6e01172017-03-07 22:18:40 -07009266 return; // NOTE: this exits the test function!
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009267 }
9268 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9269 VkEvent event;
9270 VkEventCreateInfo event_create_info{};
9271 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9272 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9273 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9274 nullptr, 0, nullptr);
9275 m_errorMonitor->VerifyFound();
9276
9277 vkEndCommandBuffer(bad_command_buffer);
9278 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009279}
9280
Tony Barbour18ba25c2016-09-29 13:42:40 -06009281TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9282 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9283
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009285 ASSERT_NO_FATAL_FAILURE(InitState());
9286 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -07009287 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
9288 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009289 ASSERT_TRUE(image.initialized());
9290
9291 VkImageMemoryBarrier barrier = {};
9292 VkImageSubresourceRange range;
9293 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9294 barrier.srcAccessMask = 0;
9295 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9296 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9297 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9298 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9299 barrier.image = image.handle();
9300 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9301 range.baseMipLevel = 0;
9302 range.levelCount = 1;
9303 range.baseArrayLayer = 0;
9304 range.layerCount = 1;
9305 barrier.subresourceRange = range;
9306 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9307 cmdbuf.BeginCommandBuffer();
9308 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9309 &barrier);
9310 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9311 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9312 barrier.srcAccessMask = 0;
9313 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9314 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9315 &barrier);
9316
9317 m_errorMonitor->VerifyFound();
9318}
9319
Karl Schultz6addd812016-02-02 17:17:23 -07009320TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009321 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009322 ASSERT_NO_FATAL_FAILURE(InitState());
9323 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009324
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009325 uint32_t const indices[] = {0};
9326 VkBufferCreateInfo buf_info = {};
9327 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9328 buf_info.size = 1024;
9329 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9330 buf_info.queueFamilyIndexCount = 1;
9331 buf_info.pQueueFamilyIndices = indices;
9332
9333 VkBuffer buffer;
9334 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
9335 ASSERT_VK_SUCCESS(err);
9336
9337 VkMemoryRequirements requirements;
9338 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
9339
9340 VkMemoryAllocateInfo alloc_info{};
9341 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9342 alloc_info.pNext = NULL;
9343 alloc_info.memoryTypeIndex = 0;
9344 alloc_info.allocationSize = requirements.size;
9345 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
9346 ASSERT_TRUE(pass);
9347
9348 VkDeviceMemory memory;
9349 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
9350 ASSERT_VK_SUCCESS(err);
9351
9352 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009353 ASSERT_VK_SUCCESS(err);
9354
Tony Barbour552f6c02016-12-21 14:34:07 -07009355 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009356 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009357
Karl Schultz6addd812016-02-02 17:17:23 -07009358 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9359 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009360 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
9362 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009363 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009364
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009365 vkFreeMemory(m_device->device(), memory, NULL);
9366 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009367}
9368
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009369TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9370 // Create an out-of-range queueFamilyIndex
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009371 ASSERT_NO_FATAL_FAILURE(InitState());
9372 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9373 VkBufferCreateInfo buffCI = {};
9374 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9375 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009376 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009377 buffCI.queueFamilyIndexCount = 2;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009378 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009379 uint32_t qfi[2];
9380 qfi[0] = 777;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009381 qfi[1] = 0;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009382
9383 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009384 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009385
9386 VkBuffer ib;
Jeremy Hayes8a43a0d2017-03-09 11:27:52 -07009387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9388 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one of the indices "
9389 "specified when the device was created, via the VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009390 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009391 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009392
9393 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -07009394 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9396
9397 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9398 buffCI.queueFamilyIndexCount = 2;
9399 qfi[0] = 1;
9400 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -07009401 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009402 VkDeviceMemory mem;
9403 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -07009404 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009405
9406 VkMemoryAllocateInfo alloc_info = {};
9407 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9408 alloc_info.allocationSize = 1024;
9409 bool pass = false;
9410 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9411 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -07009412 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009413 return;
9414 }
9415 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -07009416 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009417
9418 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -07009419 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009420 m_commandBuffer->end();
9421 QueueCommandBuffer(false);
9422 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -07009423 vkDestroyBuffer(m_device->device(), ib2, NULL);
9424 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009425 }
9426
Tony Barbourdf4c0042016-06-01 15:55:43 -06009427 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009428}
9429
Karl Schultz6addd812016-02-02 17:17:23 -07009430TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009431 TEST_DESCRIPTION(
9432 "Attempt vkCmdExecuteCommands with a primary command buffer"
9433 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009434
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009435 ASSERT_NO_FATAL_FAILURE(InitState());
9436 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009437
Chris Forbesf29a84f2016-10-06 18:39:28 +13009438 // An empty primary command buffer
9439 VkCommandBufferObj cb(m_device, m_commandPool);
9440 cb.BeginCommandBuffer();
9441 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009442
Chris Forbesf29a84f2016-10-06 18:39:28 +13009443 m_commandBuffer->BeginCommandBuffer();
9444 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9445 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009446
Chris Forbesf29a84f2016-10-06 18:39:28 +13009447 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9448 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009449 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009450
9451 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009452}
9453
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009454TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009455 TEST_DESCRIPTION(
9456 "Attempt to update descriptor sets for images and buffers "
9457 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009458 VkResult err;
9459
9460 ASSERT_NO_FATAL_FAILURE(InitState());
9461 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9462 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9463 ds_type_count[i].type = VkDescriptorType(i);
9464 ds_type_count[i].descriptorCount = 1;
9465 }
9466 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9467 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9468 ds_pool_ci.pNext = NULL;
9469 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9470 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9471 ds_pool_ci.pPoolSizes = ds_type_count;
9472
9473 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009474 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009475 ASSERT_VK_SUCCESS(err);
9476
9477 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009478 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009479 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9480 dsl_binding[i].binding = 0;
9481 dsl_binding[i].descriptorType = VkDescriptorType(i);
9482 dsl_binding[i].descriptorCount = 1;
9483 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9484 dsl_binding[i].pImmutableSamplers = NULL;
9485 }
9486
9487 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9488 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9489 ds_layout_ci.pNext = NULL;
9490 ds_layout_ci.bindingCount = 1;
9491 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9492 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9493 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009494 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009495 ASSERT_VK_SUCCESS(err);
9496 }
9497 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9498 VkDescriptorSetAllocateInfo alloc_info = {};
9499 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9500 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9501 alloc_info.descriptorPool = ds_pool;
9502 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009503 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009504 ASSERT_VK_SUCCESS(err);
9505
9506 // Create a buffer & bufferView to be used for invalid updates
9507 VkBufferCreateInfo buff_ci = {};
9508 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009509 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009510 buff_ci.size = 256;
9511 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009512 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009513 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9514 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009515
9516 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9517 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9518 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9519 ASSERT_VK_SUCCESS(err);
9520
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009521 VkMemoryRequirements mem_reqs;
9522 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9523 VkMemoryAllocateInfo mem_alloc_info = {};
9524 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9525 mem_alloc_info.pNext = NULL;
9526 mem_alloc_info.memoryTypeIndex = 0;
9527 mem_alloc_info.allocationSize = mem_reqs.size;
9528 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9529 if (!pass) {
9530 vkDestroyBuffer(m_device->device(), buffer, NULL);
9531 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9532 return;
9533 }
9534 VkDeviceMemory mem;
9535 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9536 ASSERT_VK_SUCCESS(err);
9537 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9538 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009539
9540 VkBufferViewCreateInfo buff_view_ci = {};
9541 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9542 buff_view_ci.buffer = buffer;
9543 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9544 buff_view_ci.range = VK_WHOLE_SIZE;
9545 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009546 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009547 ASSERT_VK_SUCCESS(err);
9548
Tony Barbour415497c2017-01-24 10:06:09 -07009549 // Now get resources / view for storage_texel_buffer
9550 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9551 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9552 if (!pass) {
9553 vkDestroyBuffer(m_device->device(), buffer, NULL);
9554 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9555 vkFreeMemory(m_device->device(), mem, NULL);
9556 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9557 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9558 return;
9559 }
9560 VkDeviceMemory storage_texel_buffer_mem;
9561 VkBufferView storage_texel_buffer_view;
9562 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9563 ASSERT_VK_SUCCESS(err);
9564 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9565 ASSERT_VK_SUCCESS(err);
9566 buff_view_ci.buffer = storage_texel_buffer;
9567 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9568 ASSERT_VK_SUCCESS(err);
9569
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009570 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009571 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009572 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009573 image_ci.format = VK_FORMAT_UNDEFINED;
9574 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9575 VkFormat format = static_cast<VkFormat>(f);
9576 VkFormatProperties fProps = m_device->format_properties(format);
9577 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9578 image_ci.format = format;
9579 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9580 break;
9581 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9582 image_ci.format = format;
9583 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9584 break;
9585 }
9586 }
9587 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9588 return;
9589 }
9590
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009591 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9592 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009593 image_ci.extent.width = 64;
9594 image_ci.extent.height = 64;
9595 image_ci.extent.depth = 1;
9596 image_ci.mipLevels = 1;
9597 image_ci.arrayLayers = 1;
9598 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009599 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009600 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009601 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9602 VkImage image;
9603 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9604 ASSERT_VK_SUCCESS(err);
9605 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009606 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009607
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009608 VkMemoryAllocateInfo mem_alloc = {};
9609 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9610 mem_alloc.pNext = NULL;
9611 mem_alloc.allocationSize = 0;
9612 mem_alloc.memoryTypeIndex = 0;
9613 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9614 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009615 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009616 ASSERT_TRUE(pass);
9617 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9618 ASSERT_VK_SUCCESS(err);
9619 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9620 ASSERT_VK_SUCCESS(err);
9621 // Now create view for image
9622 VkImageViewCreateInfo image_view_ci = {};
9623 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9624 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009625 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009626 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9627 image_view_ci.subresourceRange.layerCount = 1;
9628 image_view_ci.subresourceRange.baseArrayLayer = 0;
9629 image_view_ci.subresourceRange.levelCount = 1;
9630 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9631 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009632 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009633 ASSERT_VK_SUCCESS(err);
9634
9635 VkDescriptorBufferInfo buff_info = {};
9636 buff_info.buffer = buffer;
9637 VkDescriptorImageInfo img_info = {};
9638 img_info.imageView = image_view;
9639 VkWriteDescriptorSet descriptor_write = {};
9640 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9641 descriptor_write.dstBinding = 0;
9642 descriptor_write.descriptorCount = 1;
9643 descriptor_write.pTexelBufferView = &buff_view;
9644 descriptor_write.pBufferInfo = &buff_info;
9645 descriptor_write.pImageInfo = &img_info;
9646
9647 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009648 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009649 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9650 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9651 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9652 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9653 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9654 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9655 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9656 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9657 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9658 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9659 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009660 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009661 // Start loop at 1 as SAMPLER desc type has no usage bit error
9662 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009663 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9664 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9665 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9666 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009667 descriptor_write.descriptorType = VkDescriptorType(i);
9668 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009669 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009670
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009671 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009672
9673 m_errorMonitor->VerifyFound();
9674 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009675 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9676 descriptor_write.pTexelBufferView = &buff_view;
9677 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009678 }
Tony Barbour415497c2017-01-24 10:06:09 -07009679
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009680 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9681 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009682 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009683 vkDestroyImageView(m_device->device(), image_view, NULL);
9684 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009685 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009686 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009687 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009688 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009689 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009690 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9691}
9692
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009693TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009694 TEST_DESCRIPTION(
9695 "Attempt to update buffer descriptor set that has incorrect "
9696 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009697 "1. offset value greater than or equal to buffer size\n"
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009698 "2. range value of 0\n"
9699 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009700 VkResult err;
9701
9702 ASSERT_NO_FATAL_FAILURE(InitState());
9703 VkDescriptorPoolSize ds_type_count = {};
9704 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9705 ds_type_count.descriptorCount = 1;
9706
9707 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9708 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9709 ds_pool_ci.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009710 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009711 ds_pool_ci.maxSets = 1;
9712 ds_pool_ci.poolSizeCount = 1;
9713 ds_pool_ci.pPoolSizes = &ds_type_count;
9714
9715 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009716 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009717 ASSERT_VK_SUCCESS(err);
9718
9719 // Create layout with single uniform buffer descriptor
9720 VkDescriptorSetLayoutBinding dsl_binding = {};
9721 dsl_binding.binding = 0;
9722 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9723 dsl_binding.descriptorCount = 1;
9724 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9725 dsl_binding.pImmutableSamplers = NULL;
9726
9727 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9728 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9729 ds_layout_ci.pNext = NULL;
9730 ds_layout_ci.bindingCount = 1;
9731 ds_layout_ci.pBindings = &dsl_binding;
9732 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009733 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009734 ASSERT_VK_SUCCESS(err);
9735
9736 VkDescriptorSet descriptor_set = {};
9737 VkDescriptorSetAllocateInfo alloc_info = {};
9738 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9739 alloc_info.descriptorSetCount = 1;
9740 alloc_info.descriptorPool = ds_pool;
9741 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009742 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009743 ASSERT_VK_SUCCESS(err);
9744
9745 // Create a buffer to be used for invalid updates
9746 VkBufferCreateInfo buff_ci = {};
9747 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9748 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009749 buff_ci.size = m_device->props.limits.minUniformBufferOffsetAlignment;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009750 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9751 VkBuffer buffer;
9752 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9753 ASSERT_VK_SUCCESS(err);
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009754
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009755 // Have to bind memory to buffer before descriptor update
9756 VkMemoryAllocateInfo mem_alloc = {};
9757 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9758 mem_alloc.pNext = NULL;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009759 mem_alloc.allocationSize = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009760 mem_alloc.memoryTypeIndex = 0;
9761
9762 VkMemoryRequirements mem_reqs;
9763 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009764 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009765 if (!pass) {
9766 vkDestroyBuffer(m_device->device(), buffer, NULL);
9767 return;
9768 }
9769
9770 VkDeviceMemory mem;
9771 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9772 ASSERT_VK_SUCCESS(err);
9773 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9774 ASSERT_VK_SUCCESS(err);
9775
9776 VkDescriptorBufferInfo buff_info = {};
9777 buff_info.buffer = buffer;
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009778 // Cause error due to offset out of range
9779 buff_info.offset = buff_ci.size;
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009780 buff_info.range = VK_WHOLE_SIZE;
9781 VkWriteDescriptorSet descriptor_write = {};
9782 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9783 descriptor_write.dstBinding = 0;
9784 descriptor_write.descriptorCount = 1;
9785 descriptor_write.pTexelBufferView = nullptr;
9786 descriptor_write.pBufferInfo = &buff_info;
9787 descriptor_write.pImageInfo = nullptr;
9788
9789 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9790 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009791 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009792
9793 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9794
9795 m_errorMonitor->VerifyFound();
9796 // Now cause error due to range of 0
9797 buff_info.offset = 0;
9798 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009800
9801 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9802
9803 m_errorMonitor->VerifyFound();
9804 // Now cause error due to range exceeding buffer size - offset
Jeremy Hayesd1a6a822017-03-09 14:39:45 -07009805 buff_info.offset = 0;
9806 buff_info.range = buff_ci.size + 1;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009807 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009808
9809 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9810
9811 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009812 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009813 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9814 vkDestroyBuffer(m_device->device(), buffer, NULL);
9815 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9816 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9817}
9818
Tobin Ehlis845887e2017-02-02 19:01:44 -07009819TEST_F(VkLayerTest, DSBufferLimitErrors) {
9820 TEST_DESCRIPTION(
9821 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9822 "Test cases include:\n"
9823 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9824 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9825 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9826 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9827 VkResult err;
9828
9829 ASSERT_NO_FATAL_FAILURE(InitState());
9830 VkDescriptorPoolSize ds_type_count[2] = {};
9831 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9832 ds_type_count[0].descriptorCount = 1;
9833 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9834 ds_type_count[1].descriptorCount = 1;
9835
9836 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9837 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9838 ds_pool_ci.pNext = NULL;
9839 ds_pool_ci.maxSets = 1;
9840 ds_pool_ci.poolSizeCount = 2;
9841 ds_pool_ci.pPoolSizes = ds_type_count;
9842
9843 VkDescriptorPool ds_pool;
9844 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9845 ASSERT_VK_SUCCESS(err);
9846
9847 // Create layout with single uniform buffer & single storage buffer descriptor
9848 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9849 dsl_binding[0].binding = 0;
9850 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9851 dsl_binding[0].descriptorCount = 1;
9852 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9853 dsl_binding[0].pImmutableSamplers = NULL;
9854 dsl_binding[1].binding = 1;
9855 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9856 dsl_binding[1].descriptorCount = 1;
9857 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9858 dsl_binding[1].pImmutableSamplers = NULL;
9859
9860 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9861 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9862 ds_layout_ci.pNext = NULL;
9863 ds_layout_ci.bindingCount = 2;
9864 ds_layout_ci.pBindings = dsl_binding;
9865 VkDescriptorSetLayout ds_layout;
9866 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9867 ASSERT_VK_SUCCESS(err);
9868
9869 VkDescriptorSet descriptor_set = {};
9870 VkDescriptorSetAllocateInfo alloc_info = {};
9871 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9872 alloc_info.descriptorSetCount = 1;
9873 alloc_info.descriptorPool = ds_pool;
9874 alloc_info.pSetLayouts = &ds_layout;
9875 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9876 ASSERT_VK_SUCCESS(err);
9877
9878 // Create a buffer to be used for invalid updates
9879 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9880 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9881 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9882 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9883 VkBufferCreateInfo ub_ci = {};
9884 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9885 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9886 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9887 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9888 VkBuffer uniform_buffer;
9889 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9890 ASSERT_VK_SUCCESS(err);
9891 VkBufferCreateInfo sb_ci = {};
9892 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9893 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9894 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9895 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9896 VkBuffer storage_buffer;
9897 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9898 ASSERT_VK_SUCCESS(err);
9899 // Have to bind memory to buffer before descriptor update
9900 VkMemoryAllocateInfo mem_alloc = {};
9901 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9902 mem_alloc.pNext = NULL;
9903 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9904 mem_alloc.memoryTypeIndex = 0;
9905
Cort Stratton77a0d592017-02-17 13:14:13 -08009906 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9907 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9908 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9909 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9910 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009911 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009912 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009913 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009914 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9915 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009916 return;
9917 }
9918
9919 VkDeviceMemory mem;
9920 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009921 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009922 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009923 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9924 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9925 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9926 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9927 return;
9928 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009929 ASSERT_VK_SUCCESS(err);
9930 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9931 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009932 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009933 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9934 ASSERT_VK_SUCCESS(err);
9935
9936 VkDescriptorBufferInfo buff_info = {};
9937 buff_info.buffer = uniform_buffer;
9938 buff_info.range = ub_ci.size; // This will exceed limit
9939 VkWriteDescriptorSet descriptor_write = {};
9940 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9941 descriptor_write.dstBinding = 0;
9942 descriptor_write.descriptorCount = 1;
9943 descriptor_write.pTexelBufferView = nullptr;
9944 descriptor_write.pBufferInfo = &buff_info;
9945 descriptor_write.pImageInfo = nullptr;
9946
9947 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9948 descriptor_write.dstSet = descriptor_set;
9949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9950 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9951 m_errorMonitor->VerifyFound();
9952
9953 // Reduce size of range to acceptable limit & cause offset error
9954 buff_info.range = max_ub_range;
9955 buff_info.offset = min_ub_align - 1;
9956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9957 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9958 m_errorMonitor->VerifyFound();
9959
9960 // Now break storage updates
9961 buff_info.buffer = storage_buffer;
9962 buff_info.range = sb_ci.size; // This will exceed limit
9963 buff_info.offset = 0; // Reset offset for this update
9964
9965 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9966 descriptor_write.dstBinding = 1;
9967 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9968 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9969 m_errorMonitor->VerifyFound();
9970
9971 // Reduce size of range to acceptable limit & cause offset error
9972 buff_info.range = max_sb_range;
9973 buff_info.offset = min_sb_align - 1;
9974 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9975 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9976 m_errorMonitor->VerifyFound();
9977
9978 vkFreeMemory(m_device->device(), mem, NULL);
9979 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9980 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9981 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9982 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9983}
9984
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009985TEST_F(VkLayerTest, DSAspectBitsErrors) {
9986 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9987 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009988 TEST_DESCRIPTION(
9989 "Attempt to update descriptor sets for images "
9990 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009991 VkResult err;
9992
9993 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009994 auto depth_format = find_depth_stencil_format(m_device);
9995 if (!depth_format) {
9996 printf(" No Depth + Stencil format found. Skipped.\n");
9997 return;
9998 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009999 VkDescriptorPoolSize ds_type_count = {};
10000 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10001 ds_type_count.descriptorCount = 1;
10002
10003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10005 ds_pool_ci.pNext = NULL;
Jeremy Hayes293c7ed2017-03-09 14:47:07 -070010006 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010007 ds_pool_ci.maxSets = 5;
10008 ds_pool_ci.poolSizeCount = 1;
10009 ds_pool_ci.pPoolSizes = &ds_type_count;
10010
10011 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010013 ASSERT_VK_SUCCESS(err);
10014
10015 VkDescriptorSetLayoutBinding dsl_binding = {};
10016 dsl_binding.binding = 0;
10017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10018 dsl_binding.descriptorCount = 1;
10019 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10020 dsl_binding.pImmutableSamplers = NULL;
10021
10022 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10023 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10024 ds_layout_ci.pNext = NULL;
10025 ds_layout_ci.bindingCount = 1;
10026 ds_layout_ci.pBindings = &dsl_binding;
10027 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010028 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010029 ASSERT_VK_SUCCESS(err);
10030
10031 VkDescriptorSet descriptor_set = {};
10032 VkDescriptorSetAllocateInfo alloc_info = {};
10033 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10034 alloc_info.descriptorSetCount = 1;
10035 alloc_info.descriptorPool = ds_pool;
10036 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010037 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010038 ASSERT_VK_SUCCESS(err);
10039
10040 // Create an image to be used for invalid updates
10041 VkImageCreateInfo image_ci = {};
10042 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
10043 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070010044 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010045 image_ci.extent.width = 64;
10046 image_ci.extent.height = 64;
10047 image_ci.extent.depth = 1;
10048 image_ci.mipLevels = 1;
10049 image_ci.arrayLayers = 1;
10050 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -070010051 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010052 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
10053 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
10054 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
10055 VkImage image;
10056 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
10057 ASSERT_VK_SUCCESS(err);
10058 // Bind memory to image
10059 VkMemoryRequirements mem_reqs;
10060 VkDeviceMemory image_mem;
10061 bool pass;
10062 VkMemoryAllocateInfo mem_alloc = {};
10063 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
10064 mem_alloc.pNext = NULL;
10065 mem_alloc.allocationSize = 0;
10066 mem_alloc.memoryTypeIndex = 0;
10067 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
10068 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010070 ASSERT_TRUE(pass);
10071 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
10072 ASSERT_VK_SUCCESS(err);
10073 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
10074 ASSERT_VK_SUCCESS(err);
10075 // Now create view for image
10076 VkImageViewCreateInfo image_view_ci = {};
10077 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
10078 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -070010079 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010080 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
10081 image_view_ci.subresourceRange.layerCount = 1;
10082 image_view_ci.subresourceRange.baseArrayLayer = 0;
10083 image_view_ci.subresourceRange.levelCount = 1;
10084 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010085 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010086
10087 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010088 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010089 ASSERT_VK_SUCCESS(err);
10090
10091 VkDescriptorImageInfo img_info = {};
10092 img_info.imageView = image_view;
10093 VkWriteDescriptorSet descriptor_write = {};
10094 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10095 descriptor_write.dstBinding = 0;
10096 descriptor_write.descriptorCount = 1;
10097 descriptor_write.pTexelBufferView = NULL;
10098 descriptor_write.pBufferInfo = NULL;
10099 descriptor_write.pImageInfo = &img_info;
10100 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10101 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010102 const char *error_msg =
10103 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10104 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010105 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010106
10107 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10108
10109 m_errorMonitor->VerifyFound();
10110 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10111 vkDestroyImage(m_device->device(), image, NULL);
10112 vkFreeMemory(m_device->device(), image_mem, NULL);
10113 vkDestroyImageView(m_device->device(), image_view, NULL);
10114 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10115 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10116}
10117
Karl Schultz6addd812016-02-02 17:17:23 -070010118TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010119 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010120 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010121
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10123 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10124 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010125
Tobin Ehlis3b780662015-05-28 12:11:26 -060010126 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010127 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010128 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010129 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10130 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010131
10132 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010133 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10134 ds_pool_ci.pNext = NULL;
10135 ds_pool_ci.maxSets = 1;
10136 ds_pool_ci.poolSizeCount = 1;
10137 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010138
Tobin Ehlis3b780662015-05-28 12:11:26 -060010139 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010140 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010141 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010142 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010143 dsl_binding.binding = 0;
10144 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10145 dsl_binding.descriptorCount = 1;
10146 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10147 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010148
Tony Barboureb254902015-07-15 12:50:33 -060010149 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010150 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10151 ds_layout_ci.pNext = NULL;
10152 ds_layout_ci.bindingCount = 1;
10153 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010154
Tobin Ehlis3b780662015-05-28 12:11:26 -060010155 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010156 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010157 ASSERT_VK_SUCCESS(err);
10158
10159 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010160 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010161 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010162 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010163 alloc_info.descriptorPool = ds_pool;
10164 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010165 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010166 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010167
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010168 VkSamplerCreateInfo sampler_ci = {};
10169 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10170 sampler_ci.pNext = NULL;
10171 sampler_ci.magFilter = VK_FILTER_NEAREST;
10172 sampler_ci.minFilter = VK_FILTER_NEAREST;
10173 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10174 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10175 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10176 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10177 sampler_ci.mipLodBias = 1.0;
10178 sampler_ci.anisotropyEnable = VK_FALSE;
10179 sampler_ci.maxAnisotropy = 1;
10180 sampler_ci.compareEnable = VK_FALSE;
10181 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10182 sampler_ci.minLod = 1.0;
10183 sampler_ci.maxLod = 1.0;
10184 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10185 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10186 VkSampler sampler;
10187 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10188 ASSERT_VK_SUCCESS(err);
10189
10190 VkDescriptorImageInfo info = {};
10191 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010192
10193 VkWriteDescriptorSet descriptor_write;
10194 memset(&descriptor_write, 0, sizeof(descriptor_write));
10195 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010196 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010197 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010198 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010199 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010200 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010201
10202 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10203
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010204 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010205
Chia-I Wuf7458c52015-10-26 21:10:41 +080010206 vkDestroySampler(m_device->device(), sampler, NULL);
10207 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10208 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010209}
10210
Karl Schultz6addd812016-02-02 17:17:23 -070010211TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010212 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010213 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010214
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010215 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010216
Tobin Ehlis3b780662015-05-28 12:11:26 -060010217 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010218 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010219 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010220 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10221 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010222
10223 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010224 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10225 ds_pool_ci.pNext = NULL;
10226 ds_pool_ci.maxSets = 1;
10227 ds_pool_ci.poolSizeCount = 1;
10228 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010229
Tobin Ehlis3b780662015-05-28 12:11:26 -060010230 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010231 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010232 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010233
Tony Barboureb254902015-07-15 12:50:33 -060010234 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010235 dsl_binding.binding = 0;
10236 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10237 dsl_binding.descriptorCount = 1;
10238 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10239 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010240
10241 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010242 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10243 ds_layout_ci.pNext = NULL;
10244 ds_layout_ci.bindingCount = 1;
10245 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010246
Tobin Ehlis3b780662015-05-28 12:11:26 -060010247 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010248 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010249 ASSERT_VK_SUCCESS(err);
10250
10251 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010252 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010253 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010254 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010255 alloc_info.descriptorPool = ds_pool;
10256 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010257 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010258 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010259
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010260 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
10261
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010262 // Correctly update descriptor to avoid "NOT_UPDATED" error
10263 VkDescriptorBufferInfo buff_info = {};
Jeremy Hayesd5b95db2017-03-09 15:24:24 -070010264 buff_info.buffer = buffer_test.GetBuffer();
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010265 buff_info.offset = 0;
10266 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010267
10268 VkWriteDescriptorSet descriptor_write;
10269 memset(&descriptor_write, 0, sizeof(descriptor_write));
10270 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010271 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010272 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010273 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010274 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10275 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010276
10277 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010279 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010280
Chia-I Wuf7458c52015-10-26 21:10:41 +080010281 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10282 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010283}
10284
Karl Schultz6addd812016-02-02 17:17:23 -070010285TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010286 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010287 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010288
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010290
Tobin Ehlis3b780662015-05-28 12:11:26 -060010291 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010292 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010293 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010294 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10295 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010296
10297 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010298 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10299 ds_pool_ci.pNext = NULL;
10300 ds_pool_ci.maxSets = 1;
10301 ds_pool_ci.poolSizeCount = 1;
10302 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010303
Tobin Ehlis3b780662015-05-28 12:11:26 -060010304 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010305 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010306 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010307
Tony Barboureb254902015-07-15 12:50:33 -060010308 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010309 dsl_binding.binding = 0;
10310 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10311 dsl_binding.descriptorCount = 1;
10312 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10313 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010314
10315 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010316 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10317 ds_layout_ci.pNext = NULL;
10318 ds_layout_ci.bindingCount = 1;
10319 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010320 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010321 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010322 ASSERT_VK_SUCCESS(err);
10323
10324 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010325 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010326 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010327 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010328 alloc_info.descriptorPool = ds_pool;
10329 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010330 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010331 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010332
Tony Barboureb254902015-07-15 12:50:33 -060010333 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010334 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10335 sampler_ci.pNext = NULL;
10336 sampler_ci.magFilter = VK_FILTER_NEAREST;
10337 sampler_ci.minFilter = VK_FILTER_NEAREST;
10338 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10339 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10340 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10341 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10342 sampler_ci.mipLodBias = 1.0;
10343 sampler_ci.anisotropyEnable = VK_FALSE;
10344 sampler_ci.maxAnisotropy = 1;
10345 sampler_ci.compareEnable = VK_FALSE;
10346 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10347 sampler_ci.minLod = 1.0;
10348 sampler_ci.maxLod = 1.0;
10349 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10350 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010351
Tobin Ehlis3b780662015-05-28 12:11:26 -060010352 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010353 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010354 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010355
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010356 VkDescriptorImageInfo info = {};
10357 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010358
10359 VkWriteDescriptorSet descriptor_write;
10360 memset(&descriptor_write, 0, sizeof(descriptor_write));
10361 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010362 descriptor_write.dstSet = descriptorSet;
10363 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010364 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010365 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010366 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010367 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010368
10369 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10370
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010371 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010372
Chia-I Wuf7458c52015-10-26 21:10:41 +080010373 vkDestroySampler(m_device->device(), sampler, NULL);
10374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10375 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010376}
10377
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010378TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10379 // Create layout w/ empty binding and attempt to update it
10380 VkResult err;
10381
10382 ASSERT_NO_FATAL_FAILURE(InitState());
10383
10384 VkDescriptorPoolSize ds_type_count = {};
10385 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10386 ds_type_count.descriptorCount = 1;
10387
10388 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10389 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10390 ds_pool_ci.pNext = NULL;
10391 ds_pool_ci.maxSets = 1;
10392 ds_pool_ci.poolSizeCount = 1;
10393 ds_pool_ci.pPoolSizes = &ds_type_count;
10394
10395 VkDescriptorPool ds_pool;
10396 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10397 ASSERT_VK_SUCCESS(err);
10398
10399 VkDescriptorSetLayoutBinding dsl_binding = {};
10400 dsl_binding.binding = 0;
10401 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10402 dsl_binding.descriptorCount = 0;
10403 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10404 dsl_binding.pImmutableSamplers = NULL;
10405
10406 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10407 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10408 ds_layout_ci.pNext = NULL;
10409 ds_layout_ci.bindingCount = 1;
10410 ds_layout_ci.pBindings = &dsl_binding;
10411 VkDescriptorSetLayout ds_layout;
10412 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10413 ASSERT_VK_SUCCESS(err);
10414
10415 VkDescriptorSet descriptor_set;
10416 VkDescriptorSetAllocateInfo alloc_info = {};
10417 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10418 alloc_info.descriptorSetCount = 1;
10419 alloc_info.descriptorPool = ds_pool;
10420 alloc_info.pSetLayouts = &ds_layout;
10421 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10422 ASSERT_VK_SUCCESS(err);
10423
10424 VkSamplerCreateInfo sampler_ci = {};
10425 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10426 sampler_ci.magFilter = VK_FILTER_NEAREST;
10427 sampler_ci.minFilter = VK_FILTER_NEAREST;
10428 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10429 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10430 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10431 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10432 sampler_ci.mipLodBias = 1.0;
10433 sampler_ci.maxAnisotropy = 1;
10434 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10435 sampler_ci.minLod = 1.0;
10436 sampler_ci.maxLod = 1.0;
10437 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10438
10439 VkSampler sampler;
10440 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10441 ASSERT_VK_SUCCESS(err);
10442
10443 VkDescriptorImageInfo info = {};
10444 info.sampler = sampler;
10445
10446 VkWriteDescriptorSet descriptor_write;
10447 memset(&descriptor_write, 0, sizeof(descriptor_write));
10448 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10449 descriptor_write.dstSet = descriptor_set;
10450 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010451 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010452 // This is the wrong type, but empty binding error will be flagged first
10453 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10454 descriptor_write.pImageInfo = &info;
10455
10456 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10457 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10458 m_errorMonitor->VerifyFound();
10459
10460 vkDestroySampler(m_device->device(), sampler, NULL);
10461 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10462 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10463}
10464
Karl Schultz6addd812016-02-02 17:17:23 -070010465TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10466 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10467 // types
10468 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010469
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010470 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 -060010471
Tobin Ehlis3b780662015-05-28 12:11:26 -060010472 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010473
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010474 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010475 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10476 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010477
10478 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010479 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10480 ds_pool_ci.pNext = NULL;
10481 ds_pool_ci.maxSets = 1;
10482 ds_pool_ci.poolSizeCount = 1;
10483 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010484
Tobin Ehlis3b780662015-05-28 12:11:26 -060010485 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010486 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010487 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010488 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010489 dsl_binding.binding = 0;
10490 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10491 dsl_binding.descriptorCount = 1;
10492 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10493 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010494
Tony Barboureb254902015-07-15 12:50:33 -060010495 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010496 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10497 ds_layout_ci.pNext = NULL;
10498 ds_layout_ci.bindingCount = 1;
10499 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010500
Tobin Ehlis3b780662015-05-28 12:11:26 -060010501 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010502 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010503 ASSERT_VK_SUCCESS(err);
10504
10505 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010506 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010507 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010508 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010509 alloc_info.descriptorPool = ds_pool;
10510 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010511 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010512 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010513
Tony Barboureb254902015-07-15 12:50:33 -060010514 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010515 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10516 sampler_ci.pNext = NULL;
10517 sampler_ci.magFilter = VK_FILTER_NEAREST;
10518 sampler_ci.minFilter = VK_FILTER_NEAREST;
10519 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10520 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10521 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10522 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10523 sampler_ci.mipLodBias = 1.0;
10524 sampler_ci.anisotropyEnable = VK_FALSE;
10525 sampler_ci.maxAnisotropy = 1;
10526 sampler_ci.compareEnable = VK_FALSE;
10527 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10528 sampler_ci.minLod = 1.0;
10529 sampler_ci.maxLod = 1.0;
10530 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10531 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010532 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010533 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010534 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010535
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010536 VkDescriptorImageInfo info = {};
10537 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010538
10539 VkWriteDescriptorSet descriptor_write;
10540 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010541 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010542 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010543 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010544 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010545 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010546 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010547
10548 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10549
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010550 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010551
Chia-I Wuf7458c52015-10-26 21:10:41 +080010552 vkDestroySampler(m_device->device(), sampler, NULL);
10553 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10554 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010555}
10556
Karl Schultz6addd812016-02-02 17:17:23 -070010557TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010558 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010559 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010560
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010562
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010563 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010564 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10565 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010566 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010567 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10568 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010569
10570 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010571 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10572 ds_pool_ci.pNext = NULL;
10573 ds_pool_ci.maxSets = 1;
10574 ds_pool_ci.poolSizeCount = 1;
10575 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010576
10577 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010578 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010579 ASSERT_VK_SUCCESS(err);
10580
10581 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010582 dsl_binding.binding = 0;
10583 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10584 dsl_binding.descriptorCount = 1;
10585 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10586 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010587
10588 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010589 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10590 ds_layout_ci.pNext = NULL;
10591 ds_layout_ci.bindingCount = 1;
10592 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010593 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010594 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010595 ASSERT_VK_SUCCESS(err);
10596
10597 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010598 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010599 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010600 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010601 alloc_info.descriptorPool = ds_pool;
10602 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010603 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010604 ASSERT_VK_SUCCESS(err);
10605
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010606 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010607
10608 VkDescriptorImageInfo descriptor_info;
10609 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10610 descriptor_info.sampler = sampler;
10611
10612 VkWriteDescriptorSet descriptor_write;
10613 memset(&descriptor_write, 0, sizeof(descriptor_write));
10614 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010615 descriptor_write.dstSet = descriptorSet;
10616 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010617 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010618 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10619 descriptor_write.pImageInfo = &descriptor_info;
10620
10621 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10622
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010623 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010624
Chia-I Wuf7458c52015-10-26 21:10:41 +080010625 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10626 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010627}
10628
Karl Schultz6addd812016-02-02 17:17:23 -070010629TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10630 // Create a single combined Image/Sampler descriptor and send it an invalid
10631 // imageView
10632 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010633
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010634 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010635
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010636 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010637 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010638 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10639 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010640
10641 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010642 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10643 ds_pool_ci.pNext = NULL;
10644 ds_pool_ci.maxSets = 1;
10645 ds_pool_ci.poolSizeCount = 1;
10646 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010647
10648 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010649 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010650 ASSERT_VK_SUCCESS(err);
10651
10652 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010653 dsl_binding.binding = 0;
10654 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10655 dsl_binding.descriptorCount = 1;
10656 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10657 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010658
10659 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010660 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10661 ds_layout_ci.pNext = NULL;
10662 ds_layout_ci.bindingCount = 1;
10663 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010664 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010665 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010666 ASSERT_VK_SUCCESS(err);
10667
10668 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010669 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010670 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010671 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010672 alloc_info.descriptorPool = ds_pool;
10673 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010674 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010675 ASSERT_VK_SUCCESS(err);
10676
10677 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010678 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10679 sampler_ci.pNext = NULL;
10680 sampler_ci.magFilter = VK_FILTER_NEAREST;
10681 sampler_ci.minFilter = VK_FILTER_NEAREST;
10682 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10683 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10684 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10685 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10686 sampler_ci.mipLodBias = 1.0;
10687 sampler_ci.anisotropyEnable = VK_FALSE;
10688 sampler_ci.maxAnisotropy = 1;
10689 sampler_ci.compareEnable = VK_FALSE;
10690 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10691 sampler_ci.minLod = 1.0;
10692 sampler_ci.maxLod = 1.0;
10693 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10694 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010695
10696 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010697 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010698 ASSERT_VK_SUCCESS(err);
10699
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010700 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010701
10702 VkDescriptorImageInfo descriptor_info;
10703 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10704 descriptor_info.sampler = sampler;
10705 descriptor_info.imageView = view;
10706
10707 VkWriteDescriptorSet descriptor_write;
10708 memset(&descriptor_write, 0, sizeof(descriptor_write));
10709 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010710 descriptor_write.dstSet = descriptorSet;
10711 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010712 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010713 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10714 descriptor_write.pImageInfo = &descriptor_info;
10715
10716 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10717
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010718 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010719
Chia-I Wuf7458c52015-10-26 21:10:41 +080010720 vkDestroySampler(m_device->device(), sampler, NULL);
10721 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10722 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010723}
10724
Karl Schultz6addd812016-02-02 17:17:23 -070010725TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10726 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10727 // into the other
10728 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010729
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010730 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10731 " binding #1 with type "
10732 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10733 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010734
Tobin Ehlis04356f92015-10-27 16:35:27 -060010735 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010736 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010737 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010738 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10739 ds_type_count[0].descriptorCount = 1;
10740 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10741 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010742
10743 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010744 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10745 ds_pool_ci.pNext = NULL;
10746 ds_pool_ci.maxSets = 1;
10747 ds_pool_ci.poolSizeCount = 2;
10748 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010749
10750 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010751 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010752 ASSERT_VK_SUCCESS(err);
10753 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010754 dsl_binding[0].binding = 0;
10755 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10756 dsl_binding[0].descriptorCount = 1;
10757 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10758 dsl_binding[0].pImmutableSamplers = NULL;
10759 dsl_binding[1].binding = 1;
10760 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10761 dsl_binding[1].descriptorCount = 1;
10762 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10763 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010764
10765 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010766 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10767 ds_layout_ci.pNext = NULL;
10768 ds_layout_ci.bindingCount = 2;
10769 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010770
10771 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010772 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010773 ASSERT_VK_SUCCESS(err);
10774
10775 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010776 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010777 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010778 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010779 alloc_info.descriptorPool = ds_pool;
10780 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010781 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010782 ASSERT_VK_SUCCESS(err);
10783
10784 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010785 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10786 sampler_ci.pNext = NULL;
10787 sampler_ci.magFilter = VK_FILTER_NEAREST;
10788 sampler_ci.minFilter = VK_FILTER_NEAREST;
10789 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10790 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10791 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10792 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10793 sampler_ci.mipLodBias = 1.0;
10794 sampler_ci.anisotropyEnable = VK_FALSE;
10795 sampler_ci.maxAnisotropy = 1;
10796 sampler_ci.compareEnable = VK_FALSE;
10797 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10798 sampler_ci.minLod = 1.0;
10799 sampler_ci.maxLod = 1.0;
10800 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10801 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010802
10803 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010804 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010805 ASSERT_VK_SUCCESS(err);
10806
10807 VkDescriptorImageInfo info = {};
10808 info.sampler = sampler;
10809
10810 VkWriteDescriptorSet descriptor_write;
10811 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10812 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010813 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010814 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010815 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010816 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10817 descriptor_write.pImageInfo = &info;
10818 // This write update should succeed
10819 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10820 // Now perform a copy update that fails due to type mismatch
10821 VkCopyDescriptorSet copy_ds_update;
10822 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10823 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10824 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010825 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010826 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010827 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10828 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010829 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10830
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010831 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010832 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010833 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 -060010834 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10835 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10836 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010837 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010838 copy_ds_update.dstSet = descriptorSet;
10839 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010840 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010841 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10842
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010843 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010844
Tobin Ehlis04356f92015-10-27 16:35:27 -060010845 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10847 " binding#1 with offset index of 1 plus "
10848 "update array offset of 0 and update of "
10849 "5 descriptors oversteps total number "
10850 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010851
Tobin Ehlis04356f92015-10-27 16:35:27 -060010852 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10853 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10854 copy_ds_update.srcSet = descriptorSet;
10855 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010856 copy_ds_update.dstSet = descriptorSet;
10857 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010858 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010859 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10860
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010861 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010862
Chia-I Wuf7458c52015-10-26 21:10:41 +080010863 vkDestroySampler(m_device->device(), sampler, NULL);
10864 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10865 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010866}
10867
Karl Schultz6addd812016-02-02 17:17:23 -070010868TEST_F(VkLayerTest, NumSamplesMismatch) {
10869 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10870 // sampleCount
10871 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010872
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010874
Tobin Ehlis3b780662015-05-28 12:11:26 -060010875 ASSERT_NO_FATAL_FAILURE(InitState());
10876 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010877 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010878 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010879 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010880
10881 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010882 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10883 ds_pool_ci.pNext = NULL;
10884 ds_pool_ci.maxSets = 1;
10885 ds_pool_ci.poolSizeCount = 1;
10886 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010887
Tobin Ehlis3b780662015-05-28 12:11:26 -060010888 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010889 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010890 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010891
Tony Barboureb254902015-07-15 12:50:33 -060010892 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010893 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010894 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010895 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010896 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10897 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010898
Tony Barboureb254902015-07-15 12:50:33 -060010899 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10900 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10901 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010902 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010903 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010904
Tobin Ehlis3b780662015-05-28 12:11:26 -060010905 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010906 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010907 ASSERT_VK_SUCCESS(err);
10908
10909 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010910 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010911 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010912 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010913 alloc_info.descriptorPool = ds_pool;
10914 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010915 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010916 ASSERT_VK_SUCCESS(err);
10917
Tony Barboureb254902015-07-15 12:50:33 -060010918 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010919 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010920 pipe_ms_state_ci.pNext = NULL;
10921 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10922 pipe_ms_state_ci.sampleShadingEnable = 0;
10923 pipe_ms_state_ci.minSampleShading = 1.0;
10924 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010925
Tony Barboureb254902015-07-15 12:50:33 -060010926 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010927 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10928 pipeline_layout_ci.pNext = NULL;
10929 pipeline_layout_ci.setLayoutCount = 1;
10930 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010931
10932 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010933 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010934 ASSERT_VK_SUCCESS(err);
10935
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010936 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010937 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 -060010938 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010939 VkPipelineObj pipe(m_device);
10940 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010941 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010942 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010943 pipe.SetMSAA(&pipe_ms_state_ci);
10944 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010945
Tony Barbour552f6c02016-12-21 14:34:07 -070010946 m_commandBuffer->BeginCommandBuffer();
10947 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010948 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010949
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010950 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10951 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10952 VkRect2D scissor = {{0, 0}, {16, 16}};
10953 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10954
Mark Young29927482016-05-04 14:38:51 -060010955 // Render triangle (the error should trigger on the attempt to draw).
10956 Draw(3, 1, 0, 0);
10957
10958 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010959 m_commandBuffer->EndRenderPass();
10960 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010961
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010962 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010963
Chia-I Wuf7458c52015-10-26 21:10:41 +080010964 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10965 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10966 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010967}
Mark Young29927482016-05-04 14:38:51 -060010968
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010969TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010970 TEST_DESCRIPTION(
10971 "Hit RenderPass incompatible cases. "
10972 "Initial case is drawing with an active renderpass that's "
10973 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010974 VkResult err;
10975
10976 ASSERT_NO_FATAL_FAILURE(InitState());
10977 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10978
10979 VkDescriptorSetLayoutBinding dsl_binding = {};
10980 dsl_binding.binding = 0;
10981 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10982 dsl_binding.descriptorCount = 1;
10983 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10984 dsl_binding.pImmutableSamplers = NULL;
10985
10986 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10987 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10988 ds_layout_ci.pNext = NULL;
10989 ds_layout_ci.bindingCount = 1;
10990 ds_layout_ci.pBindings = &dsl_binding;
10991
10992 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010993 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010994 ASSERT_VK_SUCCESS(err);
10995
10996 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10997 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10998 pipeline_layout_ci.pNext = NULL;
10999 pipeline_layout_ci.setLayoutCount = 1;
11000 pipeline_layout_ci.pSetLayouts = &ds_layout;
11001
11002 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011003 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011004 ASSERT_VK_SUCCESS(err);
11005
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011006 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011007 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 -060011008 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011009 // Create a renderpass that will be incompatible with default renderpass
11010 VkAttachmentReference attach = {};
11011 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
11012 VkAttachmentReference color_att = {};
11013 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11014 VkSubpassDescription subpass = {};
11015 subpass.inputAttachmentCount = 1;
11016 subpass.pInputAttachments = &attach;
11017 subpass.colorAttachmentCount = 1;
11018 subpass.pColorAttachments = &color_att;
11019 VkRenderPassCreateInfo rpci = {};
11020 rpci.subpassCount = 1;
11021 rpci.pSubpasses = &subpass;
11022 rpci.attachmentCount = 1;
11023 VkAttachmentDescription attach_desc = {};
11024 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060011025 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
11026 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011027 rpci.pAttachments = &attach_desc;
11028 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
11029 VkRenderPass rp;
11030 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11031 VkPipelineObj pipe(m_device);
11032 pipe.AddShader(&vs);
11033 pipe.AddShader(&fs);
11034 pipe.AddColorAttachment();
11035 VkViewport view_port = {};
11036 m_viewports.push_back(view_port);
11037 pipe.SetViewport(m_viewports);
11038 VkRect2D rect = {};
11039 m_scissors.push_back(rect);
11040 pipe.SetScissor(m_scissors);
11041 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11042
11043 VkCommandBufferInheritanceInfo cbii = {};
11044 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
11045 cbii.renderPass = rp;
11046 cbii.subpass = 0;
11047 VkCommandBufferBeginInfo cbbi = {};
11048 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
11049 cbbi.pInheritanceInfo = &cbii;
11050 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
11051 VkRenderPassBeginInfo rpbi = {};
11052 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
11053 rpbi.framebuffer = m_framebuffer;
11054 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011055 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
11056 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011057
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011059 // Render triangle (the error should trigger on the attempt to draw).
11060 Draw(3, 1, 0, 0);
11061
11062 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070011063 m_commandBuffer->EndRenderPass();
11064 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060011065
11066 m_errorMonitor->VerifyFound();
11067
11068 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11069 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11070 vkDestroyRenderPass(m_device->device(), rp, NULL);
11071}
11072
Mark Youngc89c6312016-03-31 16:03:20 -060011073TEST_F(VkLayerTest, NumBlendAttachMismatch) {
11074 // Create Pipeline where the number of blend attachments doesn't match the
11075 // number of color attachments. In this case, we don't add any color
11076 // blend attachments even though we have a color attachment.
11077 VkResult err;
11078
Tobin Ehlis974c0d92017-02-01 13:31:22 -070011079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060011080
11081 ASSERT_NO_FATAL_FAILURE(InitState());
11082 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11083 VkDescriptorPoolSize ds_type_count = {};
11084 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11085 ds_type_count.descriptorCount = 1;
11086
11087 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11088 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11089 ds_pool_ci.pNext = NULL;
11090 ds_pool_ci.maxSets = 1;
11091 ds_pool_ci.poolSizeCount = 1;
11092 ds_pool_ci.pPoolSizes = &ds_type_count;
11093
11094 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011095 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060011096 ASSERT_VK_SUCCESS(err);
11097
11098 VkDescriptorSetLayoutBinding dsl_binding = {};
11099 dsl_binding.binding = 0;
11100 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11101 dsl_binding.descriptorCount = 1;
11102 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11103 dsl_binding.pImmutableSamplers = NULL;
11104
11105 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11106 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11107 ds_layout_ci.pNext = NULL;
11108 ds_layout_ci.bindingCount = 1;
11109 ds_layout_ci.pBindings = &dsl_binding;
11110
11111 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011112 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011113 ASSERT_VK_SUCCESS(err);
11114
11115 VkDescriptorSet descriptorSet;
11116 VkDescriptorSetAllocateInfo alloc_info = {};
11117 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11118 alloc_info.descriptorSetCount = 1;
11119 alloc_info.descriptorPool = ds_pool;
11120 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011121 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011122 ASSERT_VK_SUCCESS(err);
11123
11124 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011125 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011126 pipe_ms_state_ci.pNext = NULL;
11127 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11128 pipe_ms_state_ci.sampleShadingEnable = 0;
11129 pipe_ms_state_ci.minSampleShading = 1.0;
11130 pipe_ms_state_ci.pSampleMask = NULL;
11131
11132 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11133 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11134 pipeline_layout_ci.pNext = NULL;
11135 pipeline_layout_ci.setLayoutCount = 1;
11136 pipeline_layout_ci.pSetLayouts = &ds_layout;
11137
11138 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011139 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011140 ASSERT_VK_SUCCESS(err);
11141
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011142 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011143 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 -060011144 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011145 VkPipelineObj pipe(m_device);
11146 pipe.AddShader(&vs);
11147 pipe.AddShader(&fs);
11148 pipe.SetMSAA(&pipe_ms_state_ci);
11149 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011150 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011151
11152 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11153 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11154 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11155}
Mark Young29927482016-05-04 14:38:51 -060011156
Mark Muellerd4914412016-06-13 17:52:06 -060011157TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011158 TEST_DESCRIPTION(
11159 "Points to a wrong colorAttachment index in a VkClearAttachment "
11160 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011161 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011163
11164 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11165 m_errorMonitor->VerifyFound();
11166}
11167
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011168TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011169 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11170 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011171
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011172 ASSERT_NO_FATAL_FAILURE(InitState());
11173 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011174
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011175 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011176 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11177 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011178
11179 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011180 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11181 ds_pool_ci.pNext = NULL;
11182 ds_pool_ci.maxSets = 1;
11183 ds_pool_ci.poolSizeCount = 1;
11184 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011185
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011186 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011187 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011188 ASSERT_VK_SUCCESS(err);
11189
Tony Barboureb254902015-07-15 12:50:33 -060011190 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011191 dsl_binding.binding = 0;
11192 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11193 dsl_binding.descriptorCount = 1;
11194 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11195 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011196
Tony Barboureb254902015-07-15 12:50:33 -060011197 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011198 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11199 ds_layout_ci.pNext = NULL;
11200 ds_layout_ci.bindingCount = 1;
11201 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011202
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011203 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011204 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011205 ASSERT_VK_SUCCESS(err);
11206
11207 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011208 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011209 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011210 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011211 alloc_info.descriptorPool = ds_pool;
11212 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011213 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011214 ASSERT_VK_SUCCESS(err);
11215
Tony Barboureb254902015-07-15 12:50:33 -060011216 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011217 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011218 pipe_ms_state_ci.pNext = NULL;
11219 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11220 pipe_ms_state_ci.sampleShadingEnable = 0;
11221 pipe_ms_state_ci.minSampleShading = 1.0;
11222 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011223
Tony Barboureb254902015-07-15 12:50:33 -060011224 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011225 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11226 pipeline_layout_ci.pNext = NULL;
11227 pipeline_layout_ci.setLayoutCount = 1;
11228 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011229
11230 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011231 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011232 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011233
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011234 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011235 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011236 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011238
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011239 VkPipelineObj pipe(m_device);
11240 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011241 pipe.AddShader(&fs);
Jeremy Hayes7332f342017-03-09 15:54:12 -070011242 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011243 pipe.SetMSAA(&pipe_ms_state_ci);
11244 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011245
Tony Barbour552f6c02016-12-21 14:34:07 -070011246 m_commandBuffer->BeginCommandBuffer();
11247 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011248
Karl Schultz6addd812016-02-02 17:17:23 -070011249 // Main thing we care about for this test is that the VkImage obj we're
11250 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011251 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011252 VkClearAttachment color_attachment;
11253 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11254 color_attachment.clearValue.color.float32[0] = 1.0;
11255 color_attachment.clearValue.color.float32[1] = 1.0;
11256 color_attachment.clearValue.color.float32[2] = 1.0;
11257 color_attachment.clearValue.color.float32[3] = 1.0;
11258 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011259 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011260
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011261 // Call for full-sized FB Color attachment prior to issuing a Draw
11262 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011263 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011264 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011265 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011266
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011267 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11268 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11269 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11270 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11271 m_errorMonitor->VerifyFound();
11272
11273 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11274 clear_rect.layerCount = 2;
11275 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11276 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011277 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011278
Chia-I Wuf7458c52015-10-26 21:10:41 +080011279 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11280 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11281 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011282}
11283
Karl Schultz6addd812016-02-02 17:17:23 -070011284TEST_F(VkLayerTest, VtxBufferBadIndex) {
11285 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11288 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011289
Tobin Ehlis502480b2015-06-24 15:53:07 -060011290 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011291 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011293
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011294 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011295 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11296 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011297
11298 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011299 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11300 ds_pool_ci.pNext = NULL;
11301 ds_pool_ci.maxSets = 1;
11302 ds_pool_ci.poolSizeCount = 1;
11303 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011304
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011305 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011306 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011307 ASSERT_VK_SUCCESS(err);
11308
Tony Barboureb254902015-07-15 12:50:33 -060011309 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011310 dsl_binding.binding = 0;
11311 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11312 dsl_binding.descriptorCount = 1;
11313 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11314 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011315
Tony Barboureb254902015-07-15 12:50:33 -060011316 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011317 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11318 ds_layout_ci.pNext = NULL;
11319 ds_layout_ci.bindingCount = 1;
11320 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011321
Tobin Ehlis502480b2015-06-24 15:53:07 -060011322 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011323 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011324 ASSERT_VK_SUCCESS(err);
11325
11326 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011327 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011328 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011329 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011330 alloc_info.descriptorPool = ds_pool;
11331 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011332 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011333 ASSERT_VK_SUCCESS(err);
11334
Tony Barboureb254902015-07-15 12:50:33 -060011335 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011336 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011337 pipe_ms_state_ci.pNext = NULL;
11338 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11339 pipe_ms_state_ci.sampleShadingEnable = 0;
11340 pipe_ms_state_ci.minSampleShading = 1.0;
11341 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011342
Tony Barboureb254902015-07-15 12:50:33 -060011343 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011344 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11345 pipeline_layout_ci.pNext = NULL;
11346 pipeline_layout_ci.setLayoutCount = 1;
11347 pipeline_layout_ci.pSetLayouts = &ds_layout;
11348 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011349
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011350 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011351 ASSERT_VK_SUCCESS(err);
11352
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011353 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011354 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 -060011355 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011356 VkPipelineObj pipe(m_device);
11357 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011358 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011359 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011360 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011361 pipe.SetViewport(m_viewports);
11362 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011363 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011364
Tony Barbour552f6c02016-12-21 14:34:07 -070011365 m_commandBuffer->BeginCommandBuffer();
11366 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011367 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011368 // Don't care about actual data, just need to get to draw to flag error
11369 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011370 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011371 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011372 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011373
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011374 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011375
Chia-I Wuf7458c52015-10-26 21:10:41 +080011376 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11377 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11378 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011379}
Mark Muellerdfe37552016-07-07 14:47:42 -060011380
Mark Mueller2ee294f2016-08-04 12:59:48 -060011381TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011382 TEST_DESCRIPTION(
11383 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11384 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011385 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011386
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011387 const char *invalid_queueFamilyIndex_message =
11388 "Invalid queue create request in vkCreateDevice(). Invalid "
11389 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011390
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011391 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011392
Mark Mueller880fce52016-08-17 15:23:23 -060011393 // The following test fails with recent NVidia drivers.
11394 // By the time core_validation is reached, the NVidia
11395 // driver has sanitized the invalid condition and core_validation
11396 // is not introduced to the failure condition. This is not the case
11397 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011398 // uint32_t count = static_cast<uint32_t>(~0);
11399 // VkPhysicalDevice physical_device;
11400 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11401 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011402
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011404 float queue_priority = 0.0;
11405
11406 VkDeviceQueueCreateInfo queue_create_info = {};
11407 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11408 queue_create_info.queueCount = 1;
11409 queue_create_info.pQueuePriorities = &queue_priority;
11410 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11411
11412 VkPhysicalDeviceFeatures features = m_device->phy().features();
11413 VkDevice testDevice;
11414 VkDeviceCreateInfo device_create_info = {};
11415 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11416 device_create_info.queueCreateInfoCount = 1;
11417 device_create_info.pQueueCreateInfos = &queue_create_info;
11418 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011419 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011420 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11421 m_errorMonitor->VerifyFound();
11422
11423 queue_create_info.queueFamilyIndex = 1;
11424
11425 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11426 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11427 for (unsigned i = 0; i < feature_count; i++) {
11428 if (VK_FALSE == feature_array[i]) {
11429 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011430 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011431 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011432 m_errorMonitor->SetUnexpectedError(
11433 "You requested features that are unavailable on this device. You should first query feature availability by "
11434 "calling vkGetPhysicalDeviceFeatures().");
11435 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011436 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11437 m_errorMonitor->VerifyFound();
11438 break;
11439 }
11440 }
11441}
11442
Tobin Ehlis16edf082016-11-21 12:33:49 -070011443TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11444 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11445
11446 ASSERT_NO_FATAL_FAILURE(InitState());
11447
11448 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11449 std::vector<VkDeviceQueueCreateInfo> queue_info;
11450 queue_info.reserve(queue_props.size());
11451 std::vector<std::vector<float>> queue_priorities;
11452 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11453 VkDeviceQueueCreateInfo qi{};
11454 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11455 qi.queueFamilyIndex = i;
11456 qi.queueCount = queue_props[i].queueCount;
11457 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11458 qi.pQueuePriorities = queue_priorities[i].data();
11459 queue_info.push_back(qi);
11460 }
11461
11462 std::vector<const char *> device_extension_names;
11463
11464 VkDevice local_device;
11465 VkDeviceCreateInfo device_create_info = {};
11466 auto features = m_device->phy().features();
11467 // Intentionally disable pipeline stats
11468 features.pipelineStatisticsQuery = VK_FALSE;
11469 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11470 device_create_info.pNext = NULL;
11471 device_create_info.queueCreateInfoCount = queue_info.size();
11472 device_create_info.pQueueCreateInfos = queue_info.data();
11473 device_create_info.enabledLayerCount = 0;
11474 device_create_info.ppEnabledLayerNames = NULL;
11475 device_create_info.pEnabledFeatures = &features;
11476 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11477 ASSERT_VK_SUCCESS(err);
11478
11479 VkQueryPoolCreateInfo qpci{};
11480 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11481 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11482 qpci.queryCount = 1;
11483 VkQueryPool query_pool;
11484
11485 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11486 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11487 m_errorMonitor->VerifyFound();
11488
11489 vkDestroyDevice(local_device, nullptr);
11490}
11491
Mark Mueller2ee294f2016-08-04 12:59:48 -060011492TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011493 TEST_DESCRIPTION(
11494 "Use an invalid queue index in a vkCmdWaitEvents call."
11495 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011496
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011497 const char *invalid_queue_index =
11498 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11499 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11500 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011501
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011502 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011503
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011504 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011505
11506 ASSERT_NO_FATAL_FAILURE(InitState());
11507
11508 VkEvent event;
11509 VkEventCreateInfo event_create_info{};
11510 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11511 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11512
Mark Mueller2ee294f2016-08-04 12:59:48 -060011513 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011514 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011515
Tony Barbour552f6c02016-12-21 14:34:07 -070011516 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011517
11518 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011519 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 -060011520 ASSERT_TRUE(image.initialized());
11521 VkImageMemoryBarrier img_barrier = {};
11522 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11523 img_barrier.pNext = NULL;
11524 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11525 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11526 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11527 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11528 img_barrier.image = image.handle();
11529 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011530
11531 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11532 // that layer validation catches the case when it is not.
11533 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011534 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11535 img_barrier.subresourceRange.baseArrayLayer = 0;
11536 img_barrier.subresourceRange.baseMipLevel = 0;
11537 img_barrier.subresourceRange.layerCount = 1;
11538 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011539 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11540 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011541 m_errorMonitor->VerifyFound();
11542
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011543 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011544
11545 VkQueryPool query_pool;
11546 VkQueryPoolCreateInfo query_pool_create_info = {};
11547 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11548 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11549 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011550 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011551
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011552 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011553 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11554
11555 vkEndCommandBuffer(m_commandBuffer->handle());
11556 m_errorMonitor->VerifyFound();
11557
11558 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11559 vkDestroyEvent(m_device->device(), event, nullptr);
11560}
11561
Mark Muellerdfe37552016-07-07 14:47:42 -060011562TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011563 TEST_DESCRIPTION(
11564 "Submit a command buffer using deleted vertex buffer, "
11565 "delete a buffer twice, use an invalid offset for each "
11566 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011567
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011568 const char *deleted_buffer_in_command_buffer =
11569 "Cannot submit cmd buffer "
11570 "using deleted buffer ";
11571 const char *invalid_offset_message =
11572 "vkBindBufferMemory(): "
11573 "memoryOffset is 0x";
11574 const char *invalid_storage_buffer_offset_message =
11575 "vkBindBufferMemory(): "
11576 "storage memoryOffset "
11577 "is 0x";
11578 const char *invalid_texel_buffer_offset_message =
11579 "vkBindBufferMemory(): "
11580 "texel memoryOffset "
11581 "is 0x";
11582 const char *invalid_uniform_buffer_offset_message =
11583 "vkBindBufferMemory(): "
11584 "uniform memoryOffset "
11585 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011586
11587 ASSERT_NO_FATAL_FAILURE(InitState());
11588 ASSERT_NO_FATAL_FAILURE(InitViewport());
11589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11590
11591 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011592 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011593 pipe_ms_state_ci.pNext = NULL;
11594 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11595 pipe_ms_state_ci.sampleShadingEnable = 0;
11596 pipe_ms_state_ci.minSampleShading = 1.0;
11597 pipe_ms_state_ci.pSampleMask = nullptr;
11598
11599 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11600 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11601 VkPipelineLayout pipeline_layout;
11602
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011603 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011604 ASSERT_VK_SUCCESS(err);
11605
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011606 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11607 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011608 VkPipelineObj pipe(m_device);
11609 pipe.AddShader(&vs);
11610 pipe.AddShader(&fs);
11611 pipe.AddColorAttachment();
11612 pipe.SetMSAA(&pipe_ms_state_ci);
11613 pipe.SetViewport(m_viewports);
11614 pipe.SetScissor(m_scissors);
11615 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11616
Tony Barbour552f6c02016-12-21 14:34:07 -070011617 m_commandBuffer->BeginCommandBuffer();
11618 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011619 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011620
11621 {
11622 // Create and bind a vertex buffer in a reduced scope, which will cause
11623 // it to be deleted upon leaving this scope
11624 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011625 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011626 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11627 draw_verticies.AddVertexInputToPipe(pipe);
11628 }
11629
11630 Draw(1, 0, 0, 0);
11631
Tony Barbour552f6c02016-12-21 14:34:07 -070011632 m_commandBuffer->EndRenderPass();
11633 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011635 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011636 QueueCommandBuffer(false);
11637 m_errorMonitor->VerifyFound();
11638
11639 {
11640 // Create and bind a vertex buffer in a reduced scope, and delete it
11641 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011642 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011644 buffer_test.TestDoubleDestroy();
11645 }
11646 m_errorMonitor->VerifyFound();
11647
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011648 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011649 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011650 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011651 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011652 m_errorMonitor->SetUnexpectedError(
11653 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11654 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011655 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11656 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011657 m_errorMonitor->VerifyFound();
11658 }
11659
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011660 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11661 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011662 // Create and bind a memory buffer with an invalid offset again,
11663 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011665 m_errorMonitor->SetUnexpectedError(
11666 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11667 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011668 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11669 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011670 m_errorMonitor->VerifyFound();
11671 }
11672
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011673 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011674 // Create and bind a memory buffer with an invalid offset again, but
11675 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011677 m_errorMonitor->SetUnexpectedError(
11678 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11679 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011680 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11681 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011682 m_errorMonitor->VerifyFound();
11683 }
11684
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011685 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011686 // Create and bind a memory buffer with an invalid offset again, but
11687 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011688 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011689 m_errorMonitor->SetUnexpectedError(
11690 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11691 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011692 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11693 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011694 m_errorMonitor->VerifyFound();
11695 }
11696
11697 {
11698 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011699 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011700 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11701 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011702 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11703 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011704 m_errorMonitor->VerifyFound();
11705 }
11706
11707 {
11708 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011709 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011710 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11711 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011712 }
11713 m_errorMonitor->VerifyFound();
11714
11715 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11716}
11717
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011718// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11719TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011720 TEST_DESCRIPTION(
11721 "Hit all possible validation checks associated with the "
11722 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11723 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011724 // 3 in ValidateCmdBufImageLayouts
11725 // * -1 Attempt to submit cmd buf w/ deleted image
11726 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11727 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011728
11729 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011730 auto depth_format = find_depth_stencil_format(m_device);
11731 if (!depth_format) {
11732 printf(" No Depth + Stencil format found. Skipped.\n");
11733 return;
11734 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011735 // Create src & dst images to use for copy operations
11736 VkImage src_image;
11737 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011738 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011739
11740 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11741 const int32_t tex_width = 32;
11742 const int32_t tex_height = 32;
11743
11744 VkImageCreateInfo image_create_info = {};
11745 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11746 image_create_info.pNext = NULL;
11747 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11748 image_create_info.format = tex_format;
11749 image_create_info.extent.width = tex_width;
11750 image_create_info.extent.height = tex_height;
11751 image_create_info.extent.depth = 1;
11752 image_create_info.mipLevels = 1;
11753 image_create_info.arrayLayers = 4;
11754 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11755 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11756 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011757 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011758 image_create_info.flags = 0;
11759
11760 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11761 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011762 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011763 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11764 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011765 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11766 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11767 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11768 ASSERT_VK_SUCCESS(err);
11769
11770 // Allocate memory
11771 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011772 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011773 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011774 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11775 mem_alloc.pNext = NULL;
11776 mem_alloc.allocationSize = 0;
11777 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011778
11779 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011780 mem_alloc.allocationSize = img_mem_reqs.size;
11781 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011782 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011783 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011784 ASSERT_VK_SUCCESS(err);
11785
11786 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011787 mem_alloc.allocationSize = img_mem_reqs.size;
11788 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011789 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011790 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011791 ASSERT_VK_SUCCESS(err);
11792
11793 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011794 mem_alloc.allocationSize = img_mem_reqs.size;
11795 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011796 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011797 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011798 ASSERT_VK_SUCCESS(err);
11799
11800 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11801 ASSERT_VK_SUCCESS(err);
11802 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11803 ASSERT_VK_SUCCESS(err);
11804 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11805 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011806
Tony Barbour552f6c02016-12-21 14:34:07 -070011807 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011808 VkImageCopy copy_region;
11809 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11810 copy_region.srcSubresource.mipLevel = 0;
11811 copy_region.srcSubresource.baseArrayLayer = 0;
11812 copy_region.srcSubresource.layerCount = 1;
11813 copy_region.srcOffset.x = 0;
11814 copy_region.srcOffset.y = 0;
11815 copy_region.srcOffset.z = 0;
11816 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11817 copy_region.dstSubresource.mipLevel = 0;
11818 copy_region.dstSubresource.baseArrayLayer = 0;
11819 copy_region.dstSubresource.layerCount = 1;
11820 copy_region.dstOffset.x = 0;
11821 copy_region.dstOffset.y = 0;
11822 copy_region.dstOffset.z = 0;
11823 copy_region.extent.width = 1;
11824 copy_region.extent.height = 1;
11825 copy_region.extent.depth = 1;
11826
11827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11828 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011829 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011830 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 -060011831 m_errorMonitor->VerifyFound();
11832 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011833 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11834 "Cannot copy from an image whose source layout is "
11835 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11836 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011837 m_errorMonitor->SetUnexpectedError(
11838 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011839 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 -060011840 m_errorMonitor->VerifyFound();
11841 // Final src error is due to bad layout type
11842 m_errorMonitor->SetDesiredFailureMsg(
11843 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11844 "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 -070011845 m_errorMonitor->SetUnexpectedError(
11846 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11847 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011848 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 -060011849 m_errorMonitor->VerifyFound();
11850 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11852 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011853 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011854 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 -060011855 m_errorMonitor->VerifyFound();
11856 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011857 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11858 "Cannot copy from an image whose dest layout is "
11859 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11860 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011861 m_errorMonitor->SetUnexpectedError(
11862 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011863 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 -060011864 m_errorMonitor->VerifyFound();
11865 m_errorMonitor->SetDesiredFailureMsg(
11866 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11867 "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 -070011868 m_errorMonitor->SetUnexpectedError(
11869 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11870 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011871 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 -060011872 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011873
Cort3b021012016-12-07 12:00:57 -080011874 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11875 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11876 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11877 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11878 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11879 transfer_dst_image_barrier[0].srcAccessMask = 0;
11880 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11881 transfer_dst_image_barrier[0].image = dst_image;
11882 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11883 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11884 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11885 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11886 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11887 transfer_dst_image_barrier[0].image = depth_image;
11888 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11889 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11890 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11891
11892 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011893 VkClearColorValue color_clear_value = {};
11894 VkImageSubresourceRange clear_range;
11895 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11896 clear_range.baseMipLevel = 0;
11897 clear_range.baseArrayLayer = 0;
11898 clear_range.layerCount = 1;
11899 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011900
Cort3b021012016-12-07 12:00:57 -080011901 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11902 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011905 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011906 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011907 // Fail due to provided layout not matching actual current layout for color clear.
11908 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011909 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011910 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011911
Cort530cf382016-12-08 09:59:47 -080011912 VkClearDepthStencilValue depth_clear_value = {};
11913 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011914
11915 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11916 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11917 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011919 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011920 m_errorMonitor->VerifyFound();
11921 // Fail due to provided layout not matching actual current layout for depth clear.
11922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011923 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011924 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011925
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011926 // Now cause error due to bad image layout transition in PipelineBarrier
11927 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011928 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011929 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011930 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011931 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011932 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11933 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011934 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011935 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11936 "You cannot transition the layout of aspect 1 from "
11937 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11938 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mike Weiblen62d08a32017-03-07 22:18:27 -070011939 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00305);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011940 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11941 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011942 m_errorMonitor->VerifyFound();
11943
11944 // Finally some layout errors at RenderPass create time
11945 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11946 VkAttachmentReference attach = {};
11947 // perf warning for GENERAL layout w/ non-DS input attachment
11948 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11949 VkSubpassDescription subpass = {};
11950 subpass.inputAttachmentCount = 1;
11951 subpass.pInputAttachments = &attach;
11952 VkRenderPassCreateInfo rpci = {};
11953 rpci.subpassCount = 1;
11954 rpci.pSubpasses = &subpass;
11955 rpci.attachmentCount = 1;
11956 VkAttachmentDescription attach_desc = {};
11957 attach_desc.format = VK_FORMAT_UNDEFINED;
11958 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011959 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011960 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11962 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011963 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11964 m_errorMonitor->VerifyFound();
11965 // error w/ non-general layout
11966 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11967
11968 m_errorMonitor->SetDesiredFailureMsg(
11969 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11970 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11971 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11972 m_errorMonitor->VerifyFound();
11973 subpass.inputAttachmentCount = 0;
11974 subpass.colorAttachmentCount = 1;
11975 subpass.pColorAttachments = &attach;
11976 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11977 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011978 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11979 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011980 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11981 m_errorMonitor->VerifyFound();
11982 // error w/ non-color opt or GENERAL layout for color attachment
11983 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11984 m_errorMonitor->SetDesiredFailureMsg(
11985 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11986 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11987 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11988 m_errorMonitor->VerifyFound();
11989 subpass.colorAttachmentCount = 0;
11990 subpass.pDepthStencilAttachment = &attach;
11991 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11992 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011993 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11994 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011995 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11996 m_errorMonitor->VerifyFound();
11997 // error w/ non-ds opt or GENERAL layout for color attachment
11998 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12000 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
12001 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012002 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12003 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060012004 // For this error we need a valid renderpass so create default one
12005 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12006 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070012007 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060012008 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
12009 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
12010 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
12011 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
12012 // Can't do a CLEAR load on READ_ONLY initialLayout
12013 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
12014 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
12015 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012016 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12017 " with invalid first layout "
12018 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
12019 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060012020 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
12021 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012022
Cort3b021012016-12-07 12:00:57 -080012023 vkFreeMemory(m_device->device(), src_image_mem, NULL);
12024 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
12025 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012026 vkDestroyImage(m_device->device(), src_image, NULL);
12027 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080012028 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060012029}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060012030
Tobin Ehlise0936662016-10-11 08:10:51 -060012031TEST_F(VkLayerTest, InvalidStorageImageLayout) {
12032 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
12033 VkResult err;
12034
12035 ASSERT_NO_FATAL_FAILURE(InitState());
12036
12037 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
12038 VkImageTiling tiling;
12039 VkFormatProperties format_properties;
12040 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
12041 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12042 tiling = VK_IMAGE_TILING_LINEAR;
12043 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
12044 tiling = VK_IMAGE_TILING_OPTIMAL;
12045 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070012046 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060012047 return;
12048 }
12049
12050 VkDescriptorPoolSize ds_type = {};
12051 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12052 ds_type.descriptorCount = 1;
12053
12054 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12055 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12056 ds_pool_ci.maxSets = 1;
12057 ds_pool_ci.poolSizeCount = 1;
12058 ds_pool_ci.pPoolSizes = &ds_type;
12059 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
12060
12061 VkDescriptorPool ds_pool;
12062 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12063 ASSERT_VK_SUCCESS(err);
12064
12065 VkDescriptorSetLayoutBinding dsl_binding = {};
12066 dsl_binding.binding = 0;
12067 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12068 dsl_binding.descriptorCount = 1;
12069 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12070 dsl_binding.pImmutableSamplers = NULL;
12071
12072 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12073 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12074 ds_layout_ci.pNext = NULL;
12075 ds_layout_ci.bindingCount = 1;
12076 ds_layout_ci.pBindings = &dsl_binding;
12077
12078 VkDescriptorSetLayout ds_layout;
12079 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12080 ASSERT_VK_SUCCESS(err);
12081
12082 VkDescriptorSetAllocateInfo alloc_info = {};
12083 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12084 alloc_info.descriptorSetCount = 1;
12085 alloc_info.descriptorPool = ds_pool;
12086 alloc_info.pSetLayouts = &ds_layout;
12087 VkDescriptorSet descriptor_set;
12088 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12089 ASSERT_VK_SUCCESS(err);
12090
12091 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12092 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12093 pipeline_layout_ci.pNext = NULL;
12094 pipeline_layout_ci.setLayoutCount = 1;
12095 pipeline_layout_ci.pSetLayouts = &ds_layout;
12096 VkPipelineLayout pipeline_layout;
12097 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12098 ASSERT_VK_SUCCESS(err);
12099
12100 VkImageObj image(m_device);
12101 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12102 ASSERT_TRUE(image.initialized());
12103 VkImageView view = image.targetView(tex_format);
12104
12105 VkDescriptorImageInfo image_info = {};
12106 image_info.imageView = view;
12107 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12108
12109 VkWriteDescriptorSet descriptor_write = {};
12110 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12111 descriptor_write.dstSet = descriptor_set;
12112 descriptor_write.dstBinding = 0;
12113 descriptor_write.descriptorCount = 1;
12114 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12115 descriptor_write.pImageInfo = &image_info;
12116
12117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12118 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12119 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12120 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12121 m_errorMonitor->VerifyFound();
12122
12123 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12124 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12125 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12126 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12127}
12128
Mark Mueller93b938f2016-08-18 10:27:40 -060012129TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012130 TEST_DESCRIPTION(
12131 "Use vkCmdExecuteCommands with invalid state "
12132 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012133
12134 ASSERT_NO_FATAL_FAILURE(InitState());
12135 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12136
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012137 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012138 const char *simultaneous_use_message2 =
12139 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12140 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012141
12142 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012143 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012144 command_buffer_allocate_info.commandPool = m_commandPool;
12145 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12146 command_buffer_allocate_info.commandBufferCount = 1;
12147
12148 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012149 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012150 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12151 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012152 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012153 command_buffer_inheritance_info.renderPass = m_renderPass;
12154 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012155
Mark Mueller93b938f2016-08-18 10:27:40 -060012156 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012157 command_buffer_begin_info.flags =
12158 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012159 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12160
12161 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12162 vkEndCommandBuffer(secondary_command_buffer);
12163
Mark Mueller93b938f2016-08-18 10:27:40 -060012164 VkSubmitInfo submit_info = {};
12165 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12166 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012167 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012168
Mark Mueller4042b652016-09-05 22:52:21 -060012169 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012170 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12171 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12172 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012173 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012174 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012175 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12176 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012177
Dave Houltonfbf52152017-01-06 12:55:29 -070012178 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012179 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012180 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012181
Mark Mueller4042b652016-09-05 22:52:21 -060012182 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012183 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12184 m_errorMonitor->SetUnexpectedError(
12185 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12186 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012187 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012188 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012189
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012190 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12191 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012192 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012193 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12194 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012195
12196 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012197
12198 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012199}
12200
Tony Barbour626994c2017-02-08 15:29:37 -070012201TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12202 TEST_DESCRIPTION(
12203 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12204 "errors");
12205 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12206 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12207 ASSERT_NO_FATAL_FAILURE(InitState());
12208
12209 VkCommandBuffer cmd_bufs[2];
12210 VkCommandBufferAllocateInfo alloc_info;
12211 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12212 alloc_info.pNext = NULL;
12213 alloc_info.commandBufferCount = 2;
12214 alloc_info.commandPool = m_commandPool;
12215 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12216 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12217
12218 VkCommandBufferBeginInfo cb_binfo;
12219 cb_binfo.pNext = NULL;
12220 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12221 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12222 cb_binfo.flags = 0;
12223 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12224 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12225 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12226 vkEndCommandBuffer(cmd_bufs[0]);
12227 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12228
12229 VkSubmitInfo submit_info = {};
12230 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12231 submit_info.commandBufferCount = 2;
12232 submit_info.pCommandBuffers = duplicates;
12233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12234 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12235 m_errorMonitor->VerifyFound();
12236 vkQueueWaitIdle(m_device->m_queue);
12237
12238 // Set one time use and now look for one time submit
12239 duplicates[0] = duplicates[1] = cmd_bufs[1];
12240 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12241 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12242 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12243 vkEndCommandBuffer(cmd_bufs[1]);
12244 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12245 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12246 m_errorMonitor->VerifyFound();
12247 vkQueueWaitIdle(m_device->m_queue);
12248}
12249
Tobin Ehlisb093da82017-01-19 12:05:27 -070012250TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012251 TEST_DESCRIPTION(
12252 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12253 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012254
12255 ASSERT_NO_FATAL_FAILURE(InitState());
12256 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12257
12258 std::vector<const char *> device_extension_names;
12259 auto features = m_device->phy().features();
12260 // Make sure gs & ts are disabled
12261 features.geometryShader = false;
12262 features.tessellationShader = false;
12263 // The sacrificial device object
12264 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12265
12266 VkCommandPoolCreateInfo pool_create_info{};
12267 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12268 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12269
12270 VkCommandPool command_pool;
12271 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12272
12273 VkCommandBufferAllocateInfo cmd = {};
12274 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12275 cmd.pNext = NULL;
12276 cmd.commandPool = command_pool;
12277 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12278 cmd.commandBufferCount = 1;
12279
12280 VkCommandBuffer cmd_buffer;
12281 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12282 ASSERT_VK_SUCCESS(err);
12283
12284 VkEvent event;
12285 VkEventCreateInfo evci = {};
12286 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12287 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12288 ASSERT_VK_SUCCESS(result);
12289
12290 VkCommandBufferBeginInfo cbbi = {};
12291 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12292 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12293 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12294 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12295 m_errorMonitor->VerifyFound();
12296
12297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12298 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12299 m_errorMonitor->VerifyFound();
12300
12301 vkDestroyEvent(test_device.handle(), event, NULL);
12302 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12303}
12304
Mark Mueller917f6bc2016-08-30 10:57:19 -060012305TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012306 TEST_DESCRIPTION(
12307 "Use vkCmdExecuteCommands with invalid state "
12308 "in primary and secondary command buffers. "
12309 "Delete objects that are inuse. Call VkQueueSubmit "
12310 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012311
12312 ASSERT_NO_FATAL_FAILURE(InitState());
12313 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12314
Tony Barbour552f6c02016-12-21 14:34:07 -070012315 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012316
12317 VkEvent event;
12318 VkEventCreateInfo event_create_info = {};
12319 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12320 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012321 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012322
Tony Barbour552f6c02016-12-21 14:34:07 -070012323 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012324 vkDestroyEvent(m_device->device(), event, nullptr);
12325
12326 VkSubmitInfo submit_info = {};
12327 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12328 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012329 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012331 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12332 m_errorMonitor->VerifyFound();
12333
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012334 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012335 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12336
12337 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12338
Mark Mueller917f6bc2016-08-30 10:57:19 -060012339 VkSemaphoreCreateInfo semaphore_create_info = {};
12340 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12341 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012342 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012343 VkFenceCreateInfo fence_create_info = {};
12344 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12345 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012346 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012347
12348 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012349 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012350 descriptor_pool_type_count.descriptorCount = 1;
12351
12352 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12353 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12354 descriptor_pool_create_info.maxSets = 1;
12355 descriptor_pool_create_info.poolSizeCount = 1;
12356 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012357 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012358
12359 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012360 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012361
12362 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012363 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012364 descriptorset_layout_binding.descriptorCount = 1;
12365 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12366
12367 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012368 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012369 descriptorset_layout_create_info.bindingCount = 1;
12370 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12371
12372 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012373 ASSERT_VK_SUCCESS(
12374 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012375
12376 VkDescriptorSet descriptorset;
12377 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012378 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012379 descriptorset_allocate_info.descriptorSetCount = 1;
12380 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12381 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012382 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012383
Mark Mueller4042b652016-09-05 22:52:21 -060012384 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12385
12386 VkDescriptorBufferInfo buffer_info = {};
12387 buffer_info.buffer = buffer_test.GetBuffer();
12388 buffer_info.offset = 0;
12389 buffer_info.range = 1024;
12390
12391 VkWriteDescriptorSet write_descriptor_set = {};
12392 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12393 write_descriptor_set.dstSet = descriptorset;
12394 write_descriptor_set.descriptorCount = 1;
12395 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12396 write_descriptor_set.pBufferInfo = &buffer_info;
12397
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012398 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012399
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012400 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12401 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012402
12403 VkPipelineObj pipe(m_device);
12404 pipe.AddColorAttachment();
12405 pipe.AddShader(&vs);
12406 pipe.AddShader(&fs);
12407
12408 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012409 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012410 pipeline_layout_create_info.setLayoutCount = 1;
12411 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12412
12413 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012414 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012415
12416 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12417
Tony Barbour552f6c02016-12-21 14:34:07 -070012418 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012419 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012420
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012421 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12422 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12423 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012424
Tony Barbour552f6c02016-12-21 14:34:07 -070012425 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012426
Mark Mueller917f6bc2016-08-30 10:57:19 -060012427 submit_info.signalSemaphoreCount = 1;
12428 submit_info.pSignalSemaphores = &semaphore;
12429 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012430 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012431
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012432 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012433 vkDestroyEvent(m_device->device(), event, nullptr);
12434 m_errorMonitor->VerifyFound();
12435
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012437 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12438 m_errorMonitor->VerifyFound();
12439
Jeremy Hayes08369882017-02-02 10:31:06 -070012440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012441 vkDestroyFence(m_device->device(), fence, nullptr);
12442 m_errorMonitor->VerifyFound();
12443
Tobin Ehlis122207b2016-09-01 08:50:06 -070012444 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012445 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12446 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012447 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012448 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12449 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012450 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012451 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12452 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012453 vkDestroyEvent(m_device->device(), event, nullptr);
12454 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012455 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012456 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12457}
12458
Tobin Ehlis2adda372016-09-01 08:51:06 -070012459TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12460 TEST_DESCRIPTION("Delete in-use query pool.");
12461
12462 ASSERT_NO_FATAL_FAILURE(InitState());
12463 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12464
12465 VkQueryPool query_pool;
12466 VkQueryPoolCreateInfo query_pool_ci{};
12467 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12468 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12469 query_pool_ci.queryCount = 1;
12470 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012471 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012472 // Reset query pool to create binding with cmd buffer
12473 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12474
Tony Barbour552f6c02016-12-21 14:34:07 -070012475 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012476
12477 VkSubmitInfo submit_info = {};
12478 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12479 submit_info.commandBufferCount = 1;
12480 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12481 // Submit cmd buffer and then destroy query pool while in-flight
12482 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12483
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012484 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012485 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12486 m_errorMonitor->VerifyFound();
12487
12488 vkQueueWaitIdle(m_device->m_queue);
12489 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012490 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12491 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012492 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12493}
12494
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012495TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12496 TEST_DESCRIPTION("Delete in-use pipeline.");
12497
12498 ASSERT_NO_FATAL_FAILURE(InitState());
12499 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12500
12501 // Empty pipeline layout used for binding PSO
12502 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12503 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12504 pipeline_layout_ci.setLayoutCount = 0;
12505 pipeline_layout_ci.pSetLayouts = NULL;
12506
12507 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012508 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012509 ASSERT_VK_SUCCESS(err);
12510
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012512 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012513 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12514 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012515 // Store pipeline handle so we can actually delete it before test finishes
12516 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012517 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012518 VkPipelineObj pipe(m_device);
12519 pipe.AddShader(&vs);
12520 pipe.AddShader(&fs);
12521 pipe.AddColorAttachment();
12522 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12523 delete_this_pipeline = pipe.handle();
12524
Tony Barbour552f6c02016-12-21 14:34:07 -070012525 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012526 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012527 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012528
Tony Barbour552f6c02016-12-21 14:34:07 -070012529 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012530
12531 VkSubmitInfo submit_info = {};
12532 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12533 submit_info.commandBufferCount = 1;
12534 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12535 // Submit cmd buffer and then pipeline destroyed while in-flight
12536 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012537 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012538 m_errorMonitor->VerifyFound();
12539 // Make sure queue finished and then actually delete pipeline
12540 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012541 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12542 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012543 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12544 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12545}
12546
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012547TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12548 TEST_DESCRIPTION("Delete in-use imageView.");
12549
12550 ASSERT_NO_FATAL_FAILURE(InitState());
12551 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12552
12553 VkDescriptorPoolSize ds_type_count;
12554 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12555 ds_type_count.descriptorCount = 1;
12556
12557 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12558 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12559 ds_pool_ci.maxSets = 1;
12560 ds_pool_ci.poolSizeCount = 1;
12561 ds_pool_ci.pPoolSizes = &ds_type_count;
12562
12563 VkDescriptorPool ds_pool;
12564 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12565 ASSERT_VK_SUCCESS(err);
12566
12567 VkSamplerCreateInfo sampler_ci = {};
12568 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12569 sampler_ci.pNext = NULL;
12570 sampler_ci.magFilter = VK_FILTER_NEAREST;
12571 sampler_ci.minFilter = VK_FILTER_NEAREST;
12572 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12573 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12574 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12575 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12576 sampler_ci.mipLodBias = 1.0;
12577 sampler_ci.anisotropyEnable = VK_FALSE;
12578 sampler_ci.maxAnisotropy = 1;
12579 sampler_ci.compareEnable = VK_FALSE;
12580 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12581 sampler_ci.minLod = 1.0;
12582 sampler_ci.maxLod = 1.0;
12583 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12584 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12585 VkSampler sampler;
12586
12587 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12588 ASSERT_VK_SUCCESS(err);
12589
12590 VkDescriptorSetLayoutBinding layout_binding;
12591 layout_binding.binding = 0;
12592 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12593 layout_binding.descriptorCount = 1;
12594 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12595 layout_binding.pImmutableSamplers = NULL;
12596
12597 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12598 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12599 ds_layout_ci.bindingCount = 1;
12600 ds_layout_ci.pBindings = &layout_binding;
12601 VkDescriptorSetLayout ds_layout;
12602 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12603 ASSERT_VK_SUCCESS(err);
12604
12605 VkDescriptorSetAllocateInfo alloc_info = {};
12606 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12607 alloc_info.descriptorSetCount = 1;
12608 alloc_info.descriptorPool = ds_pool;
12609 alloc_info.pSetLayouts = &ds_layout;
12610 VkDescriptorSet descriptor_set;
12611 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12612 ASSERT_VK_SUCCESS(err);
12613
12614 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12615 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12616 pipeline_layout_ci.pNext = NULL;
12617 pipeline_layout_ci.setLayoutCount = 1;
12618 pipeline_layout_ci.pSetLayouts = &ds_layout;
12619
12620 VkPipelineLayout pipeline_layout;
12621 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12622 ASSERT_VK_SUCCESS(err);
12623
12624 VkImageObj image(m_device);
12625 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12626 ASSERT_TRUE(image.initialized());
12627
12628 VkImageView view;
12629 VkImageViewCreateInfo ivci = {};
12630 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12631 ivci.image = image.handle();
12632 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12633 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12634 ivci.subresourceRange.layerCount = 1;
12635 ivci.subresourceRange.baseMipLevel = 0;
12636 ivci.subresourceRange.levelCount = 1;
12637 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12638
12639 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12640 ASSERT_VK_SUCCESS(err);
12641
12642 VkDescriptorImageInfo image_info{};
12643 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12644 image_info.imageView = view;
12645 image_info.sampler = sampler;
12646
12647 VkWriteDescriptorSet descriptor_write = {};
12648 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12649 descriptor_write.dstSet = descriptor_set;
12650 descriptor_write.dstBinding = 0;
12651 descriptor_write.descriptorCount = 1;
12652 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12653 descriptor_write.pImageInfo = &image_info;
12654
12655 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12656
12657 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012658 char const *vsSource =
12659 "#version 450\n"
12660 "\n"
12661 "out gl_PerVertex { \n"
12662 " vec4 gl_Position;\n"
12663 "};\n"
12664 "void main(){\n"
12665 " gl_Position = vec4(1);\n"
12666 "}\n";
12667 char const *fsSource =
12668 "#version 450\n"
12669 "\n"
12670 "layout(set=0, binding=0) uniform sampler2D s;\n"
12671 "layout(location=0) out vec4 x;\n"
12672 "void main(){\n"
12673 " x = texture(s, vec2(1));\n"
12674 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012675 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12676 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12677 VkPipelineObj pipe(m_device);
12678 pipe.AddShader(&vs);
12679 pipe.AddShader(&fs);
12680 pipe.AddColorAttachment();
12681 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12682
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012683 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012684
Tony Barbour552f6c02016-12-21 14:34:07 -070012685 m_commandBuffer->BeginCommandBuffer();
12686 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012687 // Bind pipeline to cmd buffer
12688 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12689 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12690 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012691
12692 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12693 VkRect2D scissor = {{0, 0}, {16, 16}};
12694 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12695 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12696
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012697 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012698 m_commandBuffer->EndRenderPass();
12699 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012700 // Submit cmd buffer then destroy sampler
12701 VkSubmitInfo submit_info = {};
12702 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12703 submit_info.commandBufferCount = 1;
12704 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12705 // Submit cmd buffer and then destroy imageView while in-flight
12706 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12707
12708 vkDestroyImageView(m_device->device(), view, nullptr);
12709 m_errorMonitor->VerifyFound();
12710 vkQueueWaitIdle(m_device->m_queue);
12711 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012712 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12713 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012714 vkDestroyImageView(m_device->device(), view, NULL);
12715 vkDestroySampler(m_device->device(), sampler, nullptr);
12716 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12717 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12718 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12719}
12720
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012721TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12722 TEST_DESCRIPTION("Delete in-use bufferView.");
12723
12724 ASSERT_NO_FATAL_FAILURE(InitState());
12725 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12726
12727 VkDescriptorPoolSize ds_type_count;
12728 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12729 ds_type_count.descriptorCount = 1;
12730
12731 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12732 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12733 ds_pool_ci.maxSets = 1;
12734 ds_pool_ci.poolSizeCount = 1;
12735 ds_pool_ci.pPoolSizes = &ds_type_count;
12736
12737 VkDescriptorPool ds_pool;
12738 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12739 ASSERT_VK_SUCCESS(err);
12740
12741 VkDescriptorSetLayoutBinding layout_binding;
12742 layout_binding.binding = 0;
12743 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12744 layout_binding.descriptorCount = 1;
12745 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12746 layout_binding.pImmutableSamplers = NULL;
12747
12748 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12749 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12750 ds_layout_ci.bindingCount = 1;
12751 ds_layout_ci.pBindings = &layout_binding;
12752 VkDescriptorSetLayout ds_layout;
12753 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12754 ASSERT_VK_SUCCESS(err);
12755
12756 VkDescriptorSetAllocateInfo alloc_info = {};
12757 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12758 alloc_info.descriptorSetCount = 1;
12759 alloc_info.descriptorPool = ds_pool;
12760 alloc_info.pSetLayouts = &ds_layout;
12761 VkDescriptorSet descriptor_set;
12762 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12763 ASSERT_VK_SUCCESS(err);
12764
12765 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12766 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12767 pipeline_layout_ci.pNext = NULL;
12768 pipeline_layout_ci.setLayoutCount = 1;
12769 pipeline_layout_ci.pSetLayouts = &ds_layout;
12770
12771 VkPipelineLayout pipeline_layout;
12772 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12773 ASSERT_VK_SUCCESS(err);
12774
12775 VkBuffer buffer;
12776 uint32_t queue_family_index = 0;
12777 VkBufferCreateInfo buffer_create_info = {};
12778 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12779 buffer_create_info.size = 1024;
12780 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12781 buffer_create_info.queueFamilyIndexCount = 1;
12782 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12783
12784 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12785 ASSERT_VK_SUCCESS(err);
12786
12787 VkMemoryRequirements memory_reqs;
12788 VkDeviceMemory buffer_memory;
12789
12790 VkMemoryAllocateInfo memory_info = {};
12791 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12792 memory_info.allocationSize = 0;
12793 memory_info.memoryTypeIndex = 0;
12794
12795 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12796 memory_info.allocationSize = memory_reqs.size;
12797 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12798 ASSERT_TRUE(pass);
12799
12800 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12801 ASSERT_VK_SUCCESS(err);
12802 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12803 ASSERT_VK_SUCCESS(err);
12804
12805 VkBufferView view;
12806 VkBufferViewCreateInfo bvci = {};
12807 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12808 bvci.buffer = buffer;
12809 bvci.format = VK_FORMAT_R8_UNORM;
12810 bvci.range = VK_WHOLE_SIZE;
12811
12812 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12813 ASSERT_VK_SUCCESS(err);
12814
12815 VkWriteDescriptorSet descriptor_write = {};
12816 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12817 descriptor_write.dstSet = descriptor_set;
12818 descriptor_write.dstBinding = 0;
12819 descriptor_write.descriptorCount = 1;
12820 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12821 descriptor_write.pTexelBufferView = &view;
12822
12823 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12824
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012825 char const *vsSource =
12826 "#version 450\n"
12827 "\n"
12828 "out gl_PerVertex { \n"
12829 " vec4 gl_Position;\n"
12830 "};\n"
12831 "void main(){\n"
12832 " gl_Position = vec4(1);\n"
12833 "}\n";
12834 char const *fsSource =
12835 "#version 450\n"
12836 "\n"
12837 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12838 "layout(location=0) out vec4 x;\n"
12839 "void main(){\n"
12840 " x = imageLoad(s, 0);\n"
12841 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12844 VkPipelineObj pipe(m_device);
12845 pipe.AddShader(&vs);
12846 pipe.AddShader(&fs);
12847 pipe.AddColorAttachment();
12848 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12849
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012850 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012851
Tony Barbour552f6c02016-12-21 14:34:07 -070012852 m_commandBuffer->BeginCommandBuffer();
12853 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012854 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12855 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12856 VkRect2D scissor = {{0, 0}, {16, 16}};
12857 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12858 // Bind pipeline to cmd buffer
12859 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12860 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12861 &descriptor_set, 0, nullptr);
12862 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012863 m_commandBuffer->EndRenderPass();
12864 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012865
12866 VkSubmitInfo submit_info = {};
12867 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12868 submit_info.commandBufferCount = 1;
12869 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12870 // Submit cmd buffer and then destroy bufferView while in-flight
12871 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12872
12873 vkDestroyBufferView(m_device->device(), view, nullptr);
12874 m_errorMonitor->VerifyFound();
12875 vkQueueWaitIdle(m_device->m_queue);
12876 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012877 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12878 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012879 vkDestroyBufferView(m_device->device(), view, NULL);
12880 vkDestroyBuffer(m_device->device(), buffer, NULL);
12881 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12882 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12883 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12884 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12885}
12886
Tobin Ehlis209532e2016-09-07 13:52:18 -060012887TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12888 TEST_DESCRIPTION("Delete in-use sampler.");
12889
12890 ASSERT_NO_FATAL_FAILURE(InitState());
12891 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12892
12893 VkDescriptorPoolSize ds_type_count;
12894 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12895 ds_type_count.descriptorCount = 1;
12896
12897 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12898 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12899 ds_pool_ci.maxSets = 1;
12900 ds_pool_ci.poolSizeCount = 1;
12901 ds_pool_ci.pPoolSizes = &ds_type_count;
12902
12903 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012904 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012905 ASSERT_VK_SUCCESS(err);
12906
12907 VkSamplerCreateInfo sampler_ci = {};
12908 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12909 sampler_ci.pNext = NULL;
12910 sampler_ci.magFilter = VK_FILTER_NEAREST;
12911 sampler_ci.minFilter = VK_FILTER_NEAREST;
12912 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12913 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12914 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12915 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12916 sampler_ci.mipLodBias = 1.0;
12917 sampler_ci.anisotropyEnable = VK_FALSE;
12918 sampler_ci.maxAnisotropy = 1;
12919 sampler_ci.compareEnable = VK_FALSE;
12920 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12921 sampler_ci.minLod = 1.0;
12922 sampler_ci.maxLod = 1.0;
12923 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12924 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12925 VkSampler sampler;
12926
12927 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12928 ASSERT_VK_SUCCESS(err);
12929
12930 VkDescriptorSetLayoutBinding layout_binding;
12931 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012932 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012933 layout_binding.descriptorCount = 1;
12934 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12935 layout_binding.pImmutableSamplers = NULL;
12936
12937 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12938 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12939 ds_layout_ci.bindingCount = 1;
12940 ds_layout_ci.pBindings = &layout_binding;
12941 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012942 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012943 ASSERT_VK_SUCCESS(err);
12944
12945 VkDescriptorSetAllocateInfo alloc_info = {};
12946 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12947 alloc_info.descriptorSetCount = 1;
12948 alloc_info.descriptorPool = ds_pool;
12949 alloc_info.pSetLayouts = &ds_layout;
12950 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012951 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012952 ASSERT_VK_SUCCESS(err);
12953
12954 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12955 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12956 pipeline_layout_ci.pNext = NULL;
12957 pipeline_layout_ci.setLayoutCount = 1;
12958 pipeline_layout_ci.pSetLayouts = &ds_layout;
12959
12960 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012961 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012962 ASSERT_VK_SUCCESS(err);
12963
12964 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012965 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 -060012966 ASSERT_TRUE(image.initialized());
12967
12968 VkImageView view;
12969 VkImageViewCreateInfo ivci = {};
12970 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12971 ivci.image = image.handle();
12972 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12973 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12974 ivci.subresourceRange.layerCount = 1;
12975 ivci.subresourceRange.baseMipLevel = 0;
12976 ivci.subresourceRange.levelCount = 1;
12977 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12978
12979 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12980 ASSERT_VK_SUCCESS(err);
12981
12982 VkDescriptorImageInfo image_info{};
12983 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12984 image_info.imageView = view;
12985 image_info.sampler = sampler;
12986
12987 VkWriteDescriptorSet descriptor_write = {};
12988 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12989 descriptor_write.dstSet = descriptor_set;
12990 descriptor_write.dstBinding = 0;
12991 descriptor_write.descriptorCount = 1;
12992 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12993 descriptor_write.pImageInfo = &image_info;
12994
12995 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12996
12997 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012998 char const *vsSource =
12999 "#version 450\n"
13000 "\n"
13001 "out gl_PerVertex { \n"
13002 " vec4 gl_Position;\n"
13003 "};\n"
13004 "void main(){\n"
13005 " gl_Position = vec4(1);\n"
13006 "}\n";
13007 char const *fsSource =
13008 "#version 450\n"
13009 "\n"
13010 "layout(set=0, binding=0) uniform sampler2D s;\n"
13011 "layout(location=0) out vec4 x;\n"
13012 "void main(){\n"
13013 " x = texture(s, vec2(1));\n"
13014 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060013015 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13016 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13017 VkPipelineObj pipe(m_device);
13018 pipe.AddShader(&vs);
13019 pipe.AddShader(&fs);
13020 pipe.AddColorAttachment();
13021 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13022
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070013023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013024
Tony Barbour552f6c02016-12-21 14:34:07 -070013025 m_commandBuffer->BeginCommandBuffer();
13026 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060013027 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013028 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
13029 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
13030 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070013031
13032 VkViewport viewport = {0, 0, 16, 16, 0, 1};
13033 VkRect2D scissor = {{0, 0}, {16, 16}};
13034 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
13035 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
13036
Tobin Ehlis209532e2016-09-07 13:52:18 -060013037 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070013038 m_commandBuffer->EndRenderPass();
13039 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060013040 // Submit cmd buffer then destroy sampler
13041 VkSubmitInfo submit_info = {};
13042 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13043 submit_info.commandBufferCount = 1;
13044 submit_info.pCommandBuffers = &m_commandBuffer->handle();
13045 // Submit cmd buffer and then destroy sampler while in-flight
13046 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13047
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013048 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060013049 m_errorMonitor->VerifyFound();
13050 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070013051
Tobin Ehlis209532e2016-09-07 13:52:18 -060013052 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070013053 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
13054 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013055 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060013056 vkDestroyImageView(m_device->device(), view, NULL);
13057 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13058 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
13059 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
13060}
13061
Mark Mueller1cd9f412016-08-25 13:23:52 -060013062TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013063 TEST_DESCRIPTION(
13064 "Call VkQueueSubmit with a semaphore that is already "
13065 "signaled but not waited on by the queue. Wait on a "
13066 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060013067
13068 ASSERT_NO_FATAL_FAILURE(InitState());
13069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13070
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013071 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 -070013072 const char *invalid_fence_wait_message =
13073 " which has not been submitted on a Queue or during "
13074 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060013075
Tony Barbour552f6c02016-12-21 14:34:07 -070013076 m_commandBuffer->BeginCommandBuffer();
13077 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060013078
13079 VkSemaphoreCreateInfo semaphore_create_info = {};
13080 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
13081 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013082 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060013083 VkSubmitInfo submit_info = {};
13084 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
13085 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013086 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060013087 submit_info.signalSemaphoreCount = 1;
13088 submit_info.pSignalSemaphores = &semaphore;
13089 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070013090 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060013091 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070013092 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070013093 m_commandBuffer->BeginCommandBuffer();
13094 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013096 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13097 m_errorMonitor->VerifyFound();
13098
Mark Mueller1cd9f412016-08-25 13:23:52 -060013099 VkFenceCreateInfo fence_create_info = {};
13100 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13101 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013102 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013103
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013104 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013105 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13106 m_errorMonitor->VerifyFound();
13107
Mark Mueller4042b652016-09-05 22:52:21 -060013108 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013109 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013110 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13111}
13112
Tobin Ehlis4af23302016-07-19 10:50:30 -060013113TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013114 TEST_DESCRIPTION(
13115 "Bind a secondary command buffer with with a framebuffer "
13116 "that does not match the framebuffer for the active "
13117 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013118 ASSERT_NO_FATAL_FAILURE(InitState());
13119 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13120
13121 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013122 VkAttachmentDescription attachment = {0,
13123 VK_FORMAT_B8G8R8A8_UNORM,
13124 VK_SAMPLE_COUNT_1_BIT,
13125 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13126 VK_ATTACHMENT_STORE_OP_STORE,
13127 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13128 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13129 VK_IMAGE_LAYOUT_UNDEFINED,
13130 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013131
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013132 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013133
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013134 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013135
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013136 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013137
13138 VkRenderPass rp;
13139 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13140 ASSERT_VK_SUCCESS(err);
13141
13142 // A compatible framebuffer.
13143 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013144 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 -060013145 ASSERT_TRUE(image.initialized());
13146
13147 VkImageViewCreateInfo ivci = {
13148 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13149 nullptr,
13150 0,
13151 image.handle(),
13152 VK_IMAGE_VIEW_TYPE_2D,
13153 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013154 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13155 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013156 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13157 };
13158 VkImageView view;
13159 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13160 ASSERT_VK_SUCCESS(err);
13161
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013162 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013163 VkFramebuffer fb;
13164 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13165 ASSERT_VK_SUCCESS(err);
13166
13167 VkCommandBufferAllocateInfo cbai = {};
13168 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13169 cbai.commandPool = m_commandPool;
13170 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13171 cbai.commandBufferCount = 1;
13172
13173 VkCommandBuffer sec_cb;
13174 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13175 ASSERT_VK_SUCCESS(err);
13176 VkCommandBufferBeginInfo cbbi = {};
13177 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013178 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013179 cbii.renderPass = renderPass();
13180 cbii.framebuffer = fb;
13181 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13182 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013183 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 -060013184 cbbi.pInheritanceInfo = &cbii;
13185 vkBeginCommandBuffer(sec_cb, &cbbi);
13186 vkEndCommandBuffer(sec_cb);
13187
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013188 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013189 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13190 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013193 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013194 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13195 m_errorMonitor->VerifyFound();
13196 // Cleanup
13197 vkDestroyImageView(m_device->device(), view, NULL);
13198 vkDestroyRenderPass(m_device->device(), rp, NULL);
13199 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13200}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013201
13202TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013203 TEST_DESCRIPTION(
13204 "If logicOp is available on the device, set it to an "
13205 "invalid value. If logicOp is not available, attempt to "
13206 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013207 ASSERT_NO_FATAL_FAILURE(InitState());
13208 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13209
13210 auto features = m_device->phy().features();
13211 // Set the expected error depending on whether or not logicOp available
13212 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013213 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13214 "If logic operations feature not "
13215 "enabled, logicOpEnable must be "
13216 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013217 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013218 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013219 }
13220 // Create a pipeline using logicOp
13221 VkResult err;
13222
13223 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13224 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13225
13226 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013227 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013228 ASSERT_VK_SUCCESS(err);
13229
13230 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13231 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13232 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013233 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013234 vp_state_ci.pViewports = &vp;
13235 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013236 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013237 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013238
13239 VkPipelineShaderStageCreateInfo shaderStages[2];
13240 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13241
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013242 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13243 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013244 shaderStages[0] = vs.GetStageCreateInfo();
13245 shaderStages[1] = fs.GetStageCreateInfo();
13246
13247 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13248 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13249
13250 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13251 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13252 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13253
13254 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13255 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013256 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013257
13258 VkPipelineColorBlendAttachmentState att = {};
13259 att.blendEnable = VK_FALSE;
13260 att.colorWriteMask = 0xf;
13261
13262 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13263 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13264 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13265 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013266 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013267 cb_ci.attachmentCount = 1;
13268 cb_ci.pAttachments = &att;
13269
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013270 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13271 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13272 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13273
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013274 VkGraphicsPipelineCreateInfo gp_ci = {};
13275 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13276 gp_ci.stageCount = 2;
13277 gp_ci.pStages = shaderStages;
13278 gp_ci.pVertexInputState = &vi_ci;
13279 gp_ci.pInputAssemblyState = &ia_ci;
13280 gp_ci.pViewportState = &vp_state_ci;
13281 gp_ci.pRasterizationState = &rs_ci;
13282 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013283 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013284 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13285 gp_ci.layout = pipeline_layout;
13286 gp_ci.renderPass = renderPass();
13287
13288 VkPipelineCacheCreateInfo pc_ci = {};
13289 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13290
13291 VkPipeline pipeline;
13292 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013293 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013294 ASSERT_VK_SUCCESS(err);
13295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013296 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013297 m_errorMonitor->VerifyFound();
13298 if (VK_SUCCESS == err) {
13299 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13300 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013301 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13302 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13303}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013304
Mike Stroyanaccf7692015-05-12 16:00:45 -060013305#if GTEST_IS_THREADSAFE
13306struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013307 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013308 VkEvent event;
13309 bool bailout;
13310};
13311
Karl Schultz6addd812016-02-02 17:17:23 -070013312extern "C" void *AddToCommandBuffer(void *arg) {
13313 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013314
Mike Stroyana6d14942016-07-13 15:10:05 -060013315 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013316 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013317 if (data->bailout) {
13318 break;
13319 }
13320 }
13321 return NULL;
13322}
13323
Karl Schultz6addd812016-02-02 17:17:23 -070013324TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013325 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013326
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013327 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013328
Mike Stroyanaccf7692015-05-12 16:00:45 -060013329 ASSERT_NO_FATAL_FAILURE(InitState());
13330 ASSERT_NO_FATAL_FAILURE(InitViewport());
13331 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13332
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013333 // Calls AllocateCommandBuffers
13334 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013335
13336 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013337 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013338
13339 VkEventCreateInfo event_info;
13340 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013341 VkResult err;
13342
13343 memset(&event_info, 0, sizeof(event_info));
13344 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13345
Chia-I Wuf7458c52015-10-26 21:10:41 +080013346 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013347 ASSERT_VK_SUCCESS(err);
13348
Mike Stroyanaccf7692015-05-12 16:00:45 -060013349 err = vkResetEvent(device(), event);
13350 ASSERT_VK_SUCCESS(err);
13351
13352 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013353 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013354 data.event = event;
13355 data.bailout = false;
13356 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013357
13358 // First do some correct operations using multiple threads.
13359 // Add many entries to command buffer from another thread.
13360 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13361 // Make non-conflicting calls from this thread at the same time.
13362 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013363 uint32_t count;
13364 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013365 }
13366 test_platform_thread_join(thread, NULL);
13367
13368 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013369 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013370 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013371 // Add many entries to command buffer from this thread at the same time.
13372 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013373
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013374 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013375 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013376
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013377 m_errorMonitor->SetBailout(NULL);
13378
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013379 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013380
Chia-I Wuf7458c52015-10-26 21:10:41 +080013381 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013382}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013383#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013384
Karl Schultz6addd812016-02-02 17:17:23 -070013385TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013386 TEST_DESCRIPTION(
13387 "Test that an error is produced for a spirv module "
13388 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013391
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013392 ASSERT_NO_FATAL_FAILURE(InitState());
13393 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13394
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013395 VkShaderModule module;
13396 VkShaderModuleCreateInfo moduleCreateInfo;
13397 struct icd_spv_header spv;
13398
13399 spv.magic = ICD_SPV_MAGIC;
13400 spv.version = ICD_SPV_VERSION;
13401 spv.gen_magic = 0;
13402
13403 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13404 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013405 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013406 moduleCreateInfo.codeSize = 4;
13407 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013408 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013409
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013410 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013411}
13412
Karl Schultz6addd812016-02-02 17:17:23 -070013413TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013414 TEST_DESCRIPTION(
13415 "Test that an error is produced for a spirv module "
13416 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013417
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013418 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013419
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013420 ASSERT_NO_FATAL_FAILURE(InitState());
13421 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13422
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013423 VkShaderModule module;
13424 VkShaderModuleCreateInfo moduleCreateInfo;
13425 struct icd_spv_header spv;
13426
13427 spv.magic = ~ICD_SPV_MAGIC;
13428 spv.version = ICD_SPV_VERSION;
13429 spv.gen_magic = 0;
13430
13431 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13432 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013433 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013434 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13435 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013436 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013437
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013438 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013439}
13440
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013441#if 0
13442// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013443TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013445 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013446
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013447 ASSERT_NO_FATAL_FAILURE(InitState());
13448 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13449
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013450 VkShaderModule module;
13451 VkShaderModuleCreateInfo moduleCreateInfo;
13452 struct icd_spv_header spv;
13453
13454 spv.magic = ICD_SPV_MAGIC;
13455 spv.version = ~ICD_SPV_VERSION;
13456 spv.gen_magic = 0;
13457
13458 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13459 moduleCreateInfo.pNext = NULL;
13460
Karl Schultz6addd812016-02-02 17:17:23 -070013461 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013462 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13463 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013464 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013465
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013466 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013467}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013468#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013469
Karl Schultz6addd812016-02-02 17:17:23 -070013470TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013471 TEST_DESCRIPTION(
13472 "Test that a warning is produced for a vertex output that "
13473 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013475
Chris Forbes9f7ff632015-05-25 11:13:08 +120013476 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013477 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013478
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013479 char const *vsSource =
13480 "#version 450\n"
13481 "\n"
13482 "layout(location=0) out float x;\n"
13483 "out gl_PerVertex {\n"
13484 " vec4 gl_Position;\n"
13485 "};\n"
13486 "void main(){\n"
13487 " gl_Position = vec4(1);\n"
13488 " x = 0;\n"
13489 "}\n";
13490 char const *fsSource =
13491 "#version 450\n"
13492 "\n"
13493 "layout(location=0) out vec4 color;\n"
13494 "void main(){\n"
13495 " color = vec4(1);\n"
13496 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013497
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013498 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13499 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013500
13501 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013502 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013503 pipe.AddShader(&vs);
13504 pipe.AddShader(&fs);
13505
Chris Forbes9f7ff632015-05-25 11:13:08 +120013506 VkDescriptorSetObj descriptorSet(m_device);
13507 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013508 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013509
Tony Barbour5781e8f2015-08-04 16:23:11 -060013510 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013511
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013512 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013513}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013514
Mark Mueller098c9cb2016-09-08 09:01:57 -060013515TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
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 *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013522 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013523
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013524 char const *vsSource =
13525 "#version 450\n"
13526 "\n"
13527 "out gl_PerVertex {\n"
13528 " vec4 gl_Position;\n"
13529 "};\n"
13530 "void main(){\n"
13531 " gl_Position = vec4(1);\n"
13532 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013533
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013534 char const *fsSource =
13535 "#version 450\n"
13536 "\n"
13537 "layout (constant_id = 0) const float r = 0.0f;\n"
13538 "layout(location = 0) out vec4 uFragColor;\n"
13539 "void main(){\n"
13540 " uFragColor = vec4(r,1,0,1);\n"
13541 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013542
13543 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13544 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13545
13546 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13547 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13548
13549 VkPipelineLayout pipeline_layout;
13550 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13551
13552 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13553 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13554 vp_state_create_info.viewportCount = 1;
13555 VkViewport viewport = {};
13556 vp_state_create_info.pViewports = &viewport;
13557 vp_state_create_info.scissorCount = 1;
13558 VkRect2D scissors = {};
13559 vp_state_create_info.pScissors = &scissors;
13560
13561 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13562
13563 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13564 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13565 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13566 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13567
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013568 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013569
13570 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13571 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13572
13573 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13574 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13575 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13576
13577 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13578 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13579 rasterization_state_create_info.pNext = nullptr;
13580 rasterization_state_create_info.lineWidth = 1.0f;
13581 rasterization_state_create_info.rasterizerDiscardEnable = true;
13582
13583 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13584 color_blend_attachment_state.blendEnable = VK_FALSE;
13585 color_blend_attachment_state.colorWriteMask = 0xf;
13586
13587 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13588 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13589 color_blend_state_create_info.attachmentCount = 1;
13590 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13591
13592 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13593 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13594 graphicspipe_create_info.stageCount = 2;
13595 graphicspipe_create_info.pStages = shader_stage_create_info;
13596 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13597 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13598 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13599 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13600 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13601 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13602 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13603 graphicspipe_create_info.layout = pipeline_layout;
13604 graphicspipe_create_info.renderPass = renderPass();
13605
13606 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13607 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13608
13609 VkPipelineCache pipelineCache;
13610 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13611
13612 // This structure maps constant ids to data locations.
13613 const VkSpecializationMapEntry entry =
13614 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013615 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013616
13617 uint32_t data = 1;
13618
13619 // Set up the info describing spec map and data
13620 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013621 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013622 };
13623 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13624
13625 VkPipeline pipeline;
13626 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13627 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13628 m_errorMonitor->VerifyFound();
13629
13630 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13631 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13632}
13633
13634TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13635 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13636
13637 ASSERT_NO_FATAL_FAILURE(InitState());
13638 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13639
13640 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13641
13642 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13643 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13644 descriptor_pool_type_count[0].descriptorCount = 1;
13645 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13646 descriptor_pool_type_count[1].descriptorCount = 1;
13647
13648 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13649 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13650 descriptor_pool_create_info.maxSets = 1;
13651 descriptor_pool_create_info.poolSizeCount = 2;
13652 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13653 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13654
13655 VkDescriptorPool descriptorset_pool;
13656 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13657
13658 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13659 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13660 descriptorset_layout_binding.descriptorCount = 1;
13661 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070013662 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013663
13664 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13665 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13666 descriptorset_layout_create_info.bindingCount = 1;
13667 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13668
13669 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013670 ASSERT_VK_SUCCESS(
13671 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013672
13673 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13674 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13675 descriptorset_allocate_info.descriptorSetCount = 1;
13676 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13677 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13678 VkDescriptorSet descriptorset;
13679 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13680
13681 // Challenge core_validation with a non uniform buffer type.
13682 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13683
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013684 char const *vsSource =
13685 "#version 450\n"
13686 "\n"
13687 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13688 " mat4 mvp;\n"
13689 "} ubuf;\n"
13690 "out gl_PerVertex {\n"
13691 " vec4 gl_Position;\n"
13692 "};\n"
13693 "void main(){\n"
13694 " gl_Position = ubuf.mvp * vec4(1);\n"
13695 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013696
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013697 char const *fsSource =
13698 "#version 450\n"
13699 "\n"
13700 "layout(location = 0) out vec4 uFragColor;\n"
13701 "void main(){\n"
13702 " uFragColor = vec4(0,1,0,1);\n"
13703 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013704
13705 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13707
13708 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13709 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13710 pipeline_layout_create_info.setLayoutCount = 1;
13711 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13712
13713 VkPipelineLayout pipeline_layout;
13714 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13715
13716 VkPipelineObj pipe(m_device);
13717 pipe.AddColorAttachment();
13718 pipe.AddShader(&vs);
13719 pipe.AddShader(&fs);
13720
13721 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13722 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13723 m_errorMonitor->VerifyFound();
13724
13725 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13726 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13727 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13728}
13729
13730TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13731 TEST_DESCRIPTION(
13732 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13733
13734 ASSERT_NO_FATAL_FAILURE(InitState());
13735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13736
13737 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13738
13739 VkDescriptorPoolSize descriptor_pool_type_count = {};
13740 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13741 descriptor_pool_type_count.descriptorCount = 1;
13742
13743 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13744 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13745 descriptor_pool_create_info.maxSets = 1;
13746 descriptor_pool_create_info.poolSizeCount = 1;
13747 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13748 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13749
13750 VkDescriptorPool descriptorset_pool;
13751 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13752
13753 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13754 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13755 descriptorset_layout_binding.descriptorCount = 1;
13756 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13757 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
Cody Northropa6484fd2017-03-10 14:13:49 -070013758 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013759
13760 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13761 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13762 descriptorset_layout_create_info.bindingCount = 1;
13763 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13764
13765 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013766 ASSERT_VK_SUCCESS(
13767 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013768
13769 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13770 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13771 descriptorset_allocate_info.descriptorSetCount = 1;
13772 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13773 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13774 VkDescriptorSet descriptorset;
13775 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13776
13777 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13778
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013779 char const *vsSource =
13780 "#version 450\n"
13781 "\n"
13782 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13783 " mat4 mvp;\n"
13784 "} ubuf;\n"
13785 "out gl_PerVertex {\n"
13786 " vec4 gl_Position;\n"
13787 "};\n"
13788 "void main(){\n"
13789 " gl_Position = ubuf.mvp * vec4(1);\n"
13790 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013791
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013792 char const *fsSource =
13793 "#version 450\n"
13794 "\n"
13795 "layout(location = 0) out vec4 uFragColor;\n"
13796 "void main(){\n"
13797 " uFragColor = vec4(0,1,0,1);\n"
13798 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013799
13800 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13801 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13802
13803 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13804 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13805 pipeline_layout_create_info.setLayoutCount = 1;
13806 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13807
13808 VkPipelineLayout pipeline_layout;
13809 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13810
13811 VkPipelineObj pipe(m_device);
13812 pipe.AddColorAttachment();
13813 pipe.AddShader(&vs);
13814 pipe.AddShader(&fs);
13815
13816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13817 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13818 m_errorMonitor->VerifyFound();
13819
13820 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13821 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13822 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13823}
13824
13825TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013826 TEST_DESCRIPTION(
13827 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13828 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013829
13830 ASSERT_NO_FATAL_FAILURE(InitState());
13831 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13832
13833 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013834 "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 -060013835
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013836 char const *vsSource =
13837 "#version 450\n"
13838 "\n"
13839 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13840 "out gl_PerVertex {\n"
13841 " vec4 gl_Position;\n"
13842 "};\n"
13843 "void main(){\n"
13844 " gl_Position = vec4(consts.x);\n"
13845 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013846
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013847 char const *fsSource =
13848 "#version 450\n"
13849 "\n"
13850 "layout(location = 0) out vec4 uFragColor;\n"
13851 "void main(){\n"
13852 " uFragColor = vec4(0,1,0,1);\n"
13853 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013854
13855 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13856 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13857
13858 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13859 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13860
13861 // Set up a push constant range
13862 VkPushConstantRange push_constant_ranges = {};
13863 // Set to the wrong stage to challenge core_validation
13864 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13865 push_constant_ranges.size = 4;
13866
13867 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13868 pipeline_layout_create_info.pushConstantRangeCount = 1;
13869
13870 VkPipelineLayout pipeline_layout;
13871 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13872
13873 VkPipelineObj pipe(m_device);
13874 pipe.AddColorAttachment();
13875 pipe.AddShader(&vs);
13876 pipe.AddShader(&fs);
13877
13878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13879 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13880 m_errorMonitor->VerifyFound();
13881
13882 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13883}
13884
13885TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13886 TEST_DESCRIPTION(
13887 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13888
13889 ASSERT_NO_FATAL_FAILURE(InitState());
13890 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13891
13892 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013893 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013894
13895 // Some awkward steps are required to test with custom device features.
13896 std::vector<const char *> device_extension_names;
13897 auto features = m_device->phy().features();
13898 // Disable support for 64 bit floats
13899 features.shaderFloat64 = false;
13900 // The sacrificial device object
13901 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13902
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013903 char const *vsSource =
13904 "#version 450\n"
13905 "\n"
13906 "out gl_PerVertex {\n"
13907 " vec4 gl_Position;\n"
13908 "};\n"
13909 "void main(){\n"
13910 " gl_Position = vec4(1);\n"
13911 "}\n";
13912 char const *fsSource =
13913 "#version 450\n"
13914 "\n"
13915 "layout(location=0) out vec4 color;\n"
13916 "void main(){\n"
13917 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13918 " color = vec4(green);\n"
13919 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013920
13921 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13922 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13923
13924 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013925
13926 VkPipelineObj pipe(&test_device);
13927 pipe.AddColorAttachment();
13928 pipe.AddShader(&vs);
13929 pipe.AddShader(&fs);
13930
13931 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13932 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13933 VkPipelineLayout pipeline_layout;
13934 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13935
13936 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13937 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13938 m_errorMonitor->VerifyFound();
13939
13940 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13941}
13942
13943TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13944 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13945
13946 ASSERT_NO_FATAL_FAILURE(InitState());
13947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13948
13949 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13950
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013951 char const *vsSource =
13952 "#version 450\n"
13953 "\n"
13954 "out gl_PerVertex {\n"
13955 " vec4 gl_Position;\n"
13956 "};\n"
13957 "layout(xfb_buffer = 1) out;"
13958 "void main(){\n"
13959 " gl_Position = vec4(1);\n"
13960 "}\n";
13961 char const *fsSource =
13962 "#version 450\n"
13963 "\n"
13964 "layout(location=0) out vec4 color;\n"
13965 "void main(){\n"
13966 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13967 " color = vec4(green);\n"
13968 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013969
13970 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13971 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13972
13973 VkPipelineObj pipe(m_device);
13974 pipe.AddColorAttachment();
13975 pipe.AddShader(&vs);
13976 pipe.AddShader(&fs);
13977
13978 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13979 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13980 VkPipelineLayout pipeline_layout;
13981 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13982
13983 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13984 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13985 m_errorMonitor->VerifyFound();
13986
13987 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13988}
13989
Karl Schultz6addd812016-02-02 17:17:23 -070013990TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013991 TEST_DESCRIPTION(
13992 "Test that an error is produced for a fragment shader input "
13993 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013994
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013995 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013996
Chris Forbes59cb88d2015-05-25 11:13:13 +120013997 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013998 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013999
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014000 char const *vsSource =
14001 "#version 450\n"
14002 "\n"
14003 "out gl_PerVertex {\n"
14004 " vec4 gl_Position;\n"
14005 "};\n"
14006 "void main(){\n"
14007 " gl_Position = vec4(1);\n"
14008 "}\n";
14009 char const *fsSource =
14010 "#version 450\n"
14011 "\n"
14012 "layout(location=0) in float x;\n"
14013 "layout(location=0) out vec4 color;\n"
14014 "void main(){\n"
14015 " color = vec4(x);\n"
14016 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120014017
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014018 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14019 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014020
14021 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014022 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014023 pipe.AddShader(&vs);
14024 pipe.AddShader(&fs);
14025
Chris Forbes59cb88d2015-05-25 11:13:13 +120014026 VkDescriptorSetObj descriptorSet(m_device);
14027 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014028 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120014029
Tony Barbour5781e8f2015-08-04 16:23:11 -060014030 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120014031
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014032 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120014033}
14034
Karl Schultz6addd812016-02-02 17:17:23 -070014035TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014036 TEST_DESCRIPTION(
14037 "Test that an error is produced for a fragment shader input "
14038 "within an interace block, which is not present in the outputs "
14039 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014040 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014041
14042 ASSERT_NO_FATAL_FAILURE(InitState());
14043 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14044
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014045 char const *vsSource =
14046 "#version 450\n"
14047 "\n"
14048 "out gl_PerVertex {\n"
14049 " vec4 gl_Position;\n"
14050 "};\n"
14051 "void main(){\n"
14052 " gl_Position = vec4(1);\n"
14053 "}\n";
14054 char const *fsSource =
14055 "#version 450\n"
14056 "\n"
14057 "in block { layout(location=0) float x; } ins;\n"
14058 "layout(location=0) out vec4 color;\n"
14059 "void main(){\n"
14060 " color = vec4(ins.x);\n"
14061 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014062
14063 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14064 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14065
14066 VkPipelineObj pipe(m_device);
14067 pipe.AddColorAttachment();
14068 pipe.AddShader(&vs);
14069 pipe.AddShader(&fs);
14070
14071 VkDescriptorSetObj descriptorSet(m_device);
14072 descriptorSet.AppendDummy();
14073 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14074
14075 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14076
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014077 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014078}
14079
Karl Schultz6addd812016-02-02 17:17:23 -070014080TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014081 TEST_DESCRIPTION(
14082 "Test that an error is produced for mismatched array sizes "
14083 "across the vertex->fragment shader interface");
14084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14085 "Type mismatch on location 0.0: 'ptr to "
14086 "output arr[2] of float32' vs 'ptr to "
14087 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130014088
14089 ASSERT_NO_FATAL_FAILURE(InitState());
14090 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14091
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014092 char const *vsSource =
14093 "#version 450\n"
14094 "\n"
14095 "layout(location=0) out float x[2];\n"
14096 "out gl_PerVertex {\n"
14097 " vec4 gl_Position;\n"
14098 "};\n"
14099 "void main(){\n"
14100 " x[0] = 0; x[1] = 0;\n"
14101 " gl_Position = vec4(1);\n"
14102 "}\n";
14103 char const *fsSource =
14104 "#version 450\n"
14105 "\n"
14106 "layout(location=0) in float x[1];\n"
14107 "layout(location=0) out vec4 color;\n"
14108 "void main(){\n"
14109 " color = vec4(x[0]);\n"
14110 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014111
14112 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14113 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14114
14115 VkPipelineObj pipe(m_device);
14116 pipe.AddColorAttachment();
14117 pipe.AddShader(&vs);
14118 pipe.AddShader(&fs);
14119
14120 VkDescriptorSetObj descriptorSet(m_device);
14121 descriptorSet.AppendDummy();
14122 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14123
14124 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14125
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014126 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014127}
14128
Karl Schultz6addd812016-02-02 17:17:23 -070014129TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014130 TEST_DESCRIPTION(
14131 "Test that an error is produced for mismatched types across "
14132 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014133 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014134
Chris Forbesb56af562015-05-25 11:13:17 +120014135 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014136 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014137
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014138 char const *vsSource =
14139 "#version 450\n"
14140 "\n"
14141 "layout(location=0) out int x;\n"
14142 "out gl_PerVertex {\n"
14143 " vec4 gl_Position;\n"
14144 "};\n"
14145 "void main(){\n"
14146 " x = 0;\n"
14147 " gl_Position = vec4(1);\n"
14148 "}\n";
14149 char const *fsSource =
14150 "#version 450\n"
14151 "\n"
14152 "layout(location=0) in float x;\n" /* VS writes int */
14153 "layout(location=0) out vec4 color;\n"
14154 "void main(){\n"
14155 " color = vec4(x);\n"
14156 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014157
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014158 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14159 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014160
14161 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014162 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014163 pipe.AddShader(&vs);
14164 pipe.AddShader(&fs);
14165
Chris Forbesb56af562015-05-25 11:13:17 +120014166 VkDescriptorSetObj descriptorSet(m_device);
14167 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014168 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014169
Tony Barbour5781e8f2015-08-04 16:23:11 -060014170 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014171
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014172 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014173}
14174
Karl Schultz6addd812016-02-02 17:17:23 -070014175TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014176 TEST_DESCRIPTION(
14177 "Test that an error is produced for mismatched types across "
14178 "the vertex->fragment shader interface, when the variable is contained within "
14179 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014181
14182 ASSERT_NO_FATAL_FAILURE(InitState());
14183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14184
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014185 char const *vsSource =
14186 "#version 450\n"
14187 "\n"
14188 "out block { layout(location=0) int x; } outs;\n"
14189 "out gl_PerVertex {\n"
14190 " vec4 gl_Position;\n"
14191 "};\n"
14192 "void main(){\n"
14193 " outs.x = 0;\n"
14194 " gl_Position = vec4(1);\n"
14195 "}\n";
14196 char const *fsSource =
14197 "#version 450\n"
14198 "\n"
14199 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14200 "layout(location=0) out vec4 color;\n"
14201 "void main(){\n"
14202 " color = vec4(ins.x);\n"
14203 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014204
14205 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14206 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14207
14208 VkPipelineObj pipe(m_device);
14209 pipe.AddColorAttachment();
14210 pipe.AddShader(&vs);
14211 pipe.AddShader(&fs);
14212
14213 VkDescriptorSetObj descriptorSet(m_device);
14214 descriptorSet.AppendDummy();
14215 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14216
14217 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14218
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014219 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014220}
14221
14222TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014223 TEST_DESCRIPTION(
14224 "Test that an error is produced for location mismatches across "
14225 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14226 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014227 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 +130014228
14229 ASSERT_NO_FATAL_FAILURE(InitState());
14230 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14231
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014232 char const *vsSource =
14233 "#version 450\n"
14234 "\n"
14235 "out block { layout(location=1) float x; } outs;\n"
14236 "out gl_PerVertex {\n"
14237 " vec4 gl_Position;\n"
14238 "};\n"
14239 "void main(){\n"
14240 " outs.x = 0;\n"
14241 " gl_Position = vec4(1);\n"
14242 "}\n";
14243 char const *fsSource =
14244 "#version 450\n"
14245 "\n"
14246 "in block { layout(location=0) float x; } ins;\n"
14247 "layout(location=0) out vec4 color;\n"
14248 "void main(){\n"
14249 " color = vec4(ins.x);\n"
14250 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014251
14252 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14253 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14254
14255 VkPipelineObj pipe(m_device);
14256 pipe.AddColorAttachment();
14257 pipe.AddShader(&vs);
14258 pipe.AddShader(&fs);
14259
14260 VkDescriptorSetObj descriptorSet(m_device);
14261 descriptorSet.AppendDummy();
14262 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14263
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014264 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014265 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14266
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014267 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014268}
14269
14270TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014271 TEST_DESCRIPTION(
14272 "Test that an error is produced for component mismatches across the "
14273 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14274 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014275 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 +130014276
14277 ASSERT_NO_FATAL_FAILURE(InitState());
14278 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14279
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014280 char const *vsSource =
14281 "#version 450\n"
14282 "\n"
14283 "out block { layout(location=0, component=0) float x; } outs;\n"
14284 "out gl_PerVertex {\n"
14285 " vec4 gl_Position;\n"
14286 "};\n"
14287 "void main(){\n"
14288 " outs.x = 0;\n"
14289 " gl_Position = vec4(1);\n"
14290 "}\n";
14291 char const *fsSource =
14292 "#version 450\n"
14293 "\n"
14294 "in block { layout(location=0, component=1) float x; } ins;\n"
14295 "layout(location=0) out vec4 color;\n"
14296 "void main(){\n"
14297 " color = vec4(ins.x);\n"
14298 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014299
14300 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14301 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14302
14303 VkPipelineObj pipe(m_device);
14304 pipe.AddColorAttachment();
14305 pipe.AddShader(&vs);
14306 pipe.AddShader(&fs);
14307
14308 VkDescriptorSetObj descriptorSet(m_device);
14309 descriptorSet.AppendDummy();
14310 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14311
14312 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014314 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014315}
14316
Chris Forbes1f3b0152016-11-30 12:48:40 +130014317TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14318 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14319
14320 ASSERT_NO_FATAL_FAILURE(InitState());
14321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14322
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014323 char const *vsSource =
14324 "#version 450\n"
14325 "layout(location=0) out mediump float x;\n"
14326 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14327 char const *fsSource =
14328 "#version 450\n"
14329 "layout(location=0) in highp float x;\n"
14330 "layout(location=0) out vec4 color;\n"
14331 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014332
14333 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14334 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14335
14336 VkPipelineObj pipe(m_device);
14337 pipe.AddColorAttachment();
14338 pipe.AddShader(&vs);
14339 pipe.AddShader(&fs);
14340
14341 VkDescriptorSetObj descriptorSet(m_device);
14342 descriptorSet.AppendDummy();
14343 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14344
14345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14346
14347 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14348
14349 m_errorMonitor->VerifyFound();
14350}
14351
Chris Forbes870a39e2016-11-30 12:55:56 +130014352TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14353 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14354
14355 ASSERT_NO_FATAL_FAILURE(InitState());
14356 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14357
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014358 char const *vsSource =
14359 "#version 450\n"
14360 "out block { layout(location=0) mediump float x; };\n"
14361 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14362 char const *fsSource =
14363 "#version 450\n"
14364 "in block { layout(location=0) highp float x; };\n"
14365 "layout(location=0) out vec4 color;\n"
14366 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014367
14368 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14369 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14370
14371 VkPipelineObj pipe(m_device);
14372 pipe.AddColorAttachment();
14373 pipe.AddShader(&vs);
14374 pipe.AddShader(&fs);
14375
14376 VkDescriptorSetObj descriptorSet(m_device);
14377 descriptorSet.AppendDummy();
14378 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14379
14380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14381
14382 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14383
14384 m_errorMonitor->VerifyFound();
14385}
14386
Karl Schultz6addd812016-02-02 17:17:23 -070014387TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014388 TEST_DESCRIPTION(
14389 "Test that a warning is produced for a vertex attribute which is "
14390 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014391 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014392
Chris Forbesde136e02015-05-25 11:13:28 +120014393 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014394 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014395
14396 VkVertexInputBindingDescription input_binding;
14397 memset(&input_binding, 0, sizeof(input_binding));
14398
14399 VkVertexInputAttributeDescription input_attrib;
14400 memset(&input_attrib, 0, sizeof(input_attrib));
14401 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14402
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014403 char const *vsSource =
14404 "#version 450\n"
14405 "\n"
14406 "out gl_PerVertex {\n"
14407 " vec4 gl_Position;\n"
14408 "};\n"
14409 "void main(){\n"
14410 " gl_Position = vec4(1);\n"
14411 "}\n";
14412 char const *fsSource =
14413 "#version 450\n"
14414 "\n"
14415 "layout(location=0) out vec4 color;\n"
14416 "void main(){\n"
14417 " color = vec4(1);\n"
14418 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014419
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014420 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14421 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014422
14423 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014424 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014425 pipe.AddShader(&vs);
14426 pipe.AddShader(&fs);
14427
14428 pipe.AddVertexInputBindings(&input_binding, 1);
14429 pipe.AddVertexInputAttribs(&input_attrib, 1);
14430
Chris Forbesde136e02015-05-25 11:13:28 +120014431 VkDescriptorSetObj descriptorSet(m_device);
14432 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014433 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014434
Tony Barbour5781e8f2015-08-04 16:23:11 -060014435 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014436
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014437 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014438}
14439
Karl Schultz6addd812016-02-02 17:17:23 -070014440TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014441 TEST_DESCRIPTION(
14442 "Test that a warning is produced for a location mismatch on "
14443 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014445
14446 ASSERT_NO_FATAL_FAILURE(InitState());
14447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14448
14449 VkVertexInputBindingDescription input_binding;
14450 memset(&input_binding, 0, sizeof(input_binding));
14451
14452 VkVertexInputAttributeDescription input_attrib;
14453 memset(&input_attrib, 0, sizeof(input_attrib));
14454 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14455
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014456 char const *vsSource =
14457 "#version 450\n"
14458 "\n"
14459 "layout(location=1) in float x;\n"
14460 "out gl_PerVertex {\n"
14461 " vec4 gl_Position;\n"
14462 "};\n"
14463 "void main(){\n"
14464 " gl_Position = vec4(x);\n"
14465 "}\n";
14466 char const *fsSource =
14467 "#version 450\n"
14468 "\n"
14469 "layout(location=0) out vec4 color;\n"
14470 "void main(){\n"
14471 " color = vec4(1);\n"
14472 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014473
14474 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14475 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14476
14477 VkPipelineObj pipe(m_device);
14478 pipe.AddColorAttachment();
14479 pipe.AddShader(&vs);
14480 pipe.AddShader(&fs);
14481
14482 pipe.AddVertexInputBindings(&input_binding, 1);
14483 pipe.AddVertexInputAttribs(&input_attrib, 1);
14484
14485 VkDescriptorSetObj descriptorSet(m_device);
14486 descriptorSet.AppendDummy();
14487 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14488
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014489 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014490 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14491
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014492 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014493}
14494
Karl Schultz6addd812016-02-02 17:17:23 -070014495TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014496 TEST_DESCRIPTION(
14497 "Test that an error is produced for a vertex shader input which is not "
14498 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014499 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14500 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014501
Chris Forbes62e8e502015-05-25 11:13:29 +120014502 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014503 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014504
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014505 char const *vsSource =
14506 "#version 450\n"
14507 "\n"
14508 "layout(location=0) in vec4 x;\n" /* not provided */
14509 "out gl_PerVertex {\n"
14510 " vec4 gl_Position;\n"
14511 "};\n"
14512 "void main(){\n"
14513 " gl_Position = x;\n"
14514 "}\n";
14515 char const *fsSource =
14516 "#version 450\n"
14517 "\n"
14518 "layout(location=0) out vec4 color;\n"
14519 "void main(){\n"
14520 " color = vec4(1);\n"
14521 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014522
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014523 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14524 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014525
14526 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014527 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014528 pipe.AddShader(&vs);
14529 pipe.AddShader(&fs);
14530
Chris Forbes62e8e502015-05-25 11:13:29 +120014531 VkDescriptorSetObj descriptorSet(m_device);
14532 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014533 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014534
Tony Barbour5781e8f2015-08-04 16:23:11 -060014535 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014536
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014537 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014538}
14539
Karl Schultz6addd812016-02-02 17:17:23 -070014540TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014541 TEST_DESCRIPTION(
14542 "Test that an error is produced for a mismatch between the "
14543 "fundamental type (float/int/uint) of an attribute and the "
14544 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014545 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 -060014546
Chris Forbesc97d98e2015-05-25 11:13:31 +120014547 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014549
14550 VkVertexInputBindingDescription input_binding;
14551 memset(&input_binding, 0, sizeof(input_binding));
14552
14553 VkVertexInputAttributeDescription input_attrib;
14554 memset(&input_attrib, 0, sizeof(input_attrib));
14555 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14556
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014557 char const *vsSource =
14558 "#version 450\n"
14559 "\n"
14560 "layout(location=0) in int x;\n" /* attrib provided float */
14561 "out gl_PerVertex {\n"
14562 " vec4 gl_Position;\n"
14563 "};\n"
14564 "void main(){\n"
14565 " gl_Position = vec4(x);\n"
14566 "}\n";
14567 char const *fsSource =
14568 "#version 450\n"
14569 "\n"
14570 "layout(location=0) out vec4 color;\n"
14571 "void main(){\n"
14572 " color = vec4(1);\n"
14573 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014574
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014575 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14576 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014577
14578 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014579 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014580 pipe.AddShader(&vs);
14581 pipe.AddShader(&fs);
14582
14583 pipe.AddVertexInputBindings(&input_binding, 1);
14584 pipe.AddVertexInputAttribs(&input_attrib, 1);
14585
Chris Forbesc97d98e2015-05-25 11:13:31 +120014586 VkDescriptorSetObj descriptorSet(m_device);
14587 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014588 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014589
Tony Barbour5781e8f2015-08-04 16:23:11 -060014590 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014591
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014592 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014593}
14594
Chris Forbesc68b43c2016-04-06 11:18:47 +120014595TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014596 TEST_DESCRIPTION(
14597 "Test that an error is produced for a pipeline containing multiple "
14598 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014599 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14600 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014601
14602 ASSERT_NO_FATAL_FAILURE(InitState());
14603 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14604
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014605 char const *vsSource =
14606 "#version 450\n"
14607 "\n"
14608 "out gl_PerVertex {\n"
14609 " vec4 gl_Position;\n"
14610 "};\n"
14611 "void main(){\n"
14612 " gl_Position = vec4(1);\n"
14613 "}\n";
14614 char const *fsSource =
14615 "#version 450\n"
14616 "\n"
14617 "layout(location=0) out vec4 color;\n"
14618 "void main(){\n"
14619 " color = vec4(1);\n"
14620 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014621
14622 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14623 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14624
14625 VkPipelineObj pipe(m_device);
14626 pipe.AddColorAttachment();
14627 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014628 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014629 pipe.AddShader(&fs);
14630
14631 VkDescriptorSetObj descriptorSet(m_device);
14632 descriptorSet.AppendDummy();
14633 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14634
14635 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014637 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014638}
14639
Chris Forbes82ff92a2016-09-09 10:50:24 +120014640TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014642
14643 ASSERT_NO_FATAL_FAILURE(InitState());
14644 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14645
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014646 char const *vsSource =
14647 "#version 450\n"
14648 "out gl_PerVertex {\n"
14649 " vec4 gl_Position;\n"
14650 "};\n"
14651 "void main(){\n"
14652 " gl_Position = vec4(0);\n"
14653 "}\n";
14654 char const *fsSource =
14655 "#version 450\n"
14656 "\n"
14657 "layout(location=0) out vec4 color;\n"
14658 "void main(){\n"
14659 " color = vec4(1);\n"
14660 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014661
14662 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14663 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14664
14665 VkPipelineObj pipe(m_device);
14666 pipe.AddColorAttachment();
14667 pipe.AddShader(&vs);
14668 pipe.AddShader(&fs);
14669
14670 VkDescriptorSetObj descriptorSet(m_device);
14671 descriptorSet.AppendDummy();
14672 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14673
14674 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14675
14676 m_errorMonitor->VerifyFound();
14677}
14678
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014679TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014680 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14681 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14682 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014683
14684 ASSERT_NO_FATAL_FAILURE(InitState());
14685 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14686
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014687 char const *vsSource =
14688 "#version 450\n"
14689 "void main(){ gl_Position = vec4(0); }\n";
14690 char const *fsSource =
14691 "#version 450\n"
14692 "\n"
14693 "layout(location=0) out vec4 color;\n"
14694 "void main(){\n"
14695 " color = vec4(1);\n"
14696 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014697
14698 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14699 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14700
14701 VkPipelineObj pipe(m_device);
14702 pipe.AddColorAttachment();
14703 pipe.AddShader(&vs);
14704 pipe.AddShader(&fs);
14705
14706 VkDescriptorSetObj descriptorSet(m_device);
14707 descriptorSet.AppendDummy();
14708 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14709
14710 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014711 {
14712 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14713 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14714 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014715 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014716 {
14717 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14718 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14719 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014720 },
14721 };
14722 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014723 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014724 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014725 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14726 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014727 VkRenderPass rp;
14728 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14729 ASSERT_VK_SUCCESS(err);
14730
14731 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14732
14733 m_errorMonitor->VerifyFound();
14734
14735 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14736}
14737
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014738TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014739 TEST_DESCRIPTION(
14740 "Test that an error is produced for a variable output from "
14741 "the TCS without the patch decoration, but consumed in the TES "
14742 "with the decoration.");
14743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14744 "is per-vertex in tessellation control shader stage "
14745 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014746
14747 ASSERT_NO_FATAL_FAILURE(InitState());
14748 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14749
Chris Forbesc1e852d2016-04-04 19:26:42 +120014750 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014751 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014752 return;
14753 }
14754
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014755 char const *vsSource =
14756 "#version 450\n"
14757 "void main(){}\n";
14758 char const *tcsSource =
14759 "#version 450\n"
14760 "layout(location=0) out int x[];\n"
14761 "layout(vertices=3) out;\n"
14762 "void main(){\n"
14763 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14764 " gl_TessLevelInner[0] = 1;\n"
14765 " x[gl_InvocationID] = gl_InvocationID;\n"
14766 "}\n";
14767 char const *tesSource =
14768 "#version 450\n"
14769 "layout(triangles, equal_spacing, cw) in;\n"
14770 "layout(location=0) patch in int x;\n"
14771 "out gl_PerVertex { vec4 gl_Position; };\n"
14772 "void main(){\n"
14773 " gl_Position.xyz = gl_TessCoord;\n"
14774 " gl_Position.w = x;\n"
14775 "}\n";
14776 char const *fsSource =
14777 "#version 450\n"
14778 "layout(location=0) out vec4 color;\n"
14779 "void main(){\n"
14780 " color = vec4(1);\n"
14781 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014782
14783 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14784 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14785 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14786 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14787
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014788 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14789 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014790
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014791 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014792
14793 VkPipelineObj pipe(m_device);
14794 pipe.SetInputAssembly(&iasci);
14795 pipe.SetTessellation(&tsci);
14796 pipe.AddColorAttachment();
14797 pipe.AddShader(&vs);
14798 pipe.AddShader(&tcs);
14799 pipe.AddShader(&tes);
14800 pipe.AddShader(&fs);
14801
14802 VkDescriptorSetObj descriptorSet(m_device);
14803 descriptorSet.AppendDummy();
14804 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14805
14806 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14807
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014808 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014809}
14810
Karl Schultz6addd812016-02-02 17:17:23 -070014811TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014812 TEST_DESCRIPTION(
14813 "Test that an error is produced for a vertex attribute setup where multiple "
14814 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014815 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14816 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014817
Chris Forbes280ba2c2015-06-12 11:16:41 +120014818 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014819 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014820
14821 /* Two binding descriptions for binding 0 */
14822 VkVertexInputBindingDescription input_bindings[2];
14823 memset(input_bindings, 0, sizeof(input_bindings));
14824
14825 VkVertexInputAttributeDescription input_attrib;
14826 memset(&input_attrib, 0, sizeof(input_attrib));
14827 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14828
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014829 char const *vsSource =
14830 "#version 450\n"
14831 "\n"
14832 "layout(location=0) in float x;\n" /* attrib provided float */
14833 "out gl_PerVertex {\n"
14834 " vec4 gl_Position;\n"
14835 "};\n"
14836 "void main(){\n"
14837 " gl_Position = vec4(x);\n"
14838 "}\n";
14839 char const *fsSource =
14840 "#version 450\n"
14841 "\n"
14842 "layout(location=0) out vec4 color;\n"
14843 "void main(){\n"
14844 " color = vec4(1);\n"
14845 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014846
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014847 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14848 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014849
14850 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014851 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014852 pipe.AddShader(&vs);
14853 pipe.AddShader(&fs);
14854
14855 pipe.AddVertexInputBindings(input_bindings, 2);
14856 pipe.AddVertexInputAttribs(&input_attrib, 1);
14857
Chris Forbes280ba2c2015-06-12 11:16:41 +120014858 VkDescriptorSetObj descriptorSet(m_device);
14859 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014860 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014861
Tony Barbour5781e8f2015-08-04 16:23:11 -060014862 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014863
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014864 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014865}
Chris Forbes8f68b562015-05-25 11:13:32 +120014866
Karl Schultz6addd812016-02-02 17:17:23 -070014867TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014868 TEST_DESCRIPTION(
14869 "Test that an error is produced for a fragment shader which does not "
14870 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014871 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014872
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014873 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014874
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014875 char const *vsSource =
14876 "#version 450\n"
14877 "\n"
14878 "out gl_PerVertex {\n"
14879 " vec4 gl_Position;\n"
14880 "};\n"
14881 "void main(){\n"
14882 " gl_Position = vec4(1);\n"
14883 "}\n";
14884 char const *fsSource =
14885 "#version 450\n"
14886 "\n"
14887 "void main(){\n"
14888 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014889
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014890 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14891 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014892
14893 VkPipelineObj pipe(m_device);
14894 pipe.AddShader(&vs);
14895 pipe.AddShader(&fs);
14896
Chia-I Wu08accc62015-07-07 11:50:03 +080014897 /* set up CB 0, not written */
14898 pipe.AddColorAttachment();
14899 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014900
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014901 VkDescriptorSetObj descriptorSet(m_device);
14902 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014903 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014904
Tony Barbour5781e8f2015-08-04 16:23:11 -060014905 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014906
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014907 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014908}
14909
Karl Schultz6addd812016-02-02 17:17:23 -070014910TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014911 TEST_DESCRIPTION(
14912 "Test that a warning is produced for a fragment shader which provides a spurious "
14913 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014914 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014915 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014916
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014917 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014918
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014919 char const *vsSource =
14920 "#version 450\n"
14921 "\n"
14922 "out gl_PerVertex {\n"
14923 " vec4 gl_Position;\n"
14924 "};\n"
14925 "void main(){\n"
14926 " gl_Position = vec4(1);\n"
14927 "}\n";
14928 char const *fsSource =
14929 "#version 450\n"
14930 "\n"
14931 "layout(location=0) out vec4 x;\n"
14932 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14933 "void main(){\n"
14934 " x = vec4(1);\n"
14935 " y = vec4(1);\n"
14936 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014937
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014938 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14939 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014940
14941 VkPipelineObj pipe(m_device);
14942 pipe.AddShader(&vs);
14943 pipe.AddShader(&fs);
14944
Chia-I Wu08accc62015-07-07 11:50:03 +080014945 /* set up CB 0, not written */
14946 pipe.AddColorAttachment();
14947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014948 /* FS writes CB 1, but we don't configure it */
14949
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014950 VkDescriptorSetObj descriptorSet(m_device);
14951 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014952 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014953
Tony Barbour5781e8f2015-08-04 16:23:11 -060014954 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014955
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014956 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014957}
14958
Karl Schultz6addd812016-02-02 17:17:23 -070014959TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014960 TEST_DESCRIPTION(
14961 "Test that an error is produced for a mismatch between the fundamental "
14962 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014964
Chris Forbesa36d69e2015-05-25 11:13:44 +120014965 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014966
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014967 char const *vsSource =
14968 "#version 450\n"
14969 "\n"
14970 "out gl_PerVertex {\n"
14971 " vec4 gl_Position;\n"
14972 "};\n"
14973 "void main(){\n"
14974 " gl_Position = vec4(1);\n"
14975 "}\n";
14976 char const *fsSource =
14977 "#version 450\n"
14978 "\n"
14979 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14980 "void main(){\n"
14981 " x = ivec4(1);\n"
14982 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014983
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014984 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14985 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014986
14987 VkPipelineObj pipe(m_device);
14988 pipe.AddShader(&vs);
14989 pipe.AddShader(&fs);
14990
Chia-I Wu08accc62015-07-07 11:50:03 +080014991 /* set up CB 0; type is UNORM by default */
14992 pipe.AddColorAttachment();
14993 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014994
Chris Forbesa36d69e2015-05-25 11:13:44 +120014995 VkDescriptorSetObj descriptorSet(m_device);
14996 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014997 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014998
Tony Barbour5781e8f2015-08-04 16:23:11 -060014999 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120015000
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015001 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120015002}
Chris Forbes7b1b8932015-06-05 14:43:36 +120015003
Karl Schultz6addd812016-02-02 17:17:23 -070015004TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015005 TEST_DESCRIPTION(
15006 "Test that an error is produced for a shader consuming a uniform "
15007 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015009
Chris Forbes556c76c2015-08-14 12:04:59 +120015010 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120015011
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015012 char const *vsSource =
15013 "#version 450\n"
15014 "\n"
15015 "out gl_PerVertex {\n"
15016 " vec4 gl_Position;\n"
15017 "};\n"
15018 "void main(){\n"
15019 " gl_Position = vec4(1);\n"
15020 "}\n";
15021 char const *fsSource =
15022 "#version 450\n"
15023 "\n"
15024 "layout(location=0) out vec4 x;\n"
15025 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
15026 "void main(){\n"
15027 " x = vec4(bar.y);\n"
15028 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120015029
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060015030 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15031 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120015032
Chris Forbes556c76c2015-08-14 12:04:59 +120015033 VkPipelineObj pipe(m_device);
15034 pipe.AddShader(&vs);
15035 pipe.AddShader(&fs);
15036
15037 /* set up CB 0; type is UNORM by default */
15038 pipe.AddColorAttachment();
15039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15040
15041 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015042 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120015043
15044 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15045
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015046 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120015047}
15048
Chris Forbes5c59e902016-02-26 16:56:09 +130015049TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015050 TEST_DESCRIPTION(
15051 "Test that an error is produced for a shader consuming push constants "
15052 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130015054
15055 ASSERT_NO_FATAL_FAILURE(InitState());
15056
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015057 char const *vsSource =
15058 "#version 450\n"
15059 "\n"
15060 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
15061 "out gl_PerVertex {\n"
15062 " vec4 gl_Position;\n"
15063 "};\n"
15064 "void main(){\n"
15065 " gl_Position = vec4(consts.x);\n"
15066 "}\n";
15067 char const *fsSource =
15068 "#version 450\n"
15069 "\n"
15070 "layout(location=0) out vec4 x;\n"
15071 "void main(){\n"
15072 " x = vec4(1);\n"
15073 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130015074
15075 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15076 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15077
15078 VkPipelineObj pipe(m_device);
15079 pipe.AddShader(&vs);
15080 pipe.AddShader(&fs);
15081
15082 /* set up CB 0; type is UNORM by default */
15083 pipe.AddColorAttachment();
15084 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15085
15086 VkDescriptorSetObj descriptorSet(m_device);
15087 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15088
15089 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15090
15091 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015092 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130015093}
15094
Chris Forbes3fb17902016-08-22 14:57:55 +120015095TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015096 TEST_DESCRIPTION(
15097 "Test that an error is produced for a shader consuming an input attachment "
15098 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15100 "consumes input attachment index 0 but not provided in subpass");
15101
15102 ASSERT_NO_FATAL_FAILURE(InitState());
15103
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015104 char const *vsSource =
15105 "#version 450\n"
15106 "\n"
15107 "out gl_PerVertex {\n"
15108 " vec4 gl_Position;\n"
15109 "};\n"
15110 "void main(){\n"
15111 " gl_Position = vec4(1);\n"
15112 "}\n";
15113 char const *fsSource =
15114 "#version 450\n"
15115 "\n"
15116 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15117 "layout(location=0) out vec4 color;\n"
15118 "void main() {\n"
15119 " color = subpassLoad(x);\n"
15120 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015121
15122 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15123 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15124
15125 VkPipelineObj pipe(m_device);
15126 pipe.AddShader(&vs);
15127 pipe.AddShader(&fs);
15128 pipe.AddColorAttachment();
15129 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15130
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015131 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15132 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015133 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015134 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015135 ASSERT_VK_SUCCESS(err);
15136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015137 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015138 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015139 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015140 ASSERT_VK_SUCCESS(err);
15141
15142 // error here.
15143 pipe.CreateVKPipeline(pl, renderPass());
15144
15145 m_errorMonitor->VerifyFound();
15146
15147 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15148 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15149}
15150
Chris Forbes5a9a0472016-08-22 16:02:09 +120015151TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015152 TEST_DESCRIPTION(
15153 "Test that an error is produced for a shader consuming an input attachment "
15154 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015155 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15156 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15157
15158 ASSERT_NO_FATAL_FAILURE(InitState());
15159
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015160 char const *vsSource =
15161 "#version 450\n"
15162 "\n"
15163 "out gl_PerVertex {\n"
15164 " vec4 gl_Position;\n"
15165 "};\n"
15166 "void main(){\n"
15167 " gl_Position = vec4(1);\n"
15168 "}\n";
15169 char const *fsSource =
15170 "#version 450\n"
15171 "\n"
15172 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15173 "layout(location=0) out vec4 color;\n"
15174 "void main() {\n"
15175 " color = subpassLoad(x);\n"
15176 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015177
15178 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15179 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15180
15181 VkPipelineObj pipe(m_device);
15182 pipe.AddShader(&vs);
15183 pipe.AddShader(&fs);
15184 pipe.AddColorAttachment();
15185 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15186
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015187 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15188 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015189 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015190 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015191 ASSERT_VK_SUCCESS(err);
15192
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015193 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015194 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015195 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015196 ASSERT_VK_SUCCESS(err);
15197
15198 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015199 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15200 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15201 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15202 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15203 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 +120015204 };
15205 VkAttachmentReference color = {
15206 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15207 };
15208 VkAttachmentReference input = {
15209 1, VK_IMAGE_LAYOUT_GENERAL,
15210 };
15211
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015212 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015213
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015214 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015215 VkRenderPass rp;
15216 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15217 ASSERT_VK_SUCCESS(err);
15218
15219 // error here.
15220 pipe.CreateVKPipeline(pl, rp);
15221
15222 m_errorMonitor->VerifyFound();
15223
15224 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15225 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15226 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15227}
15228
Chris Forbes541f7b02016-08-22 15:30:27 +120015229TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015230 TEST_DESCRIPTION(
15231 "Test that an error is produced for a shader consuming an input attachment "
15232 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015234 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015235
15236 ASSERT_NO_FATAL_FAILURE(InitState());
15237
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015238 char const *vsSource =
15239 "#version 450\n"
15240 "\n"
15241 "out gl_PerVertex {\n"
15242 " vec4 gl_Position;\n"
15243 "};\n"
15244 "void main(){\n"
15245 " gl_Position = vec4(1);\n"
15246 "}\n";
15247 char const *fsSource =
15248 "#version 450\n"
15249 "\n"
15250 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15251 "layout(location=0) out vec4 color;\n"
15252 "void main() {\n"
15253 " color = subpassLoad(xs[0]);\n"
15254 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015255
15256 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15257 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15258
15259 VkPipelineObj pipe(m_device);
15260 pipe.AddShader(&vs);
15261 pipe.AddShader(&fs);
15262 pipe.AddColorAttachment();
15263 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15264
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015265 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15266 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015267 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015268 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015269 ASSERT_VK_SUCCESS(err);
15270
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015271 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015272 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015273 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015274 ASSERT_VK_SUCCESS(err);
15275
15276 // error here.
15277 pipe.CreateVKPipeline(pl, renderPass());
15278
15279 m_errorMonitor->VerifyFound();
15280
15281 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15282 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15283}
15284
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015285TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015286 TEST_DESCRIPTION(
15287 "Test that an error is produced for a compute pipeline consuming a "
15288 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015289 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015290
15291 ASSERT_NO_FATAL_FAILURE(InitState());
15292
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015293 char const *csSource =
15294 "#version 450\n"
15295 "\n"
15296 "layout(local_size_x=1) in;\n"
15297 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15298 "void main(){\n"
15299 " x = vec4(1);\n"
15300 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015301
15302 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15303
15304 VkDescriptorSetObj descriptorSet(m_device);
15305 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15306
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015307 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15308 nullptr,
15309 0,
15310 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15311 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15312 descriptorSet.GetPipelineLayout(),
15313 VK_NULL_HANDLE,
15314 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015315
15316 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015317 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015318
15319 m_errorMonitor->VerifyFound();
15320
15321 if (err == VK_SUCCESS) {
15322 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15323 }
15324}
15325
Chris Forbes22a9b092016-07-19 14:34:05 +120015326TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015327 TEST_DESCRIPTION(
15328 "Test that an error is produced for a pipeline consuming a "
15329 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015330 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15331 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015332
15333 ASSERT_NO_FATAL_FAILURE(InitState());
15334
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015335 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15336 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015337 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015338 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015339 ASSERT_VK_SUCCESS(err);
15340
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015341 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015342 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015343 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015344 ASSERT_VK_SUCCESS(err);
15345
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015346 char const *csSource =
15347 "#version 450\n"
15348 "\n"
15349 "layout(local_size_x=1) in;\n"
15350 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15351 "void main() {\n"
15352 " x.x = 1.0f;\n"
15353 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015354 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15355
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015356 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15357 nullptr,
15358 0,
15359 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15360 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15361 pl,
15362 VK_NULL_HANDLE,
15363 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015364
15365 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015366 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015367
15368 m_errorMonitor->VerifyFound();
15369
15370 if (err == VK_SUCCESS) {
15371 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15372 }
15373
15374 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15375 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15376}
15377
Chris Forbes50020592016-07-27 13:52:41 +120015378TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015379 TEST_DESCRIPTION(
15380 "Test that an error is produced when an image view type "
15381 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015382
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015383 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 +120015384
15385 ASSERT_NO_FATAL_FAILURE(InitState());
15386 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15387
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015388 char const *vsSource =
15389 "#version 450\n"
15390 "\n"
15391 "out gl_PerVertex { vec4 gl_Position; };\n"
15392 "void main() { gl_Position = vec4(0); }\n";
15393 char const *fsSource =
15394 "#version 450\n"
15395 "\n"
15396 "layout(set=0, binding=0) uniform sampler3D s;\n"
15397 "layout(location=0) out vec4 color;\n"
15398 "void main() {\n"
15399 " color = texture(s, vec3(0));\n"
15400 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015401 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15402 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15403
15404 VkPipelineObj pipe(m_device);
15405 pipe.AddShader(&vs);
15406 pipe.AddShader(&fs);
15407 pipe.AddColorAttachment();
15408
15409 VkTextureObj texture(m_device, nullptr);
15410 VkSamplerObj sampler(m_device);
15411
15412 VkDescriptorSetObj descriptorSet(m_device);
15413 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15414 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15415
15416 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15417 ASSERT_VK_SUCCESS(err);
15418
Tony Barbour552f6c02016-12-21 14:34:07 -070015419 m_commandBuffer->BeginCommandBuffer();
15420 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015421
15422 m_commandBuffer->BindPipeline(pipe);
15423 m_commandBuffer->BindDescriptorSet(descriptorSet);
15424
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015425 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015426 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015427 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015428 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15429
15430 // error produced here.
15431 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15432
15433 m_errorMonitor->VerifyFound();
15434
Tony Barbour552f6c02016-12-21 14:34:07 -070015435 m_commandBuffer->EndRenderPass();
15436 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015437}
15438
Chris Forbes5533bfc2016-07-27 14:12:34 +120015439TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015440 TEST_DESCRIPTION(
15441 "Test that an error is produced when a multisampled images "
15442 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015443
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015444 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015445
15446 ASSERT_NO_FATAL_FAILURE(InitState());
15447 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15448
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015449 char const *vsSource =
15450 "#version 450\n"
15451 "\n"
15452 "out gl_PerVertex { vec4 gl_Position; };\n"
15453 "void main() { gl_Position = vec4(0); }\n";
15454 char const *fsSource =
15455 "#version 450\n"
15456 "\n"
15457 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15458 "layout(location=0) out vec4 color;\n"
15459 "void main() {\n"
15460 " color = texelFetch(s, ivec2(0), 0);\n"
15461 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015462 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15463 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15464
15465 VkPipelineObj pipe(m_device);
15466 pipe.AddShader(&vs);
15467 pipe.AddShader(&fs);
15468 pipe.AddColorAttachment();
15469
15470 VkTextureObj texture(m_device, nullptr);
15471 VkSamplerObj sampler(m_device);
15472
15473 VkDescriptorSetObj descriptorSet(m_device);
15474 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15475 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15476
15477 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15478 ASSERT_VK_SUCCESS(err);
15479
Tony Barbour552f6c02016-12-21 14:34:07 -070015480 m_commandBuffer->BeginCommandBuffer();
15481 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015482
15483 m_commandBuffer->BindPipeline(pipe);
15484 m_commandBuffer->BindDescriptorSet(descriptorSet);
15485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015486 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015487 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015488 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015489 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15490
15491 // error produced here.
15492 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15493
15494 m_errorMonitor->VerifyFound();
15495
Tony Barbour552f6c02016-12-21 14:34:07 -070015496 m_commandBuffer->EndRenderPass();
15497 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015498}
15499
Mark Youngc48c4c12016-04-11 14:26:49 -060015500TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015501 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015502
15503 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015504
15505 // Create an image
15506 VkImage image;
15507
Karl Schultz6addd812016-02-02 17:17:23 -070015508 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15509 const int32_t tex_width = 32;
15510 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015511
15512 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015513 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15514 image_create_info.pNext = NULL;
15515 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15516 image_create_info.format = tex_format;
15517 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015518 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015519 image_create_info.extent.depth = 1;
15520 image_create_info.mipLevels = 1;
15521 image_create_info.arrayLayers = 1;
15522 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15523 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15524 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15525 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015526
15527 // Introduce error by sending down a bogus width extent
15528 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015529 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015530
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015531 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015532}
15533
Mark Youngc48c4c12016-04-11 14:26:49 -060015534TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015535 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015536
15537 ASSERT_NO_FATAL_FAILURE(InitState());
15538
15539 // Create an image
15540 VkImage image;
15541
15542 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15543 const int32_t tex_width = 32;
15544 const int32_t tex_height = 32;
15545
15546 VkImageCreateInfo image_create_info = {};
15547 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15548 image_create_info.pNext = NULL;
15549 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15550 image_create_info.format = tex_format;
15551 image_create_info.extent.width = tex_width;
15552 image_create_info.extent.height = tex_height;
15553 image_create_info.extent.depth = 1;
15554 image_create_info.mipLevels = 1;
15555 image_create_info.arrayLayers = 1;
15556 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15557 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15558 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15559 image_create_info.flags = 0;
15560
15561 // Introduce error by sending down a bogus width extent
15562 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015563 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015564 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15565
15566 m_errorMonitor->VerifyFound();
15567}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015568
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015569TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015570 TEST_DESCRIPTION(
15571 "Create a render pass with an attachment description "
15572 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015573
15574 ASSERT_NO_FATAL_FAILURE(InitState());
15575 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15576
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015577 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015578
15579 VkAttachmentReference color_attach = {};
15580 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15581 color_attach.attachment = 0;
15582 VkSubpassDescription subpass = {};
15583 subpass.colorAttachmentCount = 1;
15584 subpass.pColorAttachments = &color_attach;
15585
15586 VkRenderPassCreateInfo rpci = {};
15587 rpci.subpassCount = 1;
15588 rpci.pSubpasses = &subpass;
15589 rpci.attachmentCount = 1;
15590 VkAttachmentDescription attach_desc = {};
15591 attach_desc.format = VK_FORMAT_UNDEFINED;
15592 rpci.pAttachments = &attach_desc;
15593 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15594 VkRenderPass rp;
15595 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15596
15597 m_errorMonitor->VerifyFound();
15598
15599 if (result == VK_SUCCESS) {
15600 vkDestroyRenderPass(m_device->device(), rp, NULL);
15601 }
15602}
15603
Karl Schultz6addd812016-02-02 17:17:23 -070015604TEST_F(VkLayerTest, InvalidImageView) {
15605 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015606
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015608
Tobin Ehliscde08892015-09-22 10:11:37 -060015609 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015610
Mike Stroyana3082432015-09-25 13:39:21 -060015611 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015612 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015613
Karl Schultz6addd812016-02-02 17:17:23 -070015614 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15615 const int32_t tex_width = 32;
15616 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015617
15618 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015619 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15620 image_create_info.pNext = NULL;
15621 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15622 image_create_info.format = tex_format;
15623 image_create_info.extent.width = tex_width;
15624 image_create_info.extent.height = tex_height;
15625 image_create_info.extent.depth = 1;
15626 image_create_info.mipLevels = 1;
15627 image_create_info.arrayLayers = 1;
15628 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15629 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15630 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15631 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015632
Chia-I Wuf7458c52015-10-26 21:10:41 +080015633 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015634 ASSERT_VK_SUCCESS(err);
15635
15636 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015637 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015638 image_view_create_info.image = image;
15639 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15640 image_view_create_info.format = tex_format;
15641 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015642 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015643 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015644 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015645
15646 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015647 m_errorMonitor->SetUnexpectedError(
15648 "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 -060015649 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015650
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015651 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015652 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015653}
Mike Stroyana3082432015-09-25 13:39:21 -060015654
Mark Youngd339ba32016-05-30 13:28:35 -060015655TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15656 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015657 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015658 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015659
15660 ASSERT_NO_FATAL_FAILURE(InitState());
15661
15662 // Create an image and try to create a view with no memory backing the image
15663 VkImage image;
15664
15665 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15666 const int32_t tex_width = 32;
15667 const int32_t tex_height = 32;
15668
15669 VkImageCreateInfo image_create_info = {};
15670 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15671 image_create_info.pNext = NULL;
15672 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15673 image_create_info.format = tex_format;
15674 image_create_info.extent.width = tex_width;
15675 image_create_info.extent.height = tex_height;
15676 image_create_info.extent.depth = 1;
15677 image_create_info.mipLevels = 1;
15678 image_create_info.arrayLayers = 1;
15679 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15680 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15681 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15682 image_create_info.flags = 0;
15683
15684 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15685 ASSERT_VK_SUCCESS(err);
15686
15687 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015688 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015689 image_view_create_info.image = image;
15690 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15691 image_view_create_info.format = tex_format;
15692 image_view_create_info.subresourceRange.layerCount = 1;
15693 image_view_create_info.subresourceRange.baseMipLevel = 0;
15694 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015695 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015696
15697 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015698 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015699
15700 m_errorMonitor->VerifyFound();
15701 vkDestroyImage(m_device->device(), image, NULL);
15702 // If last error is success, it still created the view, so delete it.
15703 if (err == VK_SUCCESS) {
15704 vkDestroyImageView(m_device->device(), view, NULL);
15705 }
Mark Youngd339ba32016-05-30 13:28:35 -060015706}
15707
Karl Schultz6addd812016-02-02 17:17:23 -070015708TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015709 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015710 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015711
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015712 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015713
Karl Schultz6addd812016-02-02 17:17:23 -070015714 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015715 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015716 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015717 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015718
15719 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015720 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015721 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015722 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15723 image_view_create_info.format = tex_format;
15724 image_view_create_info.subresourceRange.baseMipLevel = 0;
15725 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015726 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015727 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015728 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015729
15730 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015731 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015732
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015733 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015734}
15735
Mike Weiblena1e13f42017-02-09 21:25:59 -070015736TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15737 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15738
15739 ASSERT_NO_FATAL_FAILURE(InitState());
15740 VkSubresourceLayout subres_layout = {};
15741
15742 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15743 {
15744 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15745 VkImageObj img(m_device);
15746 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15747 ASSERT_TRUE(img.initialized());
15748
15749 VkImageSubresource subres = {};
15750 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15751 subres.mipLevel = 0;
15752 subres.arrayLayer = 0;
15753
15754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15755 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15756 m_errorMonitor->VerifyFound();
15757 }
15758
15759 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15760 {
15761 VkImageObj img(m_device);
15762 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15763 ASSERT_TRUE(img.initialized());
15764
15765 VkImageSubresource subres = {};
15766 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15767 subres.mipLevel = 0;
15768 subres.arrayLayer = 0;
15769
15770 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15771 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15772 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15773 m_errorMonitor->VerifyFound();
15774 }
15775
15776 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15777 {
15778 VkImageObj img(m_device);
15779 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15780 ASSERT_TRUE(img.initialized());
15781
15782 VkImageSubresource subres = {};
15783 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15784 subres.mipLevel = 1; // ERROR: triggers VU 00739
15785 subres.arrayLayer = 0;
15786
15787 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15788 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15789 m_errorMonitor->VerifyFound();
15790 }
15791
15792 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15793 {
15794 VkImageObj img(m_device);
15795 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15796 ASSERT_TRUE(img.initialized());
15797
15798 VkImageSubresource subres = {};
15799 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15800 subres.mipLevel = 0;
15801 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15802
15803 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15804 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15805 m_errorMonitor->VerifyFound();
15806 }
15807}
15808
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015809TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015810 VkResult err;
15811 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015812
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015814
Mike Stroyana3082432015-09-25 13:39:21 -060015815 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015816
15817 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015818 VkImage srcImage;
15819 VkImage dstImage;
15820 VkDeviceMemory srcMem;
15821 VkDeviceMemory destMem;
15822 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015823
15824 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015825 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15826 image_create_info.pNext = NULL;
15827 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15828 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15829 image_create_info.extent.width = 32;
15830 image_create_info.extent.height = 32;
15831 image_create_info.extent.depth = 1;
15832 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015833 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015834 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15835 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15836 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15837 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015839 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015840 ASSERT_VK_SUCCESS(err);
15841
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015842 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015843 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015844 ASSERT_VK_SUCCESS(err);
15845
15846 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015847 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015848 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15849 memAlloc.pNext = NULL;
15850 memAlloc.allocationSize = 0;
15851 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015852
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015853 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015854 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015855 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015856 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015857 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015858 ASSERT_VK_SUCCESS(err);
15859
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015860 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015861 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015862 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015863 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015864 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015865 ASSERT_VK_SUCCESS(err);
15866
15867 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15868 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015869 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015870 ASSERT_VK_SUCCESS(err);
15871
Tony Barbour552f6c02016-12-21 14:34:07 -070015872 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015873 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015874 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015875 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015876 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015877 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015878 copyRegion.srcOffset.x = 0;
15879 copyRegion.srcOffset.y = 0;
15880 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015881 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015882 copyRegion.dstSubresource.mipLevel = 0;
15883 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015884 // Introduce failure by forcing the dst layerCount to differ from src
15885 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015886 copyRegion.dstOffset.x = 0;
15887 copyRegion.dstOffset.y = 0;
15888 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015889 copyRegion.extent.width = 1;
15890 copyRegion.extent.height = 1;
15891 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015892 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015893 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015894
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015895 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015896
Chia-I Wuf7458c52015-10-26 21:10:41 +080015897 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015898 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015899 vkFreeMemory(m_device->device(), srcMem, NULL);
15900 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015901}
15902
Tony Barbourd6673642016-05-05 14:46:39 -060015903TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015904 TEST_DESCRIPTION("Creating images with unsuported formats ");
15905
15906 ASSERT_NO_FATAL_FAILURE(InitState());
15907 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15908 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015909 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 -060015910 VK_IMAGE_TILING_OPTIMAL, 0);
15911 ASSERT_TRUE(image.initialized());
15912
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015913 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015914 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015915 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015916 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15917 image_create_info.format = VK_FORMAT_UNDEFINED;
15918 image_create_info.extent.width = 32;
15919 image_create_info.extent.height = 32;
15920 image_create_info.extent.depth = 1;
15921 image_create_info.mipLevels = 1;
15922 image_create_info.arrayLayers = 1;
15923 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15924 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15925 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015926
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15928 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015929
15930 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015931 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15932 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15933 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15934 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015935 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15936 m_errorMonitor->VerifyFound();
15937
Tony Barbourd6673642016-05-05 14:46:39 -060015938 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015939 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015940 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15941 VkFormat format = static_cast<VkFormat>(f);
15942 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015943 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015944 unsupported = format;
15945 break;
15946 }
15947 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015948
Tony Barbourd6673642016-05-05 14:46:39 -060015949 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015950 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015951 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015952
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015953 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15954 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15955 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15956 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15957 m_errorMonitor->SetUnexpectedError(
15958 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15959 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15960 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015961 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015962 m_errorMonitor->VerifyFound();
15963 }
15964}
15965
15966TEST_F(VkLayerTest, ImageLayerViewTests) {
15967 VkResult ret;
15968 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15969
15970 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015971 auto depth_format = find_depth_stencil_format(m_device);
15972 if (!depth_format) {
15973 return;
15974 }
Tony Barbourd6673642016-05-05 14:46:39 -060015975
15976 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015977 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 -060015978 VK_IMAGE_TILING_OPTIMAL, 0);
15979 ASSERT_TRUE(image.initialized());
15980
15981 VkImageView imgView;
15982 VkImageViewCreateInfo imgViewInfo = {};
15983 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15984 imgViewInfo.image = image.handle();
15985 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15986 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15987 imgViewInfo.subresourceRange.layerCount = 1;
15988 imgViewInfo.subresourceRange.baseMipLevel = 0;
15989 imgViewInfo.subresourceRange.levelCount = 1;
15990 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15991
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015992 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015993 // View can't have baseMipLevel >= image's mipLevels - Expect
15994 // VIEW_CREATE_ERROR
15995 imgViewInfo.subresourceRange.baseMipLevel = 1;
15996 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15997 m_errorMonitor->VerifyFound();
15998 imgViewInfo.subresourceRange.baseMipLevel = 0;
15999
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016000 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016001 // View can't have baseArrayLayer >= image's arraySize - Expect
16002 // VIEW_CREATE_ERROR
16003 imgViewInfo.subresourceRange.baseArrayLayer = 1;
16004 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16005 m_errorMonitor->VerifyFound();
16006 imgViewInfo.subresourceRange.baseArrayLayer = 0;
16007
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070016008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060016009 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
16010 imgViewInfo.subresourceRange.levelCount = 0;
16011 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16012 m_errorMonitor->VerifyFound();
16013 imgViewInfo.subresourceRange.levelCount = 1;
16014
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016015 m_errorMonitor->SetDesiredFailureMsg(
16016 VK_DEBUG_REPORT_ERROR_BIT_EXT,
16017 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060016018 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
16019 imgViewInfo.subresourceRange.layerCount = 0;
16020 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16021 m_errorMonitor->VerifyFound();
16022 imgViewInfo.subresourceRange.layerCount = 1;
16023
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016024 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16025 "Formats MUST be IDENTICAL unless "
16026 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
16027 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060016028 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070016029 imgViewInfo.format = depth_format;
Tony Barbourd6673642016-05-05 14:46:39 -060016030 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16031 m_errorMonitor->VerifyFound();
16032 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16033
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060016035 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
16036 // VIEW_CREATE_ERROR
16037 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
16038 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16039 m_errorMonitor->VerifyFound();
16040 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
16041
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016042 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060016043 // TODO: Update framework to easily passing mutable flag into ImageObj init
16044 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070016045 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
16046 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16047 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060016048 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
16049 // VIEW_CREATE_ERROR
16050 VkImageCreateInfo mutImgInfo = image.create_info();
16051 VkImage mutImage;
16052 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016053 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060016054 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
16055 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
16056 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
16057 ASSERT_VK_SUCCESS(ret);
16058 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016059 m_errorMonitor->SetUnexpectedError(
16060 "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 -060016061 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
16062 m_errorMonitor->VerifyFound();
16063 imgViewInfo.image = image.handle();
16064 vkDestroyImage(m_device->handle(), mutImage, NULL);
16065}
16066
Dave Houlton75967fc2017-03-06 17:21:16 -070016067TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
16068 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
16069
16070 ASSERT_NO_FATAL_FAILURE(InitState());
16071
Jamie Madill35127872017-03-15 16:17:46 -040016072 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton75967fc2017-03-06 17:21:16 -070016073 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
16074 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
16075 if (device_features.textureCompressionBC) {
16076 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
16077 } else if (device_features.textureCompressionETC2) {
16078 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
16079 } else if (device_features.textureCompressionASTC_LDR) {
16080 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
16081 } else {
16082 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
16083 return;
16084 }
16085
16086 VkImageCreateInfo ci;
16087 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16088 ci.pNext = NULL;
16089 ci.flags = 0;
16090 ci.imageType = VK_IMAGE_TYPE_2D;
16091 ci.format = compressed_format;
16092 ci.extent = {32, 32, 1};
16093 ci.mipLevels = 6;
16094 ci.arrayLayers = 1;
16095 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16096 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16097 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16098 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16099 ci.queueFamilyIndexCount = 0;
16100 ci.pQueueFamilyIndices = NULL;
16101 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16102
16103 VkImageObj image(m_device);
16104 image.init(&ci);
16105 ASSERT_TRUE(image.initialized());
16106
16107 VkImageObj odd_image(m_device);
16108 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16109 odd_image.init(&ci);
16110 ASSERT_TRUE(odd_image.initialized());
16111
16112 // Allocate buffers
16113 VkMemoryPropertyFlags reqs = 0;
16114 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16115 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16116 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16117 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16118 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16119
16120 VkBufferImageCopy region = {};
16121 region.bufferRowLength = 0;
16122 region.bufferImageHeight = 0;
16123 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16124 region.imageSubresource.layerCount = 1;
16125 region.imageOffset = {0, 0, 0};
16126 region.bufferOffset = 0;
16127
16128 // start recording
16129 m_commandBuffer->BeginCommandBuffer();
16130
16131 // Mip level copies that work - 5 levels
16132 m_errorMonitor->ExpectSuccess();
16133
16134 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16135 region.imageExtent = {32, 32, 1};
16136 region.imageSubresource.mipLevel = 0;
16137 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16138 &region);
16139 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16140 &region);
16141
16142 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16143 region.imageExtent = {8, 8, 1};
16144 region.imageSubresource.mipLevel = 2;
16145 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16146 &region);
16147 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16148 &region);
16149
16150 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16151 region.imageExtent = {4, 4, 1};
16152 region.imageSubresource.mipLevel = 3;
16153 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16154 &region);
16155 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16156 &region);
16157
16158 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16159 region.imageExtent = {2, 2, 1};
16160 region.imageSubresource.mipLevel = 4;
16161 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16162 &region);
16163 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16164 &region);
16165
16166 region.imageExtent = {1, 1, 1};
16167 region.imageSubresource.mipLevel = 5;
16168 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16169 &region);
16170 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16171 &region);
16172 m_errorMonitor->VerifyNotFound();
16173
16174 // Buffer must accomodate a full compressed block, regardless of texel count
16175 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16176 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16177 &region);
16178 m_errorMonitor->VerifyFound();
16179 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16180 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16181 &region);
16182 m_errorMonitor->VerifyFound();
16183
16184 // Copy width < compressed block size, but not the full mip width
16185 region.imageExtent = {1, 2, 1};
16186 region.imageSubresource.mipLevel = 4;
16187 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16188 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16189 &region);
16190 m_errorMonitor->VerifyFound();
16191 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16192 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16193 &region);
16194 m_errorMonitor->VerifyFound();
16195
16196 // Copy height < compressed block size but not the full mip height
16197 region.imageExtent = {2, 1, 1};
16198 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16199 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16200 &region);
16201 m_errorMonitor->VerifyFound();
16202 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16203 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16204 &region);
16205 m_errorMonitor->VerifyFound();
16206
16207 // Offsets must be multiple of compressed block size
16208 region.imageOffset = {1, 1, 0};
16209 region.imageExtent = {1, 1, 1};
16210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16211 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16212 &region);
16213 m_errorMonitor->VerifyFound();
16214 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16215 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16216 &region);
16217 m_errorMonitor->VerifyFound();
16218
16219 // Offset + extent width = mip width - should succeed
16220 region.imageOffset = {4, 4, 0};
16221 region.imageExtent = {3, 4, 1};
16222 region.imageSubresource.mipLevel = 2;
16223 m_errorMonitor->ExpectSuccess();
16224 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16225 &region);
16226 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16227 &region);
16228 m_errorMonitor->VerifyNotFound();
16229
16230 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16231 region.imageExtent = {4, 4, 1};
16232 m_errorMonitor->ExpectSuccess();
16233 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16234 &region);
16235 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16236 &region);
16237 m_errorMonitor->VerifyNotFound();
16238
16239 // Offset + extent width < mip width and not a multiple of block width - should fail
16240 region.imageExtent = {3, 3, 1};
16241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16242 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16243 &region);
16244 m_errorMonitor->VerifyFound();
16245 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16246 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16247 &region);
16248 m_errorMonitor->VerifyFound();
16249}
16250
Dave Houlton59a20702017-02-02 17:26:23 -070016251TEST_F(VkLayerTest, ImageBufferCopyTests) {
16252 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16253
16254 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016255 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16256 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16257 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16258 return;
16259 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016260
16261 // Bail if any dimension of transfer granularity is 0.
16262 auto index = m_device->graphics_queue_node_index_;
16263 auto queue_family_properties = m_device->phy().queue_properties();
16264 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16265 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16266 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16267 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16268 return;
16269 }
16270
Dave Houlton59a20702017-02-02 17:26:23 -070016271 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16272 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16273 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016274 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16275 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16276 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16277 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16278
Dave Houlton59a20702017-02-02 17:26:23 -070016279 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16280 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16281 VK_IMAGE_TILING_OPTIMAL, 0);
16282 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16283 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16284 VK_IMAGE_TILING_OPTIMAL, 0);
16285 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16286 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016287 ASSERT_TRUE(image_64k.initialized());
16288 ASSERT_TRUE(image_16k.initialized());
16289 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016290
Dave Houltonf3229d52017-02-21 15:59:08 -070016291 // Verify all needed Depth/Stencil formats are supported
16292 bool missing_ds_support = false;
16293 VkFormatProperties props = {0, 0, 0};
16294 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16295 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16296 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16297 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16298 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16299 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16300 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16301 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16302
16303 if (!missing_ds_support) {
16304 ds_image_4D_1S.init(
16305 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16306 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16307 VK_IMAGE_TILING_OPTIMAL, 0);
16308 ASSERT_TRUE(ds_image_4D_1S.initialized());
16309
16310 ds_image_3D_1S.init(
16311 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16312 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16313 VK_IMAGE_TILING_OPTIMAL, 0);
16314 ASSERT_TRUE(ds_image_3D_1S.initialized());
16315
16316 ds_image_2D.init(
16317 256, 256, VK_FORMAT_D16_UNORM,
16318 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16319 VK_IMAGE_TILING_OPTIMAL, 0);
16320 ASSERT_TRUE(ds_image_2D.initialized());
16321
16322 ds_image_1S.init(
16323 256, 256, VK_FORMAT_S8_UINT,
16324 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16325 VK_IMAGE_TILING_OPTIMAL, 0);
16326 ASSERT_TRUE(ds_image_1S.initialized());
16327 }
16328
16329 // Allocate buffers
16330 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016331 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016332 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16333 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16334 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16335 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016336
16337 VkBufferImageCopy region = {};
16338 region.bufferRowLength = 0;
16339 region.bufferImageHeight = 0;
16340 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16341 region.imageSubresource.layerCount = 1;
16342 region.imageOffset = {0, 0, 0};
16343 region.imageExtent = {64, 64, 1};
16344 region.bufferOffset = 0;
16345
16346 // attempt copies before putting command buffer in recording state
16347 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16348 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16349 &region);
16350 m_errorMonitor->VerifyFound();
16351
16352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16353 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16354 &region);
16355 m_errorMonitor->VerifyFound();
16356
16357 // start recording
16358 m_commandBuffer->BeginCommandBuffer();
16359
16360 // successful copies
16361 m_errorMonitor->ExpectSuccess();
16362 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16363 &region);
16364 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16365 &region);
16366 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16367 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16368 &region);
16369 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16370 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16371 &region);
16372 region.imageOffset.x = 0;
16373 region.imageExtent.height = 64;
16374 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16375 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16376 &region);
16377 m_errorMonitor->VerifyNotFound();
16378
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016379 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016380 region.imageExtent = {65, 64, 1};
16381 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16382 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16383 &region);
16384 m_errorMonitor->VerifyFound();
16385
16386 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16387 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16388 &region);
16389 m_errorMonitor->VerifyFound();
16390
16391 // image/buffer too small (offset) on copy to image
16392 region.imageExtent = {64, 64, 1};
16393 region.imageOffset = {0, 4, 0};
16394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16395 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16396 &region);
16397 m_errorMonitor->VerifyFound();
16398
16399 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16400 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16401 &region);
16402 m_errorMonitor->VerifyFound();
16403
16404 // image/buffer too small on copy to buffer
16405 region.imageExtent = {64, 64, 1};
16406 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016407 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016408 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16409 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16410 &region);
16411 m_errorMonitor->VerifyFound();
16412
16413 region.imageExtent = {64, 65, 1};
16414 region.bufferOffset = 0;
16415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16416 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16417 &region);
16418 m_errorMonitor->VerifyFound();
16419
16420 // buffer size ok but rowlength causes loose packing
16421 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16422 region.imageExtent = {64, 64, 1};
16423 region.bufferRowLength = 68;
16424 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16425 &region);
16426 m_errorMonitor->VerifyFound();
16427
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016428 // An extent with zero area should produce a warning, but no error
16429 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16430 region.imageExtent.width = 0;
16431 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16432 &region);
16433 m_errorMonitor->VerifyFound();
16434
Dave Houlton59a20702017-02-02 17:26:23 -070016435 // aspect bits
16436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16437 region.imageExtent = {64, 64, 1};
16438 region.bufferRowLength = 0;
16439 region.bufferImageHeight = 0;
16440 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16441 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16442 buffer_16k.handle(), 1, &region);
16443 m_errorMonitor->VerifyFound();
16444
16445 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16446 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16447 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16448 &region);
16449 m_errorMonitor->VerifyFound();
16450
16451 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16452 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16453 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16454 buffer_16k.handle(), 1, &region);
16455 m_errorMonitor->VerifyFound();
16456
Dave Houltonf3229d52017-02-21 15:59:08 -070016457 // Test Depth/Stencil copies
16458 if (missing_ds_support) {
16459 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16460 } else {
16461 VkBufferImageCopy ds_region = {};
16462 ds_region.bufferOffset = 0;
16463 ds_region.bufferRowLength = 0;
16464 ds_region.bufferImageHeight = 0;
16465 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16466 ds_region.imageSubresource.mipLevel = 0;
16467 ds_region.imageSubresource.baseArrayLayer = 0;
16468 ds_region.imageSubresource.layerCount = 1;
16469 ds_region.imageOffset = {0, 0, 0};
16470 ds_region.imageExtent = {256, 256, 1};
16471
16472 // Depth copies that should succeed
16473 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16474 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16475 buffer_256k.handle(), 1, &ds_region);
16476 m_errorMonitor->VerifyNotFound();
16477
16478 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16479 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16480 buffer_256k.handle(), 1, &ds_region);
16481 m_errorMonitor->VerifyNotFound();
16482
16483 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16484 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16485 buffer_128k.handle(), 1, &ds_region);
16486 m_errorMonitor->VerifyNotFound();
16487
16488 // Depth copies that should fail
16489 ds_region.bufferOffset = 4;
16490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16491 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16492 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16493 buffer_256k.handle(), 1, &ds_region);
16494 m_errorMonitor->VerifyFound();
16495
16496 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16497 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16498 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16499 buffer_256k.handle(), 1, &ds_region);
16500 m_errorMonitor->VerifyFound();
16501
16502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16503 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16504 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16505 buffer_128k.handle(), 1, &ds_region);
16506 m_errorMonitor->VerifyFound();
16507
16508 // Stencil copies that should succeed
16509 ds_region.bufferOffset = 0;
16510 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16511 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16512 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16513 buffer_64k.handle(), 1, &ds_region);
16514 m_errorMonitor->VerifyNotFound();
16515
16516 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16517 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16518 buffer_64k.handle(), 1, &ds_region);
16519 m_errorMonitor->VerifyNotFound();
16520
16521 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16522 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16523 buffer_64k.handle(), 1, &ds_region);
16524 m_errorMonitor->VerifyNotFound();
16525
16526 // Stencil copies that should fail
16527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16528 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16529 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16530 buffer_16k.handle(), 1, &ds_region);
16531 m_errorMonitor->VerifyFound();
16532
16533 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16534 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16535 ds_region.bufferRowLength = 260;
16536 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16537 buffer_64k.handle(), 1, &ds_region);
16538 m_errorMonitor->VerifyFound();
16539
16540 ds_region.bufferRowLength = 0;
16541 ds_region.bufferOffset = 4;
16542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16543 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16544 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16545 buffer_64k.handle(), 1, &ds_region);
16546 m_errorMonitor->VerifyFound();
16547 }
16548
Dave Houlton584d51e2017-02-16 12:52:54 -070016549 // Test compressed formats, if supported
Jamie Madill35127872017-03-15 16:17:46 -040016550 VkPhysicalDeviceFeatures device_features = {};
Dave Houlton584d51e2017-02-16 12:52:54 -070016551 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016552 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16553 device_features.textureCompressionASTC_LDR)) {
16554 printf(" No compressed formats supported - block compression tests skipped.\n");
16555 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016556 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16557 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016558 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016559 image_16k_4x4comp.init(128, 128, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016560 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16561 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016562 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016563 image_16k_4x4comp.init(128, 128, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
Dave Houlton584d51e2017-02-16 12:52:54 -070016564 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016565 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16566 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016567 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016568 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16569 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016570 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16571 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016572 }
16573 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016574
Dave Houlton584d51e2017-02-16 12:52:54 -070016575 // Just fits
16576 m_errorMonitor->ExpectSuccess();
16577 region.imageExtent = {128, 128, 1};
16578 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16579 buffer_16k.handle(), 1, &region);
16580 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016581
Dave Houlton584d51e2017-02-16 12:52:54 -070016582 // with offset, too big for buffer
16583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16584 region.bufferOffset = 16;
16585 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16586 buffer_16k.handle(), 1, &region);
16587 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016588 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016589
Dave Houlton67e9b532017-03-02 17:00:10 -070016590 // extents that are not a multiple of compressed block size
16591 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16592 region.imageExtent.width = 66;
16593 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16594 buffer_16k.handle(), 1, &region);
16595 m_errorMonitor->VerifyFound();
16596 region.imageExtent.width = 128;
16597
16598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016599 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016600 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16601 buffer_16k.handle(), 1, &region);
16602 m_errorMonitor->VerifyFound();
16603 region.imageExtent.height = 128;
16604
16605 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16606
16607 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16608 m_errorMonitor->ExpectSuccess();
16609 region.imageExtent.width = 66;
16610 region.imageOffset.x = 64;
16611 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16612 buffer_16k.handle(), 1, &region);
16613 region.imageExtent.width = 16;
16614 region.imageOffset.x = 0;
16615 region.imageExtent.height = 2;
16616 region.imageOffset.y = 128;
16617 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016618 buffer_16k.handle(), 1, &region);
16619 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016620 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016621
Dave Houlton584d51e2017-02-16 12:52:54 -070016622 // buffer offset must be a multiple of texel block size (16)
16623 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16624 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16625 region.imageExtent = {64, 64, 1};
16626 region.bufferOffset = 24;
16627 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16628 buffer_16k.handle(), 1, &region);
16629 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016630
Dave Houlton584d51e2017-02-16 12:52:54 -070016631 // rowlength not a multiple of block width (4)
16632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16633 region.bufferOffset = 0;
16634 region.bufferRowLength = 130;
16635 region.bufferImageHeight = 0;
16636 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16637 buffer_64k.handle(), 1, &region);
16638 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016639
Dave Houlton584d51e2017-02-16 12:52:54 -070016640 // imageheight not a multiple of block height (4)
16641 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16642 region.bufferRowLength = 0;
16643 region.bufferImageHeight = 130;
16644 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16645 buffer_64k.handle(), 1, &region);
16646 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016647 }
Dave Houlton59a20702017-02-02 17:26:23 -070016648}
16649
Tony Barbourd6673642016-05-05 14:46:39 -060016650TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016651 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016652
16653 ASSERT_NO_FATAL_FAILURE(InitState());
16654
Rene Lindsay135204f2016-12-22 17:11:09 -070016655 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016656 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016657 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 -070016658 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016659 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016660 vk_testing::Buffer buffer;
16661 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016662 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016663 VkBufferImageCopy region = {};
16664 region.bufferRowLength = 128;
16665 region.bufferImageHeight = 128;
16666 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16667 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016668 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016669 region.imageExtent.height = 4;
16670 region.imageExtent.width = 4;
16671 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016672
16673 VkImageObj image2(m_device);
16674 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 -070016675 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016676 ASSERT_TRUE(image2.initialized());
16677 vk_testing::Buffer buffer2;
16678 VkMemoryPropertyFlags reqs2 = 0;
16679 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16680 VkBufferImageCopy region2 = {};
16681 region2.bufferRowLength = 128;
16682 region2.bufferImageHeight = 128;
16683 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16684 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16685 region2.imageSubresource.layerCount = 1;
16686 region2.imageExtent.height = 4;
16687 region2.imageExtent.width = 4;
16688 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016689 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016690
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016691 // Image must have offset.z of 0 and extent.depth of 1
16692 // Introduce failure by setting imageExtent.depth to 0
16693 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016694 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016695 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016696 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016697 m_errorMonitor->VerifyFound();
16698
16699 region.imageExtent.depth = 1;
16700
16701 // Image must have offset.z of 0 and extent.depth of 1
16702 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016703 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016704 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016706 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016707 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016708 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016709 m_errorMonitor->VerifyFound();
16710
16711 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016712 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16713 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016714 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016716 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16717 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016718 m_errorMonitor->VerifyFound();
16719
16720 // BufferOffset must be a multiple of 4
16721 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016722 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016723 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016724 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16725 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016726 m_errorMonitor->VerifyFound();
16727
16728 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16729 region.bufferOffset = 0;
16730 region.imageExtent.height = 128;
16731 region.imageExtent.width = 128;
16732 // Introduce failure by setting bufferRowLength > 0 but less than width
16733 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016734 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016735 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16736 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016737 m_errorMonitor->VerifyFound();
16738
16739 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16740 region.bufferRowLength = 128;
16741 // Introduce failure by setting bufferRowHeight > 0 but less than height
16742 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016743 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016744 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16745 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016746 m_errorMonitor->VerifyFound();
16747
16748 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016749 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016750 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16751 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016752 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016753 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16754 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016755 VkImageBlit blitRegion = {};
16756 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16757 blitRegion.srcSubresource.baseArrayLayer = 0;
16758 blitRegion.srcSubresource.layerCount = 1;
16759 blitRegion.srcSubresource.mipLevel = 0;
16760 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16761 blitRegion.dstSubresource.baseArrayLayer = 0;
16762 blitRegion.dstSubresource.layerCount = 1;
16763 blitRegion.dstSubresource.mipLevel = 0;
16764
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016765 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016766 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016767 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016768 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16769 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016770 m_errorMonitor->VerifyFound();
16771
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016772 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016773 VkImageMemoryBarrier img_barrier;
16774 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16775 img_barrier.pNext = NULL;
16776 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16777 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16778 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16779 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16780 img_barrier.image = image.handle();
16781 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16782 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16783 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16784 img_barrier.subresourceRange.baseArrayLayer = 0;
16785 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016786 img_barrier.subresourceRange.layerCount = 0;
16787 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016788 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16789 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016790 m_errorMonitor->VerifyFound();
16791 img_barrier.subresourceRange.layerCount = 1;
16792}
16793
16794TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016795 TEST_DESCRIPTION("Exceed the limits of image format ");
16796
Cody Northropc31a84f2016-08-22 10:41:47 -060016797 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016798 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016799 VkImageCreateInfo image_create_info = {};
16800 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16801 image_create_info.pNext = NULL;
16802 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16803 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16804 image_create_info.extent.width = 32;
16805 image_create_info.extent.height = 32;
16806 image_create_info.extent.depth = 1;
16807 image_create_info.mipLevels = 1;
16808 image_create_info.arrayLayers = 1;
16809 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16810 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16811 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16812 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16813 image_create_info.flags = 0;
16814
16815 VkImage nullImg;
16816 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016817 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16818 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016819 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016820 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16821 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16822 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016823 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016824
Tony Barbour0907e362017-03-09 15:05:30 -070016825 uint32_t maxDim =
16826 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
16827 // If max mip levels exceeds image extents, skip the max mip levels test
16828 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
16829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
16830 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16831 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16832 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16833 m_errorMonitor->VerifyFound();
16834 image_create_info.mipLevels = 1;
16835 }
Tony Barbourd6673642016-05-05 14:46:39 -060016836
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016837 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016838 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16839 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16840 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16841 m_errorMonitor->VerifyFound();
16842 image_create_info.arrayLayers = 1;
16843
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016844 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016845 int samples = imgFmtProps.sampleCounts >> 1;
16846 image_create_info.samples = (VkSampleCountFlagBits)samples;
16847 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16848 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16849 m_errorMonitor->VerifyFound();
16850 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16851
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16853 "pCreateInfo->initialLayout, must be "
16854 "VK_IMAGE_LAYOUT_UNDEFINED or "
16855 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016856 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16857 // Expect INVALID_LAYOUT
16858 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16859 m_errorMonitor->VerifyFound();
16860 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16861}
16862
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016863TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016864 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016866
16867 ASSERT_NO_FATAL_FAILURE(InitState());
16868
16869 VkImageObj src_image(m_device);
16870 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16871 VkImageObj dst_image(m_device);
16872 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16873
Tony Barbour552f6c02016-12-21 14:34:07 -070016874 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016875 VkImageCopy copy_region;
16876 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16877 copy_region.srcSubresource.mipLevel = 0;
16878 copy_region.srcSubresource.baseArrayLayer = 0;
16879 copy_region.srcSubresource.layerCount = 0;
16880 copy_region.srcOffset.x = 0;
16881 copy_region.srcOffset.y = 0;
16882 copy_region.srcOffset.z = 0;
16883 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16884 copy_region.dstSubresource.mipLevel = 0;
16885 copy_region.dstSubresource.baseArrayLayer = 0;
16886 copy_region.dstSubresource.layerCount = 0;
16887 copy_region.dstOffset.x = 0;
16888 copy_region.dstOffset.y = 0;
16889 copy_region.dstOffset.z = 0;
16890 copy_region.extent.width = 64;
16891 copy_region.extent.height = 64;
16892 copy_region.extent.depth = 1;
16893 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16894 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016895 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016896
16897 m_errorMonitor->VerifyFound();
16898}
16899
16900TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016901 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016903
16904 ASSERT_NO_FATAL_FAILURE(InitState());
16905
16906 VkImageObj src_image(m_device);
16907 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16908 VkImageObj dst_image(m_device);
16909 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16910
Tony Barbour552f6c02016-12-21 14:34:07 -070016911 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016912 VkImageCopy copy_region;
16913 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16914 copy_region.srcSubresource.mipLevel = 0;
16915 copy_region.srcSubresource.baseArrayLayer = 0;
16916 copy_region.srcSubresource.layerCount = 0;
16917 copy_region.srcOffset.x = 0;
16918 copy_region.srcOffset.y = 0;
16919 copy_region.srcOffset.z = 0;
16920 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16921 copy_region.dstSubresource.mipLevel = 0;
16922 copy_region.dstSubresource.baseArrayLayer = 0;
16923 copy_region.dstSubresource.layerCount = 0;
16924 copy_region.dstOffset.x = 0;
16925 copy_region.dstOffset.y = 0;
16926 copy_region.dstOffset.z = 0;
16927 copy_region.extent.width = 64;
16928 copy_region.extent.height = 64;
16929 copy_region.extent.depth = 1;
16930 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16931 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016932 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016933
16934 m_errorMonitor->VerifyFound();
16935}
16936
Karl Schultz6addd812016-02-02 17:17:23 -070016937TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016938 VkResult err;
16939 bool pass;
16940
16941 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016943
16944 ASSERT_NO_FATAL_FAILURE(InitState());
16945
16946 // Create two images of different types and try to copy between them
16947 VkImage srcImage;
16948 VkImage dstImage;
16949 VkDeviceMemory srcMem;
16950 VkDeviceMemory destMem;
16951 VkMemoryRequirements memReqs;
16952
16953 VkImageCreateInfo image_create_info = {};
16954 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16955 image_create_info.pNext = NULL;
16956 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16957 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16958 image_create_info.extent.width = 32;
16959 image_create_info.extent.height = 32;
16960 image_create_info.extent.depth = 1;
16961 image_create_info.mipLevels = 1;
16962 image_create_info.arrayLayers = 1;
16963 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16964 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16965 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16966 image_create_info.flags = 0;
16967
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016968 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016969 ASSERT_VK_SUCCESS(err);
16970
16971 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16972 // Introduce failure by creating second image with a different-sized format.
16973 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016975 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016976 ASSERT_VK_SUCCESS(err);
16977
16978 // Allocate memory
16979 VkMemoryAllocateInfo memAlloc = {};
16980 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16981 memAlloc.pNext = NULL;
16982 memAlloc.allocationSize = 0;
16983 memAlloc.memoryTypeIndex = 0;
16984
16985 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16986 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016987 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016988 ASSERT_TRUE(pass);
16989 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16990 ASSERT_VK_SUCCESS(err);
16991
16992 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16993 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016994 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016995 ASSERT_TRUE(pass);
16996 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16997 ASSERT_VK_SUCCESS(err);
16998
16999 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17000 ASSERT_VK_SUCCESS(err);
17001 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
17002 ASSERT_VK_SUCCESS(err);
17003
Tony Barbour552f6c02016-12-21 14:34:07 -070017004 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017005 VkImageCopy copyRegion;
17006 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17007 copyRegion.srcSubresource.mipLevel = 0;
17008 copyRegion.srcSubresource.baseArrayLayer = 0;
17009 copyRegion.srcSubresource.layerCount = 0;
17010 copyRegion.srcOffset.x = 0;
17011 copyRegion.srcOffset.y = 0;
17012 copyRegion.srcOffset.z = 0;
17013 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
17014 copyRegion.dstSubresource.mipLevel = 0;
17015 copyRegion.dstSubresource.baseArrayLayer = 0;
17016 copyRegion.dstSubresource.layerCount = 0;
17017 copyRegion.dstOffset.x = 0;
17018 copyRegion.dstOffset.y = 0;
17019 copyRegion.dstOffset.z = 0;
17020 copyRegion.extent.width = 1;
17021 copyRegion.extent.height = 1;
17022 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017023 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017024 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060017025
17026 m_errorMonitor->VerifyFound();
17027
17028 vkDestroyImage(m_device->device(), srcImage, NULL);
17029 vkDestroyImage(m_device->device(), dstImage, NULL);
17030 vkFreeMemory(m_device->device(), srcMem, NULL);
17031 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017032}
17033
Karl Schultz6addd812016-02-02 17:17:23 -070017034TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
17035 VkResult err;
17036 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017037
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017038 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17040 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017041
Mike Stroyana3082432015-09-25 13:39:21 -060017042 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017043 auto depth_format = find_depth_stencil_format(m_device);
17044 if (!depth_format) {
17045 return;
17046 }
Mike Stroyana3082432015-09-25 13:39:21 -060017047
17048 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017049 VkImage srcImage;
17050 VkImage dstImage;
17051 VkDeviceMemory srcMem;
17052 VkDeviceMemory destMem;
17053 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017054
17055 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017056 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17057 image_create_info.pNext = NULL;
17058 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17059 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17060 image_create_info.extent.width = 32;
17061 image_create_info.extent.height = 32;
17062 image_create_info.extent.depth = 1;
17063 image_create_info.mipLevels = 1;
17064 image_create_info.arrayLayers = 1;
17065 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17066 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17067 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17068 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017069
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017070 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017071 ASSERT_VK_SUCCESS(err);
17072
Karl Schultzbdb75952016-04-19 11:36:49 -060017073 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
17074
Mark Lobodzinskidb117632016-03-31 10:45:56 -060017075 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070017076 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070017077 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060017078 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017079
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017080 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017081 ASSERT_VK_SUCCESS(err);
17082
17083 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017084 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017085 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17086 memAlloc.pNext = NULL;
17087 memAlloc.allocationSize = 0;
17088 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017089
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017090 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017091 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017092 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017093 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017094 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017095 ASSERT_VK_SUCCESS(err);
17096
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017097 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017098 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017099 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017100 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017101 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017102 ASSERT_VK_SUCCESS(err);
17103
17104 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17105 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017106 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017107 ASSERT_VK_SUCCESS(err);
17108
Tony Barbour552f6c02016-12-21 14:34:07 -070017109 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017110 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017111 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017112 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017113 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017114 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017115 copyRegion.srcOffset.x = 0;
17116 copyRegion.srcOffset.y = 0;
17117 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017118 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017119 copyRegion.dstSubresource.mipLevel = 0;
17120 copyRegion.dstSubresource.baseArrayLayer = 0;
17121 copyRegion.dstSubresource.layerCount = 0;
17122 copyRegion.dstOffset.x = 0;
17123 copyRegion.dstOffset.y = 0;
17124 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017125 copyRegion.extent.width = 1;
17126 copyRegion.extent.height = 1;
17127 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017128 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017129 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017130
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017131 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017132
Chia-I Wuf7458c52015-10-26 21:10:41 +080017133 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017134 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017135 vkFreeMemory(m_device->device(), srcMem, NULL);
17136 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017137}
17138
Karl Schultz6addd812016-02-02 17:17:23 -070017139TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17140 VkResult err;
17141 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017142
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017143 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17144 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017145
Mike Stroyana3082432015-09-25 13:39:21 -060017146 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017147
17148 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017149 VkImage srcImage;
17150 VkImage dstImage;
17151 VkDeviceMemory srcMem;
17152 VkDeviceMemory destMem;
17153 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017154
17155 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017156 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17157 image_create_info.pNext = NULL;
17158 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17159 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17160 image_create_info.extent.width = 32;
17161 image_create_info.extent.height = 1;
17162 image_create_info.extent.depth = 1;
17163 image_create_info.mipLevels = 1;
17164 image_create_info.arrayLayers = 1;
17165 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17166 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17167 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17168 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017169
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017170 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017171 ASSERT_VK_SUCCESS(err);
17172
Karl Schultz6addd812016-02-02 17:17:23 -070017173 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017175 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017176 ASSERT_VK_SUCCESS(err);
17177
17178 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017179 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017180 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17181 memAlloc.pNext = NULL;
17182 memAlloc.allocationSize = 0;
17183 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017184
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017185 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017186 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017187 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017188 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017189 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017190 ASSERT_VK_SUCCESS(err);
17191
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017192 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017193 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017194 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017195 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017196 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017197 ASSERT_VK_SUCCESS(err);
17198
17199 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17200 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017201 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017202 ASSERT_VK_SUCCESS(err);
17203
Tony Barbour552f6c02016-12-21 14:34:07 -070017204 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017205 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017206 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17207 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017208 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017209 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017210 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017211 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017212 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017213 resolveRegion.srcOffset.x = 0;
17214 resolveRegion.srcOffset.y = 0;
17215 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017216 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017217 resolveRegion.dstSubresource.mipLevel = 0;
17218 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017219 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017220 resolveRegion.dstOffset.x = 0;
17221 resolveRegion.dstOffset.y = 0;
17222 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017223 resolveRegion.extent.width = 1;
17224 resolveRegion.extent.height = 1;
17225 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017226 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017227 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017228
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017229 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017230
Chia-I Wuf7458c52015-10-26 21:10:41 +080017231 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017232 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017233 vkFreeMemory(m_device->device(), srcMem, NULL);
17234 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017235}
17236
Karl Schultz6addd812016-02-02 17:17:23 -070017237TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17238 VkResult err;
17239 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017240
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017241 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17242 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017243
Mike Stroyana3082432015-09-25 13:39:21 -060017244 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017245
Chris Forbesa7530692016-05-08 12:35:39 +120017246 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017247 VkImage srcImage;
17248 VkImage dstImage;
17249 VkDeviceMemory srcMem;
17250 VkDeviceMemory destMem;
17251 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017252
17253 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017254 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17255 image_create_info.pNext = NULL;
17256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17257 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17258 image_create_info.extent.width = 32;
17259 image_create_info.extent.height = 1;
17260 image_create_info.extent.depth = 1;
17261 image_create_info.mipLevels = 1;
17262 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017263 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017264 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17265 // Note: Some implementations expect color attachment usage for any
17266 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017267 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017268 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017269
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017270 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017271 ASSERT_VK_SUCCESS(err);
17272
Karl Schultz6addd812016-02-02 17:17:23 -070017273 // Note: Some implementations expect color attachment usage for any
17274 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017275 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017276
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017277 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017278 ASSERT_VK_SUCCESS(err);
17279
17280 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017281 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017282 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17283 memAlloc.pNext = NULL;
17284 memAlloc.allocationSize = 0;
17285 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017286
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017287 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017288 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017289 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017290 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017291 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017292 ASSERT_VK_SUCCESS(err);
17293
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017294 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017295 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017296 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017297 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017298 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017299 ASSERT_VK_SUCCESS(err);
17300
17301 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17302 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017303 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017304 ASSERT_VK_SUCCESS(err);
17305
Tony Barbour552f6c02016-12-21 14:34:07 -070017306 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017307 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017308 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17309 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017310 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017311 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017312 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017313 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017314 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017315 resolveRegion.srcOffset.x = 0;
17316 resolveRegion.srcOffset.y = 0;
17317 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017318 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017319 resolveRegion.dstSubresource.mipLevel = 0;
17320 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017321 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017322 resolveRegion.dstOffset.x = 0;
17323 resolveRegion.dstOffset.y = 0;
17324 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017325 resolveRegion.extent.width = 1;
17326 resolveRegion.extent.height = 1;
17327 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017328 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017329 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017330
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017331 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017332
Chia-I Wuf7458c52015-10-26 21:10:41 +080017333 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017334 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017335 vkFreeMemory(m_device->device(), srcMem, NULL);
17336 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017337}
17338
Karl Schultz6addd812016-02-02 17:17:23 -070017339TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17340 VkResult err;
17341 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017342
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017343 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017344 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017345
Mike Stroyana3082432015-09-25 13:39:21 -060017346 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017347
17348 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017349 VkImage srcImage;
17350 VkImage dstImage;
17351 VkDeviceMemory srcMem;
17352 VkDeviceMemory destMem;
17353 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017354
17355 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017356 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17357 image_create_info.pNext = NULL;
17358 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17359 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17360 image_create_info.extent.width = 32;
17361 image_create_info.extent.height = 1;
17362 image_create_info.extent.depth = 1;
17363 image_create_info.mipLevels = 1;
17364 image_create_info.arrayLayers = 1;
17365 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17366 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17367 // Note: Some implementations expect color attachment usage for any
17368 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017369 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017370 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017371
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017372 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017373 ASSERT_VK_SUCCESS(err);
17374
Karl Schultz6addd812016-02-02 17:17:23 -070017375 // Set format to something other than source image
17376 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17377 // Note: Some implementations expect color attachment usage for any
17378 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017379 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017380 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017381
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017382 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017383 ASSERT_VK_SUCCESS(err);
17384
17385 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017386 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017387 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17388 memAlloc.pNext = NULL;
17389 memAlloc.allocationSize = 0;
17390 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017391
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017392 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017393 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017394 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017395 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017396 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017397 ASSERT_VK_SUCCESS(err);
17398
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017399 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017400 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017401 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017402 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017403 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017404 ASSERT_VK_SUCCESS(err);
17405
17406 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17407 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017408 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017409 ASSERT_VK_SUCCESS(err);
17410
Tony Barbour552f6c02016-12-21 14:34:07 -070017411 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017412 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017413 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17414 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017415 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017416 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017417 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017418 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017419 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017420 resolveRegion.srcOffset.x = 0;
17421 resolveRegion.srcOffset.y = 0;
17422 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017423 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017424 resolveRegion.dstSubresource.mipLevel = 0;
17425 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017426 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017427 resolveRegion.dstOffset.x = 0;
17428 resolveRegion.dstOffset.y = 0;
17429 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017430 resolveRegion.extent.width = 1;
17431 resolveRegion.extent.height = 1;
17432 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017433 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017434 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017435
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017436 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017437
Chia-I Wuf7458c52015-10-26 21:10:41 +080017438 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017439 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017440 vkFreeMemory(m_device->device(), srcMem, NULL);
17441 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017442}
17443
Karl Schultz6addd812016-02-02 17:17:23 -070017444TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17445 VkResult err;
17446 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017447
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017449 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017450
Mike Stroyana3082432015-09-25 13:39:21 -060017451 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017452
17453 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017454 VkImage srcImage;
17455 VkImage dstImage;
17456 VkDeviceMemory srcMem;
17457 VkDeviceMemory destMem;
17458 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017459
17460 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017461 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17462 image_create_info.pNext = NULL;
17463 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17464 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17465 image_create_info.extent.width = 32;
17466 image_create_info.extent.height = 1;
17467 image_create_info.extent.depth = 1;
17468 image_create_info.mipLevels = 1;
17469 image_create_info.arrayLayers = 1;
17470 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17471 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17472 // Note: Some implementations expect color attachment usage for any
17473 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017474 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017475 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017476
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017477 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017478 ASSERT_VK_SUCCESS(err);
17479
Karl Schultz6addd812016-02-02 17:17:23 -070017480 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17481 // Note: Some implementations expect color attachment usage for any
17482 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017483 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017484 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017485
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017486 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017487 ASSERT_VK_SUCCESS(err);
17488
17489 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017490 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017491 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17492 memAlloc.pNext = NULL;
17493 memAlloc.allocationSize = 0;
17494 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017495
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017496 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017497 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017498 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017499 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017500 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017501 ASSERT_VK_SUCCESS(err);
17502
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017503 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017504 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017505 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017506 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017507 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017508 ASSERT_VK_SUCCESS(err);
17509
17510 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17511 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017512 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017513 ASSERT_VK_SUCCESS(err);
17514
Tony Barbour552f6c02016-12-21 14:34:07 -070017515 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017516 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017517 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17518 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017519 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017520 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017521 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017522 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017523 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017524 resolveRegion.srcOffset.x = 0;
17525 resolveRegion.srcOffset.y = 0;
17526 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017527 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017528 resolveRegion.dstSubresource.mipLevel = 0;
17529 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017530 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017531 resolveRegion.dstOffset.x = 0;
17532 resolveRegion.dstOffset.y = 0;
17533 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017534 resolveRegion.extent.width = 1;
17535 resolveRegion.extent.height = 1;
17536 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017537 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017538 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017539
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017540 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017541
Chia-I Wuf7458c52015-10-26 21:10:41 +080017542 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017543 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017544 vkFreeMemory(m_device->device(), srcMem, NULL);
17545 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017546}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017547
Karl Schultz6addd812016-02-02 17:17:23 -070017548TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017549 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017550 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17551 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017552 // The image format check comes 2nd in validation so we trigger it first,
17553 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017554 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017555
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17557 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017558
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017559 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017560 auto depth_format = find_depth_stencil_format(m_device);
17561 if (!depth_format) {
17562 return;
17563 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017564
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017565 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017566 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17567 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017568
17569 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017570 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17571 ds_pool_ci.pNext = NULL;
17572 ds_pool_ci.maxSets = 1;
17573 ds_pool_ci.poolSizeCount = 1;
17574 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017575
17576 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017577 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017578 ASSERT_VK_SUCCESS(err);
17579
17580 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017581 dsl_binding.binding = 0;
17582 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17583 dsl_binding.descriptorCount = 1;
17584 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17585 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017586
17587 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017588 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17589 ds_layout_ci.pNext = NULL;
17590 ds_layout_ci.bindingCount = 1;
17591 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017592 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017593 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017594 ASSERT_VK_SUCCESS(err);
17595
17596 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017597 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017598 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017599 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017600 alloc_info.descriptorPool = ds_pool;
17601 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017602 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017603 ASSERT_VK_SUCCESS(err);
17604
Karl Schultz6addd812016-02-02 17:17:23 -070017605 VkImage image_bad;
17606 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017607 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017608 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017609 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017610 const int32_t tex_width = 32;
17611 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017612
17613 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017614 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17615 image_create_info.pNext = NULL;
17616 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17617 image_create_info.format = tex_format_bad;
17618 image_create_info.extent.width = tex_width;
17619 image_create_info.extent.height = tex_height;
17620 image_create_info.extent.depth = 1;
17621 image_create_info.mipLevels = 1;
17622 image_create_info.arrayLayers = 1;
17623 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17624 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017625 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017626 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017627
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017628 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017629 ASSERT_VK_SUCCESS(err);
17630 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017631 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17632 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017633 ASSERT_VK_SUCCESS(err);
17634
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017635 // ---Bind image memory---
17636 VkMemoryRequirements img_mem_reqs;
17637 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17638 VkMemoryAllocateInfo image_alloc_info = {};
17639 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17640 image_alloc_info.pNext = NULL;
17641 image_alloc_info.memoryTypeIndex = 0;
17642 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017643 bool pass =
17644 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 -070017645 ASSERT_TRUE(pass);
17646 VkDeviceMemory mem;
17647 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17648 ASSERT_VK_SUCCESS(err);
17649 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17650 ASSERT_VK_SUCCESS(err);
17651 // -----------------------
17652
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017653 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017654 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017655 image_view_create_info.image = image_bad;
17656 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17657 image_view_create_info.format = tex_format_bad;
17658 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17659 image_view_create_info.subresourceRange.baseMipLevel = 0;
17660 image_view_create_info.subresourceRange.layerCount = 1;
17661 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017662 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017663
17664 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017665 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017666
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017667 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017668
Chia-I Wuf7458c52015-10-26 21:10:41 +080017669 vkDestroyImage(m_device->device(), image_bad, NULL);
17670 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017671 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17672 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017673
17674 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017675}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017676
17677TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017678 TEST_DESCRIPTION(
17679 "Call ClearColorImage w/ a depth|stencil image and "
17680 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017681
17682 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017683 auto depth_format = find_depth_stencil_format(m_device);
17684 if (!depth_format) {
17685 return;
17686 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17688
Tony Barbour552f6c02016-12-21 14:34:07 -070017689 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017690
17691 // Color image
17692 VkClearColorValue clear_color;
17693 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17694 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17695 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17696 const int32_t img_width = 32;
17697 const int32_t img_height = 32;
17698 VkImageCreateInfo image_create_info = {};
17699 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17700 image_create_info.pNext = NULL;
17701 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17702 image_create_info.format = color_format;
17703 image_create_info.extent.width = img_width;
17704 image_create_info.extent.height = img_height;
17705 image_create_info.extent.depth = 1;
17706 image_create_info.mipLevels = 1;
17707 image_create_info.arrayLayers = 1;
17708 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17709 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17710 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17711
17712 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017713 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017714
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017715 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017716
17717 // Depth/Stencil image
17718 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017719 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017720 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17721 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017722 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017723 ds_image_create_info.extent.width = 64;
17724 ds_image_create_info.extent.height = 64;
17725 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017726 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 -060017727
17728 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017729 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017730
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017731 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 -060017732
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017734
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017735 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017736 &color_range);
17737
17738 m_errorMonitor->VerifyFound();
17739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17741 "vkCmdClearColorImage called with "
17742 "image created without "
17743 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017744
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017745 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017746 &color_range);
17747
17748 m_errorMonitor->VerifyFound();
17749
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017750 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017751 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17752 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017753
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017754 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17755 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017756
17757 m_errorMonitor->VerifyFound();
17758}
Tobin Ehliscde08892015-09-22 10:11:37 -060017759
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017760// WSI Enabled Tests
17761//
Chris Forbes09368e42016-10-13 11:59:22 +130017762#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017763TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17764
17765#if defined(VK_USE_PLATFORM_XCB_KHR)
17766 VkSurfaceKHR surface = VK_NULL_HANDLE;
17767
17768 VkResult err;
17769 bool pass;
17770 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17771 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17772 // uint32_t swapchain_image_count = 0;
17773 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17774 // uint32_t image_index = 0;
17775 // VkPresentInfoKHR present_info = {};
17776
17777 ASSERT_NO_FATAL_FAILURE(InitState());
17778
17779 // Use the create function from one of the VK_KHR_*_surface extension in
17780 // order to create a surface, testing all known errors in the process,
17781 // before successfully creating a surface:
17782 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17783 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17784 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17785 pass = (err != VK_SUCCESS);
17786 ASSERT_TRUE(pass);
17787 m_errorMonitor->VerifyFound();
17788
17789 // Next, try to create a surface with the wrong
17790 // VkXcbSurfaceCreateInfoKHR::sType:
17791 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17792 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17793 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17794 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17795 pass = (err != VK_SUCCESS);
17796 ASSERT_TRUE(pass);
17797 m_errorMonitor->VerifyFound();
17798
17799 // Create a native window, and then correctly create a surface:
17800 xcb_connection_t *connection;
17801 xcb_screen_t *screen;
17802 xcb_window_t xcb_window;
17803 xcb_intern_atom_reply_t *atom_wm_delete_window;
17804
17805 const xcb_setup_t *setup;
17806 xcb_screen_iterator_t iter;
17807 int scr;
17808 uint32_t value_mask, value_list[32];
17809 int width = 1;
17810 int height = 1;
17811
17812 connection = xcb_connect(NULL, &scr);
17813 ASSERT_TRUE(connection != NULL);
17814 setup = xcb_get_setup(connection);
17815 iter = xcb_setup_roots_iterator(setup);
17816 while (scr-- > 0)
17817 xcb_screen_next(&iter);
17818 screen = iter.data;
17819
17820 xcb_window = xcb_generate_id(connection);
17821
17822 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17823 value_list[0] = screen->black_pixel;
17824 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17825
17826 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17827 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17828
17829 /* Magic code that will send notification when window is destroyed */
17830 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17831 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17832
17833 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17834 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17835 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17836 free(reply);
17837
17838 xcb_map_window(connection, xcb_window);
17839
17840 // Force the x/y coordinates to 100,100 results are identical in consecutive
17841 // runs
17842 const uint32_t coords[] = { 100, 100 };
17843 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17844
17845 // Finally, try to correctly create a surface:
17846 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17847 xcb_create_info.pNext = NULL;
17848 xcb_create_info.flags = 0;
17849 xcb_create_info.connection = connection;
17850 xcb_create_info.window = xcb_window;
17851 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17852 pass = (err == VK_SUCCESS);
17853 ASSERT_TRUE(pass);
17854
17855 // Check if surface supports presentation:
17856
17857 // 1st, do so without having queried the queue families:
17858 VkBool32 supported = false;
17859 // TODO: Get the following error to come out:
17860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17861 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17862 "function");
17863 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17864 pass = (err != VK_SUCCESS);
17865 // ASSERT_TRUE(pass);
17866 // m_errorMonitor->VerifyFound();
17867
17868 // Next, query a queue family index that's too large:
17869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17870 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17871 pass = (err != VK_SUCCESS);
17872 ASSERT_TRUE(pass);
17873 m_errorMonitor->VerifyFound();
17874
17875 // Finally, do so correctly:
17876 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17877 // SUPPORTED
17878 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17879 pass = (err == VK_SUCCESS);
17880 ASSERT_TRUE(pass);
17881
17882 // Before proceeding, try to create a swapchain without having called
17883 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17884 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17885 swapchain_create_info.pNext = NULL;
17886 swapchain_create_info.flags = 0;
17887 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17888 swapchain_create_info.surface = surface;
17889 swapchain_create_info.imageArrayLayers = 1;
17890 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17891 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17892 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17893 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17894 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17895 pass = (err != VK_SUCCESS);
17896 ASSERT_TRUE(pass);
17897 m_errorMonitor->VerifyFound();
17898
17899 // Get the surface capabilities:
17900 VkSurfaceCapabilitiesKHR surface_capabilities;
17901
17902 // Do so correctly (only error logged by this entrypoint is if the
17903 // extension isn't enabled):
17904 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17905 pass = (err == VK_SUCCESS);
17906 ASSERT_TRUE(pass);
17907
17908 // Get the surface formats:
17909 uint32_t surface_format_count;
17910
17911 // First, try without a pointer to surface_format_count:
17912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17913 "specified as NULL");
17914 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17915 pass = (err == VK_SUCCESS);
17916 ASSERT_TRUE(pass);
17917 m_errorMonitor->VerifyFound();
17918
17919 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17920 // correctly done a 1st try (to get the count):
17921 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17922 surface_format_count = 0;
17923 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17924 pass = (err == VK_SUCCESS);
17925 ASSERT_TRUE(pass);
17926 m_errorMonitor->VerifyFound();
17927
17928 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17929 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17930 pass = (err == VK_SUCCESS);
17931 ASSERT_TRUE(pass);
17932
17933 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17934 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17935
17936 // Next, do a 2nd try with surface_format_count being set too high:
17937 surface_format_count += 5;
17938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17939 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17940 pass = (err == VK_SUCCESS);
17941 ASSERT_TRUE(pass);
17942 m_errorMonitor->VerifyFound();
17943
17944 // Finally, do a correct 1st and 2nd try:
17945 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17946 pass = (err == VK_SUCCESS);
17947 ASSERT_TRUE(pass);
17948 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17949 pass = (err == VK_SUCCESS);
17950 ASSERT_TRUE(pass);
17951
17952 // Get the surface present modes:
17953 uint32_t surface_present_mode_count;
17954
17955 // First, try without a pointer to surface_format_count:
17956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17957 "specified as NULL");
17958
17959 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17960 pass = (err == VK_SUCCESS);
17961 ASSERT_TRUE(pass);
17962 m_errorMonitor->VerifyFound();
17963
17964 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17965 // correctly done a 1st try (to get the count):
17966 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17967 surface_present_mode_count = 0;
17968 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17969 (VkPresentModeKHR *)&surface_present_mode_count);
17970 pass = (err == VK_SUCCESS);
17971 ASSERT_TRUE(pass);
17972 m_errorMonitor->VerifyFound();
17973
17974 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17975 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17976 pass = (err == VK_SUCCESS);
17977 ASSERT_TRUE(pass);
17978
17979 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17980 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17981
17982 // Next, do a 2nd try with surface_format_count being set too high:
17983 surface_present_mode_count += 5;
17984 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17985 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17986 pass = (err == VK_SUCCESS);
17987 ASSERT_TRUE(pass);
17988 m_errorMonitor->VerifyFound();
17989
17990 // Finally, do a correct 1st and 2nd try:
17991 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17992 pass = (err == VK_SUCCESS);
17993 ASSERT_TRUE(pass);
17994 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17995 pass = (err == VK_SUCCESS);
17996 ASSERT_TRUE(pass);
17997
17998 // Create a swapchain:
17999
18000 // First, try without a pointer to swapchain_create_info:
18001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
18002 "specified as NULL");
18003
18004 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
18005 pass = (err != VK_SUCCESS);
18006 ASSERT_TRUE(pass);
18007 m_errorMonitor->VerifyFound();
18008
18009 // Next, call with a non-NULL swapchain_create_info, that has the wrong
18010 // sType:
18011 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
18012 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
18013
18014 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18015 pass = (err != VK_SUCCESS);
18016 ASSERT_TRUE(pass);
18017 m_errorMonitor->VerifyFound();
18018
18019 // Next, call with a NULL swapchain pointer:
18020 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
18021 swapchain_create_info.pNext = NULL;
18022 swapchain_create_info.flags = 0;
18023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
18024 "specified as NULL");
18025
18026 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
18027 pass = (err != VK_SUCCESS);
18028 ASSERT_TRUE(pass);
18029 m_errorMonitor->VerifyFound();
18030
18031 // TODO: Enhance swapchain layer so that
18032 // swapchain_create_info.queueFamilyIndexCount is checked against something?
18033
18034 // Next, call with a queue family index that's too large:
18035 uint32_t queueFamilyIndex[2] = { 100000, 0 };
18036 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18037 swapchain_create_info.queueFamilyIndexCount = 2;
18038 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
18039 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
18040 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18041 pass = (err != VK_SUCCESS);
18042 ASSERT_TRUE(pass);
18043 m_errorMonitor->VerifyFound();
18044
18045 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
18046 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
18047 swapchain_create_info.queueFamilyIndexCount = 1;
18048 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18049 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
18050 "pCreateInfo->pQueueFamilyIndices).");
18051 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18052 pass = (err != VK_SUCCESS);
18053 ASSERT_TRUE(pass);
18054 m_errorMonitor->VerifyFound();
18055
18056 // Next, call with an invalid imageSharingMode:
18057 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
18058 swapchain_create_info.queueFamilyIndexCount = 1;
18059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
18060 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
18061 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
18062 pass = (err != VK_SUCCESS);
18063 ASSERT_TRUE(pass);
18064 m_errorMonitor->VerifyFound();
18065 // Fix for the future:
18066 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
18067 // SUPPORTED
18068 swapchain_create_info.queueFamilyIndexCount = 0;
18069 queueFamilyIndex[0] = 0;
18070 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
18071
18072 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
18073 // Get the images from a swapchain:
18074 // Acquire an image from a swapchain:
18075 // Present an image to a swapchain:
18076 // Destroy the swapchain:
18077
18078 // TODOs:
18079 //
18080 // - Try destroying the device without first destroying the swapchain
18081 //
18082 // - Try destroying the device without first destroying the surface
18083 //
18084 // - Try destroying the surface without first destroying the swapchain
18085
18086 // Destroy the surface:
18087 vkDestroySurfaceKHR(instance(), surface, NULL);
18088
18089 // Tear down the window:
18090 xcb_destroy_window(connection, xcb_window);
18091 xcb_disconnect(connection);
18092
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018093#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018094 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018095#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018096}
Chris Forbes09368e42016-10-13 11:59:22 +130018097#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018098
18099//
18100// POSITIVE VALIDATION TESTS
18101//
18102// These tests do not expect to encounter ANY validation errors pass only if this is true
18103
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070018104TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
18105 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
18106 ASSERT_NO_FATAL_FAILURE(InitState());
18107 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18108
18109 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18110 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18111 command_buffer_allocate_info.commandPool = m_commandPool;
18112 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18113 command_buffer_allocate_info.commandBufferCount = 1;
18114
18115 VkCommandBuffer secondary_command_buffer;
18116 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18117 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18118 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18119 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18120 command_buffer_inheritance_info.renderPass = m_renderPass;
18121 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18122
18123 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18124 command_buffer_begin_info.flags =
18125 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18126 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18127
18128 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18129 VkClearAttachment color_attachment;
18130 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18131 color_attachment.clearValue.color.float32[0] = 0;
18132 color_attachment.clearValue.color.float32[1] = 0;
18133 color_attachment.clearValue.color.float32[2] = 0;
18134 color_attachment.clearValue.color.float32[3] = 0;
18135 color_attachment.colorAttachment = 0;
18136 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18137 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18138}
18139
Tobin Ehlise0006882016-11-03 10:14:28 -060018140TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018141 TEST_DESCRIPTION(
18142 "Perform an image layout transition in a secondary command buffer followed "
18143 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018144 VkResult err;
18145 m_errorMonitor->ExpectSuccess();
18146 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018147 auto depth_format = find_depth_stencil_format(m_device);
18148 if (!depth_format) {
18149 return;
18150 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018151 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18152 // Allocate a secondary and primary cmd buffer
18153 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18154 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18155 command_buffer_allocate_info.commandPool = m_commandPool;
18156 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18157 command_buffer_allocate_info.commandBufferCount = 1;
18158
18159 VkCommandBuffer secondary_command_buffer;
18160 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18161 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18162 VkCommandBuffer primary_command_buffer;
18163 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18164 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18165 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18166 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18167 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18168 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18169 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18170
18171 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18172 ASSERT_VK_SUCCESS(err);
18173 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018174 image.init(128, 128, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlise0006882016-11-03 10:14:28 -060018175 ASSERT_TRUE(image.initialized());
18176 VkImageMemoryBarrier img_barrier = {};
18177 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18178 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18179 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18180 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18181 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18182 img_barrier.image = image.handle();
18183 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18184 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18185 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18186 img_barrier.subresourceRange.baseArrayLayer = 0;
18187 img_barrier.subresourceRange.baseMipLevel = 0;
18188 img_barrier.subresourceRange.layerCount = 1;
18189 img_barrier.subresourceRange.levelCount = 1;
18190 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18191 0, nullptr, 1, &img_barrier);
18192 err = vkEndCommandBuffer(secondary_command_buffer);
18193 ASSERT_VK_SUCCESS(err);
18194
18195 // Now update primary cmd buffer to execute secondary and transitions image
18196 command_buffer_begin_info.pInheritanceInfo = nullptr;
18197 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18198 ASSERT_VK_SUCCESS(err);
18199 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18200 VkImageMemoryBarrier img_barrier2 = {};
18201 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18202 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18203 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18204 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18205 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18206 img_barrier2.image = image.handle();
18207 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18208 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18209 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18210 img_barrier2.subresourceRange.baseArrayLayer = 0;
18211 img_barrier2.subresourceRange.baseMipLevel = 0;
18212 img_barrier2.subresourceRange.layerCount = 1;
18213 img_barrier2.subresourceRange.levelCount = 1;
18214 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18215 nullptr, 1, &img_barrier2);
18216 err = vkEndCommandBuffer(primary_command_buffer);
18217 ASSERT_VK_SUCCESS(err);
18218 VkSubmitInfo submit_info = {};
18219 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18220 submit_info.commandBufferCount = 1;
18221 submit_info.pCommandBuffers = &primary_command_buffer;
18222 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18223 ASSERT_VK_SUCCESS(err);
18224 m_errorMonitor->VerifyNotFound();
18225 err = vkDeviceWaitIdle(m_device->device());
18226 ASSERT_VK_SUCCESS(err);
18227 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18228 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18229}
18230
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018231// This is a positive test. No failures are expected.
18232TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018233 TEST_DESCRIPTION(
18234 "Ensure that the vkUpdateDescriptorSets validation code "
18235 "is ignoring VkWriteDescriptorSet members that are not "
18236 "related to the descriptor type specified by "
18237 "VkWriteDescriptorSet::descriptorType. Correct "
18238 "validation behavior will result in the test running to "
18239 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018240
18241 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18242
18243 ASSERT_NO_FATAL_FAILURE(InitState());
18244
18245 // Image Case
18246 {
18247 m_errorMonitor->ExpectSuccess();
18248
18249 VkImage image;
18250 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18251 const int32_t tex_width = 32;
18252 const int32_t tex_height = 32;
18253 VkImageCreateInfo image_create_info = {};
18254 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18255 image_create_info.pNext = NULL;
18256 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18257 image_create_info.format = tex_format;
18258 image_create_info.extent.width = tex_width;
18259 image_create_info.extent.height = tex_height;
18260 image_create_info.extent.depth = 1;
18261 image_create_info.mipLevels = 1;
18262 image_create_info.arrayLayers = 1;
18263 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18264 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18265 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18266 image_create_info.flags = 0;
18267 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18268 ASSERT_VK_SUCCESS(err);
18269
18270 VkMemoryRequirements memory_reqs;
18271 VkDeviceMemory image_memory;
18272 bool pass;
18273 VkMemoryAllocateInfo memory_info = {};
18274 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18275 memory_info.pNext = NULL;
18276 memory_info.allocationSize = 0;
18277 memory_info.memoryTypeIndex = 0;
18278 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18279 memory_info.allocationSize = memory_reqs.size;
18280 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18281 ASSERT_TRUE(pass);
18282 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18283 ASSERT_VK_SUCCESS(err);
18284 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18285 ASSERT_VK_SUCCESS(err);
18286
18287 VkImageViewCreateInfo image_view_create_info = {};
18288 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18289 image_view_create_info.image = image;
18290 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18291 image_view_create_info.format = tex_format;
18292 image_view_create_info.subresourceRange.layerCount = 1;
18293 image_view_create_info.subresourceRange.baseMipLevel = 0;
18294 image_view_create_info.subresourceRange.levelCount = 1;
18295 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18296
18297 VkImageView view;
18298 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18299 ASSERT_VK_SUCCESS(err);
18300
18301 VkDescriptorPoolSize ds_type_count = {};
18302 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18303 ds_type_count.descriptorCount = 1;
18304
18305 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18306 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18307 ds_pool_ci.pNext = NULL;
18308 ds_pool_ci.maxSets = 1;
18309 ds_pool_ci.poolSizeCount = 1;
18310 ds_pool_ci.pPoolSizes = &ds_type_count;
18311
18312 VkDescriptorPool ds_pool;
18313 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18314 ASSERT_VK_SUCCESS(err);
18315
18316 VkDescriptorSetLayoutBinding dsl_binding = {};
18317 dsl_binding.binding = 0;
18318 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18319 dsl_binding.descriptorCount = 1;
18320 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18321 dsl_binding.pImmutableSamplers = NULL;
18322
18323 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18324 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18325 ds_layout_ci.pNext = NULL;
18326 ds_layout_ci.bindingCount = 1;
18327 ds_layout_ci.pBindings = &dsl_binding;
18328 VkDescriptorSetLayout ds_layout;
18329 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18330 ASSERT_VK_SUCCESS(err);
18331
18332 VkDescriptorSet descriptor_set;
18333 VkDescriptorSetAllocateInfo alloc_info = {};
18334 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18335 alloc_info.descriptorSetCount = 1;
18336 alloc_info.descriptorPool = ds_pool;
18337 alloc_info.pSetLayouts = &ds_layout;
18338 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18339 ASSERT_VK_SUCCESS(err);
18340
18341 VkDescriptorImageInfo image_info = {};
18342 image_info.imageView = view;
18343 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18344
18345 VkWriteDescriptorSet descriptor_write;
18346 memset(&descriptor_write, 0, sizeof(descriptor_write));
18347 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18348 descriptor_write.dstSet = descriptor_set;
18349 descriptor_write.dstBinding = 0;
18350 descriptor_write.descriptorCount = 1;
18351 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18352 descriptor_write.pImageInfo = &image_info;
18353
18354 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18355 // be
18356 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18357 // This will most likely produce a crash if the parameter_validation
18358 // layer
18359 // does not correctly ignore pBufferInfo.
18360 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18361 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18362
18363 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18364
18365 m_errorMonitor->VerifyNotFound();
18366
18367 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18368 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18369 vkDestroyImageView(m_device->device(), view, NULL);
18370 vkDestroyImage(m_device->device(), image, NULL);
18371 vkFreeMemory(m_device->device(), image_memory, NULL);
18372 }
18373
18374 // Buffer Case
18375 {
18376 m_errorMonitor->ExpectSuccess();
18377
18378 VkBuffer buffer;
18379 uint32_t queue_family_index = 0;
18380 VkBufferCreateInfo buffer_create_info = {};
18381 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18382 buffer_create_info.size = 1024;
18383 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18384 buffer_create_info.queueFamilyIndexCount = 1;
18385 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18386
18387 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18388 ASSERT_VK_SUCCESS(err);
18389
18390 VkMemoryRequirements memory_reqs;
18391 VkDeviceMemory buffer_memory;
18392 bool pass;
18393 VkMemoryAllocateInfo memory_info = {};
18394 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18395 memory_info.pNext = NULL;
18396 memory_info.allocationSize = 0;
18397 memory_info.memoryTypeIndex = 0;
18398
18399 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18400 memory_info.allocationSize = memory_reqs.size;
18401 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18402 ASSERT_TRUE(pass);
18403
18404 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18405 ASSERT_VK_SUCCESS(err);
18406 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18407 ASSERT_VK_SUCCESS(err);
18408
18409 VkDescriptorPoolSize ds_type_count = {};
18410 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18411 ds_type_count.descriptorCount = 1;
18412
18413 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18414 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18415 ds_pool_ci.pNext = NULL;
18416 ds_pool_ci.maxSets = 1;
18417 ds_pool_ci.poolSizeCount = 1;
18418 ds_pool_ci.pPoolSizes = &ds_type_count;
18419
18420 VkDescriptorPool ds_pool;
18421 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18422 ASSERT_VK_SUCCESS(err);
18423
18424 VkDescriptorSetLayoutBinding dsl_binding = {};
18425 dsl_binding.binding = 0;
18426 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18427 dsl_binding.descriptorCount = 1;
18428 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18429 dsl_binding.pImmutableSamplers = NULL;
18430
18431 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18432 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18433 ds_layout_ci.pNext = NULL;
18434 ds_layout_ci.bindingCount = 1;
18435 ds_layout_ci.pBindings = &dsl_binding;
18436 VkDescriptorSetLayout ds_layout;
18437 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18438 ASSERT_VK_SUCCESS(err);
18439
18440 VkDescriptorSet descriptor_set;
18441 VkDescriptorSetAllocateInfo alloc_info = {};
18442 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18443 alloc_info.descriptorSetCount = 1;
18444 alloc_info.descriptorPool = ds_pool;
18445 alloc_info.pSetLayouts = &ds_layout;
18446 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18447 ASSERT_VK_SUCCESS(err);
18448
18449 VkDescriptorBufferInfo buffer_info = {};
18450 buffer_info.buffer = buffer;
18451 buffer_info.offset = 0;
18452 buffer_info.range = 1024;
18453
18454 VkWriteDescriptorSet descriptor_write;
18455 memset(&descriptor_write, 0, sizeof(descriptor_write));
18456 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18457 descriptor_write.dstSet = descriptor_set;
18458 descriptor_write.dstBinding = 0;
18459 descriptor_write.descriptorCount = 1;
18460 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18461 descriptor_write.pBufferInfo = &buffer_info;
18462
18463 // Set pImageInfo and pTexelBufferView to invalid values, which should
18464 // be
18465 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18466 // This will most likely produce a crash if the parameter_validation
18467 // layer
18468 // does not correctly ignore pImageInfo.
18469 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18470 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18471
18472 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18473
18474 m_errorMonitor->VerifyNotFound();
18475
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018476 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18477 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18478 vkDestroyBuffer(m_device->device(), buffer, NULL);
18479 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18480 }
18481
18482 // Texel Buffer Case
18483 {
18484 m_errorMonitor->ExpectSuccess();
18485
18486 VkBuffer buffer;
18487 uint32_t queue_family_index = 0;
18488 VkBufferCreateInfo buffer_create_info = {};
18489 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18490 buffer_create_info.size = 1024;
18491 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18492 buffer_create_info.queueFamilyIndexCount = 1;
18493 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18494
18495 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18496 ASSERT_VK_SUCCESS(err);
18497
18498 VkMemoryRequirements memory_reqs;
18499 VkDeviceMemory buffer_memory;
18500 bool pass;
18501 VkMemoryAllocateInfo memory_info = {};
18502 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18503 memory_info.pNext = NULL;
18504 memory_info.allocationSize = 0;
18505 memory_info.memoryTypeIndex = 0;
18506
18507 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18508 memory_info.allocationSize = memory_reqs.size;
18509 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18510 ASSERT_TRUE(pass);
18511
18512 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18513 ASSERT_VK_SUCCESS(err);
18514 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18515 ASSERT_VK_SUCCESS(err);
18516
18517 VkBufferViewCreateInfo buff_view_ci = {};
18518 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18519 buff_view_ci.buffer = buffer;
18520 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18521 buff_view_ci.range = VK_WHOLE_SIZE;
18522 VkBufferView buffer_view;
18523 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18524
18525 VkDescriptorPoolSize ds_type_count = {};
18526 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18527 ds_type_count.descriptorCount = 1;
18528
18529 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18530 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18531 ds_pool_ci.pNext = NULL;
18532 ds_pool_ci.maxSets = 1;
18533 ds_pool_ci.poolSizeCount = 1;
18534 ds_pool_ci.pPoolSizes = &ds_type_count;
18535
18536 VkDescriptorPool ds_pool;
18537 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18538 ASSERT_VK_SUCCESS(err);
18539
18540 VkDescriptorSetLayoutBinding dsl_binding = {};
18541 dsl_binding.binding = 0;
18542 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18543 dsl_binding.descriptorCount = 1;
18544 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18545 dsl_binding.pImmutableSamplers = NULL;
18546
18547 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18548 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18549 ds_layout_ci.pNext = NULL;
18550 ds_layout_ci.bindingCount = 1;
18551 ds_layout_ci.pBindings = &dsl_binding;
18552 VkDescriptorSetLayout ds_layout;
18553 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18554 ASSERT_VK_SUCCESS(err);
18555
18556 VkDescriptorSet descriptor_set;
18557 VkDescriptorSetAllocateInfo alloc_info = {};
18558 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18559 alloc_info.descriptorSetCount = 1;
18560 alloc_info.descriptorPool = ds_pool;
18561 alloc_info.pSetLayouts = &ds_layout;
18562 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18563 ASSERT_VK_SUCCESS(err);
18564
18565 VkWriteDescriptorSet descriptor_write;
18566 memset(&descriptor_write, 0, sizeof(descriptor_write));
18567 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18568 descriptor_write.dstSet = descriptor_set;
18569 descriptor_write.dstBinding = 0;
18570 descriptor_write.descriptorCount = 1;
18571 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18572 descriptor_write.pTexelBufferView = &buffer_view;
18573
18574 // Set pImageInfo and pBufferInfo to invalid values, which should be
18575 // ignored for descriptorType ==
18576 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18577 // This will most likely produce a crash if the parameter_validation
18578 // layer
18579 // does not correctly ignore pImageInfo and pBufferInfo.
18580 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18581 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18582
18583 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18584
18585 m_errorMonitor->VerifyNotFound();
18586
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018587 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18588 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18589 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18590 vkDestroyBuffer(m_device->device(), buffer, NULL);
18591 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18592 }
18593}
18594
Tobin Ehlisf7428442016-10-25 07:58:24 -060018595TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18596 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18597
18598 ASSERT_NO_FATAL_FAILURE(InitState());
18599 // Create layout where two binding #s are "1"
18600 static const uint32_t NUM_BINDINGS = 3;
18601 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18602 dsl_binding[0].binding = 1;
18603 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18604 dsl_binding[0].descriptorCount = 1;
18605 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18606 dsl_binding[0].pImmutableSamplers = NULL;
18607 dsl_binding[1].binding = 0;
18608 dsl_binding[1].descriptorCount = 1;
18609 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18610 dsl_binding[1].descriptorCount = 1;
18611 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18612 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018613 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018614 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18615 dsl_binding[2].descriptorCount = 1;
18616 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18617 dsl_binding[2].pImmutableSamplers = NULL;
18618
18619 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18620 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18621 ds_layout_ci.pNext = NULL;
18622 ds_layout_ci.bindingCount = NUM_BINDINGS;
18623 ds_layout_ci.pBindings = dsl_binding;
18624 VkDescriptorSetLayout ds_layout;
18625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18626 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18627 m_errorMonitor->VerifyFound();
18628}
18629
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018630TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018631 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18632
18633 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018634
Tony Barbour552f6c02016-12-21 14:34:07 -070018635 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018636
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018637 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18638
18639 {
18640 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18641 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18642 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18643 m_errorMonitor->VerifyFound();
18644 }
18645
18646 {
18647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18648 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18649 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18650 m_errorMonitor->VerifyFound();
18651 }
18652
18653 {
18654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18655 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18656 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18657 m_errorMonitor->VerifyFound();
18658 }
18659
18660 {
18661 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18662 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18663 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18664 m_errorMonitor->VerifyFound();
18665 }
18666
18667 {
18668 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18669 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18670 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18671 m_errorMonitor->VerifyFound();
18672 }
18673
18674 {
18675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18676 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18677 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18678 m_errorMonitor->VerifyFound();
18679 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018680
18681 {
18682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18683 VkRect2D scissor = {{-1, 0}, {16, 16}};
18684 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18685 m_errorMonitor->VerifyFound();
18686 }
18687
18688 {
18689 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18690 VkRect2D scissor = {{0, -2}, {16, 16}};
18691 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18692 m_errorMonitor->VerifyFound();
18693 }
18694
18695 {
18696 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18697 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18698 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18699 m_errorMonitor->VerifyFound();
18700 }
18701
18702 {
18703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18704 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18705 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18706 m_errorMonitor->VerifyFound();
18707 }
18708
Tony Barbour552f6c02016-12-21 14:34:07 -070018709 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018710}
18711
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018712// This is a positive test. No failures are expected.
18713TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18714 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18715 VkResult err;
18716
18717 ASSERT_NO_FATAL_FAILURE(InitState());
18718 m_errorMonitor->ExpectSuccess();
18719 VkDescriptorPoolSize ds_type_count = {};
18720 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18721 ds_type_count.descriptorCount = 2;
18722
18723 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18724 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18725 ds_pool_ci.pNext = NULL;
18726 ds_pool_ci.maxSets = 1;
18727 ds_pool_ci.poolSizeCount = 1;
18728 ds_pool_ci.pPoolSizes = &ds_type_count;
18729
18730 VkDescriptorPool ds_pool;
18731 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18732 ASSERT_VK_SUCCESS(err);
18733
18734 // Create layout with two uniform buffer descriptors w/ empty binding between them
18735 static const uint32_t NUM_BINDINGS = 3;
18736 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18737 dsl_binding[0].binding = 0;
18738 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18739 dsl_binding[0].descriptorCount = 1;
18740 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18741 dsl_binding[0].pImmutableSamplers = NULL;
18742 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018743 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018744 dsl_binding[2].binding = 2;
18745 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18746 dsl_binding[2].descriptorCount = 1;
18747 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18748 dsl_binding[2].pImmutableSamplers = NULL;
18749
18750 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18751 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18752 ds_layout_ci.pNext = NULL;
18753 ds_layout_ci.bindingCount = NUM_BINDINGS;
18754 ds_layout_ci.pBindings = dsl_binding;
18755 VkDescriptorSetLayout ds_layout;
18756 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18757 ASSERT_VK_SUCCESS(err);
18758
18759 VkDescriptorSet descriptor_set = {};
18760 VkDescriptorSetAllocateInfo alloc_info = {};
18761 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18762 alloc_info.descriptorSetCount = 1;
18763 alloc_info.descriptorPool = ds_pool;
18764 alloc_info.pSetLayouts = &ds_layout;
18765 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18766 ASSERT_VK_SUCCESS(err);
18767
18768 // Create a buffer to be used for update
18769 VkBufferCreateInfo buff_ci = {};
18770 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18771 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18772 buff_ci.size = 256;
18773 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18774 VkBuffer buffer;
18775 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18776 ASSERT_VK_SUCCESS(err);
18777 // Have to bind memory to buffer before descriptor update
18778 VkMemoryAllocateInfo mem_alloc = {};
18779 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18780 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018781 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018782 mem_alloc.memoryTypeIndex = 0;
18783
18784 VkMemoryRequirements mem_reqs;
18785 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18786 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18787 if (!pass) {
18788 vkDestroyBuffer(m_device->device(), buffer, NULL);
18789 return;
18790 }
18791
18792 VkDeviceMemory mem;
18793 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18794 ASSERT_VK_SUCCESS(err);
18795 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18796 ASSERT_VK_SUCCESS(err);
18797
18798 // Only update the descriptor at binding 2
18799 VkDescriptorBufferInfo buff_info = {};
18800 buff_info.buffer = buffer;
18801 buff_info.offset = 0;
18802 buff_info.range = VK_WHOLE_SIZE;
18803 VkWriteDescriptorSet descriptor_write = {};
18804 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18805 descriptor_write.dstBinding = 2;
18806 descriptor_write.descriptorCount = 1;
18807 descriptor_write.pTexelBufferView = nullptr;
18808 descriptor_write.pBufferInfo = &buff_info;
18809 descriptor_write.pImageInfo = nullptr;
18810 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18811 descriptor_write.dstSet = descriptor_set;
18812
18813 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18814
18815 m_errorMonitor->VerifyNotFound();
18816 // Cleanup
18817 vkFreeMemory(m_device->device(), mem, NULL);
18818 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18819 vkDestroyBuffer(m_device->device(), buffer, NULL);
18820 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18821}
18822
18823// This is a positive test. No failures are expected.
18824TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18825 VkResult err;
18826 bool pass;
18827
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018828 TEST_DESCRIPTION(
18829 "Create a buffer, allocate memory, bind memory, destroy "
18830 "the buffer, create an image, and bind the same memory to "
18831 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018832
18833 m_errorMonitor->ExpectSuccess();
18834
18835 ASSERT_NO_FATAL_FAILURE(InitState());
18836
18837 VkBuffer buffer;
18838 VkImage image;
18839 VkDeviceMemory mem;
18840 VkMemoryRequirements mem_reqs;
18841
18842 VkBufferCreateInfo buf_info = {};
18843 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18844 buf_info.pNext = NULL;
18845 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18846 buf_info.size = 256;
18847 buf_info.queueFamilyIndexCount = 0;
18848 buf_info.pQueueFamilyIndices = NULL;
18849 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18850 buf_info.flags = 0;
18851 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18852 ASSERT_VK_SUCCESS(err);
18853
18854 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18855
18856 VkMemoryAllocateInfo alloc_info = {};
18857 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18858 alloc_info.pNext = NULL;
18859 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018860
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018861 // Ensure memory is big enough for both bindings
18862 alloc_info.allocationSize = 0x10000;
18863
18864 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18865 if (!pass) {
18866 vkDestroyBuffer(m_device->device(), buffer, NULL);
18867 return;
18868 }
18869
18870 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18871 ASSERT_VK_SUCCESS(err);
18872
18873 uint8_t *pData;
18874 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18875 ASSERT_VK_SUCCESS(err);
18876
18877 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18878
18879 vkUnmapMemory(m_device->device(), mem);
18880
18881 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18882 ASSERT_VK_SUCCESS(err);
18883
18884 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18885 // memory. In fact, it was never used by the GPU.
18886 // Just be be sure, wait for idle.
18887 vkDestroyBuffer(m_device->device(), buffer, NULL);
18888 vkDeviceWaitIdle(m_device->device());
18889
Tobin Ehlis6a005702016-12-28 15:25:56 -070018890 // Use optimal as some platforms report linear support but then fail image creation
18891 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18892 VkImageFormatProperties image_format_properties;
18893 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18894 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18895 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018896 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018897 vkFreeMemory(m_device->device(), mem, NULL);
18898 return;
18899 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018900 VkImageCreateInfo image_create_info = {};
18901 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18902 image_create_info.pNext = NULL;
18903 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18904 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18905 image_create_info.extent.width = 64;
18906 image_create_info.extent.height = 64;
18907 image_create_info.extent.depth = 1;
18908 image_create_info.mipLevels = 1;
18909 image_create_info.arrayLayers = 1;
18910 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018911 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018912 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18913 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18914 image_create_info.queueFamilyIndexCount = 0;
18915 image_create_info.pQueueFamilyIndices = NULL;
18916 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18917 image_create_info.flags = 0;
18918
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018919 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018920 * to be textures or it will be the staging image if they are not.
18921 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018922 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18923 ASSERT_VK_SUCCESS(err);
18924
18925 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18926
Tobin Ehlis6a005702016-12-28 15:25:56 -070018927 VkMemoryAllocateInfo mem_alloc = {};
18928 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18929 mem_alloc.pNext = NULL;
18930 mem_alloc.allocationSize = 0;
18931 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018932 mem_alloc.allocationSize = mem_reqs.size;
18933
18934 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18935 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018936 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018937 vkDestroyImage(m_device->device(), image, NULL);
18938 return;
18939 }
18940
18941 // VALIDATION FAILURE:
18942 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18943 ASSERT_VK_SUCCESS(err);
18944
18945 m_errorMonitor->VerifyNotFound();
18946
18947 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018948 vkDestroyImage(m_device->device(), image, NULL);
18949}
18950
Tony Barbourab713912017-02-02 14:17:35 -070018951// This is a positive test. No failures are expected.
18952TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18953 VkResult err;
18954
18955 TEST_DESCRIPTION(
18956 "Call all applicable destroy and free routines with NULL"
18957 "handles, expecting no validation errors");
18958
18959 m_errorMonitor->ExpectSuccess();
18960
18961 ASSERT_NO_FATAL_FAILURE(InitState());
18962 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18963 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18964 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18965 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18966 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18967 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18968 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18969 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18970 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18971 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18972 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18973 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18974 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18975 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18976 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18977 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18978 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18979 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18980 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18981 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18982
18983 VkCommandPool command_pool;
18984 VkCommandPoolCreateInfo pool_create_info{};
18985 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18986 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18987 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18988 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18989 VkCommandBuffer command_buffers[3] = {};
18990 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18991 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18992 command_buffer_allocate_info.commandPool = command_pool;
18993 command_buffer_allocate_info.commandBufferCount = 1;
18994 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18995 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18996 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18997 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18998
18999 VkDescriptorPoolSize ds_type_count = {};
19000 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19001 ds_type_count.descriptorCount = 1;
19002
19003 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19004 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19005 ds_pool_ci.pNext = NULL;
19006 ds_pool_ci.maxSets = 1;
19007 ds_pool_ci.poolSizeCount = 1;
19008 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
19009 ds_pool_ci.pPoolSizes = &ds_type_count;
19010
19011 VkDescriptorPool ds_pool;
19012 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19013 ASSERT_VK_SUCCESS(err);
19014
19015 VkDescriptorSetLayoutBinding dsl_binding = {};
19016 dsl_binding.binding = 2;
19017 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19018 dsl_binding.descriptorCount = 1;
19019 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19020 dsl_binding.pImmutableSamplers = NULL;
19021 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19022 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19023 ds_layout_ci.pNext = NULL;
19024 ds_layout_ci.bindingCount = 1;
19025 ds_layout_ci.pBindings = &dsl_binding;
19026 VkDescriptorSetLayout ds_layout;
19027 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19028 ASSERT_VK_SUCCESS(err);
19029
19030 VkDescriptorSet descriptor_sets[3] = {};
19031 VkDescriptorSetAllocateInfo alloc_info = {};
19032 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19033 alloc_info.descriptorSetCount = 1;
19034 alloc_info.descriptorPool = ds_pool;
19035 alloc_info.pSetLayouts = &ds_layout;
19036 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
19037 ASSERT_VK_SUCCESS(err);
19038 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
19039 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19040 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19041
19042 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
19043
19044 m_errorMonitor->VerifyNotFound();
19045}
19046
Tony Barbour626994c2017-02-08 15:29:37 -070019047TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070019048 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070019049
19050 m_errorMonitor->ExpectSuccess();
19051
19052 ASSERT_NO_FATAL_FAILURE(InitState());
19053 VkCommandBuffer cmd_bufs[4];
19054 VkCommandBufferAllocateInfo alloc_info;
19055 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19056 alloc_info.pNext = NULL;
19057 alloc_info.commandBufferCount = 4;
19058 alloc_info.commandPool = m_commandPool;
19059 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19060 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
19061 VkImageObj image(m_device);
Mike Weiblen62d08a32017-03-07 22:18:27 -070019062 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM,
19063 (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT),
19064 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour626994c2017-02-08 15:29:37 -070019065 ASSERT_TRUE(image.initialized());
19066 VkCommandBufferBeginInfo cb_binfo;
19067 cb_binfo.pNext = NULL;
19068 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19069 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
19070 cb_binfo.flags = 0;
19071 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
19072 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
19073 VkImageMemoryBarrier img_barrier = {};
19074 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19075 img_barrier.pNext = NULL;
19076 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19077 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
19078 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19079 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
19080 img_barrier.image = image.handle();
19081 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19082 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
19083 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19084 img_barrier.subresourceRange.baseArrayLayer = 0;
19085 img_barrier.subresourceRange.baseMipLevel = 0;
19086 img_barrier.subresourceRange.layerCount = 1;
19087 img_barrier.subresourceRange.levelCount = 1;
19088 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19089 &img_barrier);
19090 vkEndCommandBuffer(cmd_bufs[0]);
19091 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
19092 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
19093 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19094 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19095 &img_barrier);
19096 vkEndCommandBuffer(cmd_bufs[1]);
19097 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
19098 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19099 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19100 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19101 &img_barrier);
19102 vkEndCommandBuffer(cmd_bufs[2]);
19103 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
19104 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19105 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19106 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19107 &img_barrier);
19108 vkEndCommandBuffer(cmd_bufs[3]);
19109
19110 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
19111 VkSemaphore semaphore1, semaphore2;
19112 VkSemaphoreCreateInfo semaphore_create_info{};
19113 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19114 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
19115 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
19116 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
19117 VkSubmitInfo submit_info[3];
19118 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19119 submit_info[0].pNext = nullptr;
19120 submit_info[0].commandBufferCount = 1;
19121 submit_info[0].pCommandBuffers = &cmd_bufs[0];
19122 submit_info[0].signalSemaphoreCount = 1;
19123 submit_info[0].pSignalSemaphores = &semaphore1;
19124 submit_info[0].waitSemaphoreCount = 0;
19125 submit_info[0].pWaitDstStageMask = nullptr;
19126 submit_info[0].pWaitDstStageMask = flags;
19127 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19128 submit_info[1].pNext = nullptr;
19129 submit_info[1].commandBufferCount = 1;
19130 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19131 submit_info[1].waitSemaphoreCount = 1;
19132 submit_info[1].pWaitSemaphores = &semaphore1;
19133 submit_info[1].signalSemaphoreCount = 1;
19134 submit_info[1].pSignalSemaphores = &semaphore2;
19135 submit_info[1].pWaitDstStageMask = flags;
19136 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19137 submit_info[2].pNext = nullptr;
19138 submit_info[2].commandBufferCount = 2;
19139 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19140 submit_info[2].waitSemaphoreCount = 1;
19141 submit_info[2].pWaitSemaphores = &semaphore2;
19142 submit_info[2].signalSemaphoreCount = 0;
19143 submit_info[2].pSignalSemaphores = nullptr;
19144 submit_info[2].pWaitDstStageMask = flags;
19145 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19146 vkQueueWaitIdle(m_device->m_queue);
19147
19148 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19149 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19150 m_errorMonitor->VerifyNotFound();
19151}
19152
Tobin Ehlis953e8392016-11-17 10:54:13 -070019153TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19154 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19155 // We previously had a bug where dynamic offset of inactive bindings was still being used
19156 VkResult err;
19157 m_errorMonitor->ExpectSuccess();
19158
19159 ASSERT_NO_FATAL_FAILURE(InitState());
19160 ASSERT_NO_FATAL_FAILURE(InitViewport());
19161 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19162
19163 VkDescriptorPoolSize ds_type_count = {};
19164 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19165 ds_type_count.descriptorCount = 3;
19166
19167 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19168 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19169 ds_pool_ci.pNext = NULL;
19170 ds_pool_ci.maxSets = 1;
19171 ds_pool_ci.poolSizeCount = 1;
19172 ds_pool_ci.pPoolSizes = &ds_type_count;
19173
19174 VkDescriptorPool ds_pool;
19175 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19176 ASSERT_VK_SUCCESS(err);
19177
19178 const uint32_t BINDING_COUNT = 3;
19179 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019180 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019181 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19182 dsl_binding[0].descriptorCount = 1;
19183 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19184 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019185 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019186 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19187 dsl_binding[1].descriptorCount = 1;
19188 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19189 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019190 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019191 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19192 dsl_binding[2].descriptorCount = 1;
19193 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19194 dsl_binding[2].pImmutableSamplers = NULL;
19195
19196 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19197 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19198 ds_layout_ci.pNext = NULL;
19199 ds_layout_ci.bindingCount = BINDING_COUNT;
19200 ds_layout_ci.pBindings = dsl_binding;
19201 VkDescriptorSetLayout ds_layout;
19202 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19203 ASSERT_VK_SUCCESS(err);
19204
19205 VkDescriptorSet descriptor_set;
19206 VkDescriptorSetAllocateInfo alloc_info = {};
19207 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19208 alloc_info.descriptorSetCount = 1;
19209 alloc_info.descriptorPool = ds_pool;
19210 alloc_info.pSetLayouts = &ds_layout;
19211 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19212 ASSERT_VK_SUCCESS(err);
19213
19214 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19215 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19216 pipeline_layout_ci.pNext = NULL;
19217 pipeline_layout_ci.setLayoutCount = 1;
19218 pipeline_layout_ci.pSetLayouts = &ds_layout;
19219
19220 VkPipelineLayout pipeline_layout;
19221 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19222 ASSERT_VK_SUCCESS(err);
19223
19224 // Create two buffers to update the descriptors with
19225 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19226 uint32_t qfi = 0;
19227 VkBufferCreateInfo buffCI = {};
19228 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19229 buffCI.size = 2048;
19230 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19231 buffCI.queueFamilyIndexCount = 1;
19232 buffCI.pQueueFamilyIndices = &qfi;
19233
19234 VkBuffer dyub1;
19235 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19236 ASSERT_VK_SUCCESS(err);
19237 // buffer2
19238 buffCI.size = 1024;
19239 VkBuffer dyub2;
19240 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19241 ASSERT_VK_SUCCESS(err);
19242 // Allocate memory and bind to buffers
19243 VkMemoryAllocateInfo mem_alloc[2] = {};
19244 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19245 mem_alloc[0].pNext = NULL;
19246 mem_alloc[0].memoryTypeIndex = 0;
19247 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19248 mem_alloc[1].pNext = NULL;
19249 mem_alloc[1].memoryTypeIndex = 0;
19250
19251 VkMemoryRequirements mem_reqs1;
19252 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19253 VkMemoryRequirements mem_reqs2;
19254 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19255 mem_alloc[0].allocationSize = mem_reqs1.size;
19256 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19257 mem_alloc[1].allocationSize = mem_reqs2.size;
19258 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19259 if (!pass) {
19260 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19261 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19262 return;
19263 }
19264
19265 VkDeviceMemory mem1;
19266 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19267 ASSERT_VK_SUCCESS(err);
19268 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19269 ASSERT_VK_SUCCESS(err);
19270 VkDeviceMemory mem2;
19271 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19272 ASSERT_VK_SUCCESS(err);
19273 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19274 ASSERT_VK_SUCCESS(err);
19275 // Update descriptors
19276 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19277 buff_info[0].buffer = dyub1;
19278 buff_info[0].offset = 0;
19279 buff_info[0].range = 256;
19280 buff_info[1].buffer = dyub1;
19281 buff_info[1].offset = 256;
19282 buff_info[1].range = 512;
19283 buff_info[2].buffer = dyub2;
19284 buff_info[2].offset = 0;
19285 buff_info[2].range = 512;
19286
19287 VkWriteDescriptorSet descriptor_write;
19288 memset(&descriptor_write, 0, sizeof(descriptor_write));
19289 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19290 descriptor_write.dstSet = descriptor_set;
19291 descriptor_write.dstBinding = 0;
19292 descriptor_write.descriptorCount = BINDING_COUNT;
19293 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19294 descriptor_write.pBufferInfo = buff_info;
19295
19296 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19297
Tony Barbour552f6c02016-12-21 14:34:07 -070019298 m_commandBuffer->BeginCommandBuffer();
19299 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019300
19301 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019302 char const *vsSource =
19303 "#version 450\n"
19304 "\n"
19305 "out gl_PerVertex { \n"
19306 " vec4 gl_Position;\n"
19307 "};\n"
19308 "void main(){\n"
19309 " gl_Position = vec4(1);\n"
19310 "}\n";
19311 char const *fsSource =
19312 "#version 450\n"
19313 "\n"
19314 "layout(location=0) out vec4 x;\n"
19315 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19316 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19317 "void main(){\n"
19318 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19319 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019320 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19321 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19322 VkPipelineObj pipe(m_device);
19323 pipe.SetViewport(m_viewports);
19324 pipe.SetScissor(m_scissors);
19325 pipe.AddShader(&vs);
19326 pipe.AddShader(&fs);
19327 pipe.AddColorAttachment();
19328 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19329
19330 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19331 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19332 // we used to have a bug in this case.
19333 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19334 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19335 &descriptor_set, BINDING_COUNT, dyn_off);
19336 Draw(1, 0, 0, 0);
19337 m_errorMonitor->VerifyNotFound();
19338
19339 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19340 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19341 vkFreeMemory(m_device->device(), mem1, NULL);
19342 vkFreeMemory(m_device->device(), mem2, NULL);
19343
19344 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19345 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19346 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19347}
19348
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019349TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019350 TEST_DESCRIPTION(
19351 "Ensure that validations handling of non-coherent memory "
19352 "mapping while using VK_WHOLE_SIZE does not cause access "
19353 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019354 VkResult err;
19355 uint8_t *pData;
19356 ASSERT_NO_FATAL_FAILURE(InitState());
19357
19358 VkDeviceMemory mem;
19359 VkMemoryRequirements mem_reqs;
19360 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019361 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019362 VkMemoryAllocateInfo alloc_info = {};
19363 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19364 alloc_info.pNext = NULL;
19365 alloc_info.memoryTypeIndex = 0;
19366
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019367 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019368 alloc_info.allocationSize = allocation_size;
19369
19370 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19371 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 -070019372 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019373 if (!pass) {
19374 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019375 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19376 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019377 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019378 pass = m_device->phy().set_memory_type(
19379 mem_reqs.memoryTypeBits, &alloc_info,
19380 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19381 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019382 if (!pass) {
19383 return;
19384 }
19385 }
19386 }
19387
19388 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19389 ASSERT_VK_SUCCESS(err);
19390
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019391 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019392 m_errorMonitor->ExpectSuccess();
19393 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19394 ASSERT_VK_SUCCESS(err);
19395 VkMappedMemoryRange mmr = {};
19396 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19397 mmr.memory = mem;
19398 mmr.offset = 0;
19399 mmr.size = VK_WHOLE_SIZE;
19400 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19401 ASSERT_VK_SUCCESS(err);
19402 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19403 ASSERT_VK_SUCCESS(err);
19404 m_errorMonitor->VerifyNotFound();
19405 vkUnmapMemory(m_device->device(), mem);
19406
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019407 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019408 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019409 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019410 ASSERT_VK_SUCCESS(err);
19411 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19412 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019413 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019414 mmr.size = VK_WHOLE_SIZE;
19415 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19416 ASSERT_VK_SUCCESS(err);
19417 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19418 ASSERT_VK_SUCCESS(err);
19419 m_errorMonitor->VerifyNotFound();
19420 vkUnmapMemory(m_device->device(), mem);
19421
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019422 // Map with offset and size
19423 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019424 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019425 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019426 ASSERT_VK_SUCCESS(err);
19427 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19428 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019429 mmr.offset = 4 * atom_size;
19430 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019431 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19432 ASSERT_VK_SUCCESS(err);
19433 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19434 ASSERT_VK_SUCCESS(err);
19435 m_errorMonitor->VerifyNotFound();
19436 vkUnmapMemory(m_device->device(), mem);
19437
19438 // Map without offset and flush WHOLE_SIZE with two separate offsets
19439 m_errorMonitor->ExpectSuccess();
19440 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19441 ASSERT_VK_SUCCESS(err);
19442 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19443 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019444 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019445 mmr.size = VK_WHOLE_SIZE;
19446 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19447 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019448 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019449 mmr.size = VK_WHOLE_SIZE;
19450 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19451 ASSERT_VK_SUCCESS(err);
19452 m_errorMonitor->VerifyNotFound();
19453 vkUnmapMemory(m_device->device(), mem);
19454
19455 vkFreeMemory(m_device->device(), mem, NULL);
19456}
19457
19458// This is a positive test. We used to expect error in this case but spec now allows it
19459TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19460 m_errorMonitor->ExpectSuccess();
19461 vk_testing::Fence testFence;
19462 VkFenceCreateInfo fenceInfo = {};
19463 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19464 fenceInfo.pNext = NULL;
19465
19466 ASSERT_NO_FATAL_FAILURE(InitState());
19467 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019468 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019469 VkResult result = vkResetFences(m_device->device(), 1, fences);
19470 ASSERT_VK_SUCCESS(result);
19471
19472 m_errorMonitor->VerifyNotFound();
19473}
19474
19475TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19476 m_errorMonitor->ExpectSuccess();
19477
19478 ASSERT_NO_FATAL_FAILURE(InitState());
19479 VkResult err;
19480
19481 // Record (empty!) command buffer that can be submitted multiple times
19482 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019483 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19484 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019485 m_commandBuffer->BeginCommandBuffer(&cbbi);
19486 m_commandBuffer->EndCommandBuffer();
19487
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019488 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019489 VkFence fence;
19490 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19491 ASSERT_VK_SUCCESS(err);
19492
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019493 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019494 VkSemaphore s1, s2;
19495 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19496 ASSERT_VK_SUCCESS(err);
19497 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19498 ASSERT_VK_SUCCESS(err);
19499
19500 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019501 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019502 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19503 ASSERT_VK_SUCCESS(err);
19504
19505 // Submit CB again, signaling s2.
19506 si.pSignalSemaphores = &s2;
19507 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19508 ASSERT_VK_SUCCESS(err);
19509
19510 // Wait for fence.
19511 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19512 ASSERT_VK_SUCCESS(err);
19513
19514 // CB is still in flight from second submission, but semaphore s1 is no
19515 // longer in flight. delete it.
19516 vkDestroySemaphore(m_device->device(), s1, nullptr);
19517
19518 m_errorMonitor->VerifyNotFound();
19519
19520 // Force device idle and clean up remaining objects
19521 vkDeviceWaitIdle(m_device->device());
19522 vkDestroySemaphore(m_device->device(), s2, nullptr);
19523 vkDestroyFence(m_device->device(), fence, nullptr);
19524}
19525
19526TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19527 m_errorMonitor->ExpectSuccess();
19528
19529 ASSERT_NO_FATAL_FAILURE(InitState());
19530 VkResult err;
19531
19532 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019533 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019534 VkFence f1;
19535 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19536 ASSERT_VK_SUCCESS(err);
19537
19538 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019539 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019540 VkFence f2;
19541 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19542 ASSERT_VK_SUCCESS(err);
19543
19544 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019545 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019546 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19547
19548 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019549 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019550 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19551
19552 // Should have both retired!
19553 vkDestroyFence(m_device->device(), f1, nullptr);
19554 vkDestroyFence(m_device->device(), f2, nullptr);
19555
19556 m_errorMonitor->VerifyNotFound();
19557}
19558
19559TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019560 TEST_DESCRIPTION(
19561 "Verify that creating an image view from an image with valid usage "
19562 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019563
19564 ASSERT_NO_FATAL_FAILURE(InitState());
19565
19566 m_errorMonitor->ExpectSuccess();
19567 // Verify that we can create a view with usage INPUT_ATTACHMENT
19568 VkImageObj image(m_device);
19569 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19570 ASSERT_TRUE(image.initialized());
19571 VkImageView imageView;
19572 VkImageViewCreateInfo ivci = {};
19573 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19574 ivci.image = image.handle();
19575 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19576 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19577 ivci.subresourceRange.layerCount = 1;
19578 ivci.subresourceRange.baseMipLevel = 0;
19579 ivci.subresourceRange.levelCount = 1;
19580 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19581
19582 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19583 m_errorMonitor->VerifyNotFound();
19584 vkDestroyImageView(m_device->device(), imageView, NULL);
19585}
19586
19587// This is a positive test. No failures are expected.
19588TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019589 TEST_DESCRIPTION(
19590 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19591 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019592
19593 ASSERT_NO_FATAL_FAILURE(InitState());
19594
19595 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019596 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019597
19598 m_errorMonitor->ExpectSuccess();
19599
19600 VkImage image;
19601 VkImageCreateInfo image_create_info = {};
19602 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19603 image_create_info.pNext = NULL;
19604 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19605 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19606 image_create_info.extent.width = 64;
19607 image_create_info.extent.height = 64;
19608 image_create_info.extent.depth = 1;
19609 image_create_info.mipLevels = 1;
19610 image_create_info.arrayLayers = 1;
19611 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19612 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19613 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19614 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19615 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19616 ASSERT_VK_SUCCESS(err);
19617
19618 VkMemoryRequirements memory_reqs;
19619 VkDeviceMemory memory_one, memory_two;
19620 bool pass;
19621 VkMemoryAllocateInfo memory_info = {};
19622 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19623 memory_info.pNext = NULL;
19624 memory_info.allocationSize = 0;
19625 memory_info.memoryTypeIndex = 0;
19626 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19627 // Find an image big enough to allow sparse mapping of 2 memory regions
19628 // Increase the image size until it is at least twice the
19629 // size of the required alignment, to ensure we can bind both
19630 // allocated memory blocks to the image on aligned offsets.
19631 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19632 vkDestroyImage(m_device->device(), image, nullptr);
19633 image_create_info.extent.width *= 2;
19634 image_create_info.extent.height *= 2;
19635 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19636 ASSERT_VK_SUCCESS(err);
19637 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19638 }
19639 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19640 // at the end of the first
19641 memory_info.allocationSize = memory_reqs.alignment;
19642 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19643 ASSERT_TRUE(pass);
19644 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19645 ASSERT_VK_SUCCESS(err);
19646 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19647 ASSERT_VK_SUCCESS(err);
19648 VkSparseMemoryBind binds[2];
19649 binds[0].flags = 0;
19650 binds[0].memory = memory_one;
19651 binds[0].memoryOffset = 0;
19652 binds[0].resourceOffset = 0;
19653 binds[0].size = memory_info.allocationSize;
19654 binds[1].flags = 0;
19655 binds[1].memory = memory_two;
19656 binds[1].memoryOffset = 0;
19657 binds[1].resourceOffset = memory_info.allocationSize;
19658 binds[1].size = memory_info.allocationSize;
19659
19660 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19661 opaqueBindInfo.image = image;
19662 opaqueBindInfo.bindCount = 2;
19663 opaqueBindInfo.pBinds = binds;
19664
19665 VkFence fence = VK_NULL_HANDLE;
19666 VkBindSparseInfo bindSparseInfo = {};
19667 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19668 bindSparseInfo.imageOpaqueBindCount = 1;
19669 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19670
19671 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19672 vkQueueWaitIdle(m_device->m_queue);
19673 vkDestroyImage(m_device->device(), image, NULL);
19674 vkFreeMemory(m_device->device(), memory_one, NULL);
19675 vkFreeMemory(m_device->device(), memory_two, NULL);
19676 m_errorMonitor->VerifyNotFound();
19677}
19678
19679TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019680 TEST_DESCRIPTION(
19681 "Ensure that CmdBeginRenderPass with an attachment's "
19682 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19683 "the command buffer has prior knowledge of that "
19684 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019685
19686 m_errorMonitor->ExpectSuccess();
19687
19688 ASSERT_NO_FATAL_FAILURE(InitState());
19689
19690 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019691 VkAttachmentDescription attachment = {0,
19692 VK_FORMAT_R8G8B8A8_UNORM,
19693 VK_SAMPLE_COUNT_1_BIT,
19694 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19695 VK_ATTACHMENT_STORE_OP_STORE,
19696 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19697 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19698 VK_IMAGE_LAYOUT_UNDEFINED,
19699 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019700
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019701 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019702
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019703 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019704
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019705 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019706
19707 VkRenderPass rp;
19708 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19709 ASSERT_VK_SUCCESS(err);
19710
19711 // A compatible framebuffer.
19712 VkImageObj image(m_device);
19713 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19714 ASSERT_TRUE(image.initialized());
19715
19716 VkImageViewCreateInfo ivci = {
19717 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19718 nullptr,
19719 0,
19720 image.handle(),
19721 VK_IMAGE_VIEW_TYPE_2D,
19722 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019723 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19724 VK_COMPONENT_SWIZZLE_IDENTITY},
19725 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019726 };
19727 VkImageView view;
19728 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19729 ASSERT_VK_SUCCESS(err);
19730
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019731 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019732 VkFramebuffer fb;
19733 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19734 ASSERT_VK_SUCCESS(err);
19735
19736 // Record a single command buffer which uses this renderpass twice. The
19737 // bug is triggered at the beginning of the second renderpass, when the
19738 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019739 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 -070019740 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019741 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19742 vkCmdEndRenderPass(m_commandBuffer->handle());
19743 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19744
19745 m_errorMonitor->VerifyNotFound();
19746
19747 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019748 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019749
19750 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19751 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19752 vkDestroyImageView(m_device->device(), view, nullptr);
19753}
19754
19755TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019756 TEST_DESCRIPTION(
19757 "This test should pass. Create a Framebuffer and "
19758 "command buffer, bind them together, then destroy "
19759 "command pool and framebuffer and verify there are no "
19760 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019761
19762 m_errorMonitor->ExpectSuccess();
19763
19764 ASSERT_NO_FATAL_FAILURE(InitState());
19765
19766 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019767 VkAttachmentDescription attachment = {0,
19768 VK_FORMAT_R8G8B8A8_UNORM,
19769 VK_SAMPLE_COUNT_1_BIT,
19770 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19771 VK_ATTACHMENT_STORE_OP_STORE,
19772 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19773 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19774 VK_IMAGE_LAYOUT_UNDEFINED,
19775 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019776
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019777 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019778
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019779 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019780
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019781 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019782
19783 VkRenderPass rp;
19784 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19785 ASSERT_VK_SUCCESS(err);
19786
19787 // A compatible framebuffer.
19788 VkImageObj image(m_device);
19789 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19790 ASSERT_TRUE(image.initialized());
19791
19792 VkImageViewCreateInfo ivci = {
19793 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19794 nullptr,
19795 0,
19796 image.handle(),
19797 VK_IMAGE_VIEW_TYPE_2D,
19798 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019799 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19800 VK_COMPONENT_SWIZZLE_IDENTITY},
19801 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019802 };
19803 VkImageView view;
19804 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19805 ASSERT_VK_SUCCESS(err);
19806
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019807 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019808 VkFramebuffer fb;
19809 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19810 ASSERT_VK_SUCCESS(err);
19811
19812 // Explicitly create a command buffer to bind the FB to so that we can then
19813 // destroy the command pool in order to implicitly free command buffer
19814 VkCommandPool command_pool;
19815 VkCommandPoolCreateInfo pool_create_info{};
19816 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19817 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19818 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19819 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19820
19821 VkCommandBuffer command_buffer;
19822 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19823 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19824 command_buffer_allocate_info.commandPool = command_pool;
19825 command_buffer_allocate_info.commandBufferCount = 1;
19826 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19827 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19828
19829 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019830 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 -060019831 VkCommandBufferBeginInfo begin_info{};
19832 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19833 vkBeginCommandBuffer(command_buffer, &begin_info);
19834
19835 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19836 vkCmdEndRenderPass(command_buffer);
19837 vkEndCommandBuffer(command_buffer);
19838 vkDestroyImageView(m_device->device(), view, nullptr);
19839 // Destroy command pool to implicitly free command buffer
19840 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19841 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19842 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19843 m_errorMonitor->VerifyNotFound();
19844}
19845
19846TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019847 TEST_DESCRIPTION(
19848 "Ensure that CmdBeginRenderPass applies the layout "
19849 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019850
19851 m_errorMonitor->ExpectSuccess();
19852
19853 ASSERT_NO_FATAL_FAILURE(InitState());
19854
19855 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019856 VkAttachmentDescription attachment = {0,
19857 VK_FORMAT_R8G8B8A8_UNORM,
19858 VK_SAMPLE_COUNT_1_BIT,
19859 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19860 VK_ATTACHMENT_STORE_OP_STORE,
19861 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19862 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19863 VK_IMAGE_LAYOUT_UNDEFINED,
19864 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019865
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019866 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019867
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019868 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019869
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019870 VkSubpassDependency dep = {0,
19871 0,
19872 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19873 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19874 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19875 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19876 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019877
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019878 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019879
19880 VkResult err;
19881 VkRenderPass rp;
19882 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19883 ASSERT_VK_SUCCESS(err);
19884
19885 // A compatible framebuffer.
19886 VkImageObj image(m_device);
19887 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19888 ASSERT_TRUE(image.initialized());
19889
19890 VkImageViewCreateInfo ivci = {
19891 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19892 nullptr,
19893 0,
19894 image.handle(),
19895 VK_IMAGE_VIEW_TYPE_2D,
19896 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019897 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19898 VK_COMPONENT_SWIZZLE_IDENTITY},
19899 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019900 };
19901 VkImageView view;
19902 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19903 ASSERT_VK_SUCCESS(err);
19904
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019905 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019906 VkFramebuffer fb;
19907 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19908 ASSERT_VK_SUCCESS(err);
19909
19910 // Record a single command buffer which issues a pipeline barrier w/
19911 // image memory barrier for the attachment. This detects the previously
19912 // missing tracking of the subpass layout by throwing a validation error
19913 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019914 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 -070019915 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019916 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19917
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019918 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19919 nullptr,
19920 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19921 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19922 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19923 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19924 VK_QUEUE_FAMILY_IGNORED,
19925 VK_QUEUE_FAMILY_IGNORED,
19926 image.handle(),
19927 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019928 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019929 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19930 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019931
19932 vkCmdEndRenderPass(m_commandBuffer->handle());
19933 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019934 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019935
19936 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19937 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19938 vkDestroyImageView(m_device->device(), view, nullptr);
19939}
19940
19941TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019942 TEST_DESCRIPTION(
19943 "Validate that when an imageView of a depth/stencil image "
19944 "is used as a depth/stencil framebuffer attachment, the "
19945 "aspectMask is ignored and both depth and stencil image "
19946 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019947
19948 VkFormatProperties format_properties;
19949 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19950 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19951 return;
19952 }
19953
19954 m_errorMonitor->ExpectSuccess();
19955
19956 ASSERT_NO_FATAL_FAILURE(InitState());
19957
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019958 VkAttachmentDescription attachment = {0,
19959 VK_FORMAT_D32_SFLOAT_S8_UINT,
19960 VK_SAMPLE_COUNT_1_BIT,
19961 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19962 VK_ATTACHMENT_STORE_OP_STORE,
19963 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19964 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19965 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19966 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019967
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019968 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019969
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019970 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019971
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019972 VkSubpassDependency dep = {0,
19973 0,
19974 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19975 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19976 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19977 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19978 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019979
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019980 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019981
19982 VkResult err;
19983 VkRenderPass rp;
19984 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19985 ASSERT_VK_SUCCESS(err);
19986
19987 VkImageObj image(m_device);
19988 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019989 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019990 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019991 ASSERT_TRUE(image.initialized());
19992 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19993
19994 VkImageViewCreateInfo ivci = {
19995 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19996 nullptr,
19997 0,
19998 image.handle(),
19999 VK_IMAGE_VIEW_TYPE_2D,
20000 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020001 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
20002 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020003 };
20004 VkImageView view;
20005 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
20006 ASSERT_VK_SUCCESS(err);
20007
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020008 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020009 VkFramebuffer fb;
20010 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20011 ASSERT_VK_SUCCESS(err);
20012
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020013 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 -070020014 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020015 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20016
20017 VkImageMemoryBarrier imb = {};
20018 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20019 imb.pNext = nullptr;
20020 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20021 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20022 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20023 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
20024 imb.srcQueueFamilyIndex = 0;
20025 imb.dstQueueFamilyIndex = 0;
20026 imb.image = image.handle();
20027 imb.subresourceRange.aspectMask = 0x6;
20028 imb.subresourceRange.baseMipLevel = 0;
20029 imb.subresourceRange.levelCount = 0x1;
20030 imb.subresourceRange.baseArrayLayer = 0;
20031 imb.subresourceRange.layerCount = 0x1;
20032
20033 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020034 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
20035 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020036
20037 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070020038 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020039 QueueCommandBuffer(false);
20040 m_errorMonitor->VerifyNotFound();
20041
20042 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20043 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20044 vkDestroyImageView(m_device->device(), view, nullptr);
20045}
20046
20047TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020048 TEST_DESCRIPTION(
20049 "Ensure that layout transitions work correctly without "
20050 "errors, when an attachment reference is "
20051 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020052
20053 m_errorMonitor->ExpectSuccess();
20054
20055 ASSERT_NO_FATAL_FAILURE(InitState());
20056
20057 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020058 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020059
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020060 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020061
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020062 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020063
20064 VkRenderPass rp;
20065 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
20066 ASSERT_VK_SUCCESS(err);
20067
20068 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020069 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020070 VkFramebuffer fb;
20071 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
20072 ASSERT_VK_SUCCESS(err);
20073
20074 // Record a command buffer which just begins and ends the renderpass. The
20075 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020076 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 -070020077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020078 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
20079 vkCmdEndRenderPass(m_commandBuffer->handle());
20080 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070020081 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020082
20083 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20084 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20085}
20086
20087// This is a positive test. No errors are expected.
20088TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020089 TEST_DESCRIPTION(
20090 "Create a stencil-only attachment with a LOAD_OP set to "
20091 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020092 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070020093 ASSERT_NO_FATAL_FAILURE(InitState());
20094 auto depth_format = find_depth_stencil_format(m_device);
20095 if (!depth_format) {
20096 printf(" No Depth + Stencil format found. Skipped.\n");
20097 return;
20098 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020099 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070020100 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020101 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
20102 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020103 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
20104 return;
20105 }
20106
Tony Barbourf887b162017-03-09 10:06:46 -070020107 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020108 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020109 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020110 VkAttachmentDescription att = {};
20111 VkAttachmentReference ref = {};
20112 att.format = depth_stencil_fmt;
20113 att.samples = VK_SAMPLE_COUNT_1_BIT;
20114 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
20115 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20116 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20117 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
20118 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20119 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20120
20121 VkClearValue clear;
20122 clear.depthStencil.depth = 1.0;
20123 clear.depthStencil.stencil = 0;
20124 ref.attachment = 0;
20125 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20126
20127 VkSubpassDescription subpass = {};
20128 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20129 subpass.flags = 0;
20130 subpass.inputAttachmentCount = 0;
20131 subpass.pInputAttachments = NULL;
20132 subpass.colorAttachmentCount = 0;
20133 subpass.pColorAttachments = NULL;
20134 subpass.pResolveAttachments = NULL;
20135 subpass.pDepthStencilAttachment = &ref;
20136 subpass.preserveAttachmentCount = 0;
20137 subpass.pPreserveAttachments = NULL;
20138
20139 VkRenderPass rp;
20140 VkRenderPassCreateInfo rp_info = {};
20141 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20142 rp_info.attachmentCount = 1;
20143 rp_info.pAttachments = &att;
20144 rp_info.subpassCount = 1;
20145 rp_info.pSubpasses = &subpass;
20146 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20147 ASSERT_VK_SUCCESS(result);
20148
20149 VkImageView *depthView = m_depthStencil->BindInfo();
20150 VkFramebufferCreateInfo fb_info = {};
20151 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20152 fb_info.pNext = NULL;
20153 fb_info.renderPass = rp;
20154 fb_info.attachmentCount = 1;
20155 fb_info.pAttachments = depthView;
20156 fb_info.width = 100;
20157 fb_info.height = 100;
20158 fb_info.layers = 1;
20159 VkFramebuffer fb;
20160 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20161 ASSERT_VK_SUCCESS(result);
20162
20163 VkRenderPassBeginInfo rpbinfo = {};
20164 rpbinfo.clearValueCount = 1;
20165 rpbinfo.pClearValues = &clear;
20166 rpbinfo.pNext = NULL;
20167 rpbinfo.renderPass = rp;
20168 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20169 rpbinfo.renderArea.extent.width = 100;
20170 rpbinfo.renderArea.extent.height = 100;
20171 rpbinfo.renderArea.offset.x = 0;
20172 rpbinfo.renderArea.offset.y = 0;
20173 rpbinfo.framebuffer = fb;
20174
20175 VkFence fence = {};
20176 VkFenceCreateInfo fence_ci = {};
20177 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20178 fence_ci.pNext = nullptr;
20179 fence_ci.flags = 0;
20180 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20181 ASSERT_VK_SUCCESS(result);
20182
20183 m_commandBuffer->BeginCommandBuffer();
20184 m_commandBuffer->BeginRenderPass(rpbinfo);
20185 m_commandBuffer->EndRenderPass();
20186 m_commandBuffer->EndCommandBuffer();
20187 m_commandBuffer->QueueCommandBuffer(fence);
20188
20189 VkImageObj destImage(m_device);
20190 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 -070020191 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020192 VkImageMemoryBarrier barrier = {};
20193 VkImageSubresourceRange range;
20194 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20195 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20196 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20197 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20198 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20199 barrier.image = m_depthStencil->handle();
20200 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20201 range.baseMipLevel = 0;
20202 range.levelCount = 1;
20203 range.baseArrayLayer = 0;
20204 range.layerCount = 1;
20205 barrier.subresourceRange = range;
20206 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20207 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20208 cmdbuf.BeginCommandBuffer();
20209 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 -070020210 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020211 barrier.srcAccessMask = 0;
20212 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20213 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20214 barrier.image = destImage.handle();
20215 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20216 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 -070020217 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020218 VkImageCopy cregion;
20219 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20220 cregion.srcSubresource.mipLevel = 0;
20221 cregion.srcSubresource.baseArrayLayer = 0;
20222 cregion.srcSubresource.layerCount = 1;
20223 cregion.srcOffset.x = 0;
20224 cregion.srcOffset.y = 0;
20225 cregion.srcOffset.z = 0;
20226 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20227 cregion.dstSubresource.mipLevel = 0;
20228 cregion.dstSubresource.baseArrayLayer = 0;
20229 cregion.dstSubresource.layerCount = 1;
20230 cregion.dstOffset.x = 0;
20231 cregion.dstOffset.y = 0;
20232 cregion.dstOffset.z = 0;
20233 cregion.extent.width = 100;
20234 cregion.extent.height = 100;
20235 cregion.extent.depth = 1;
20236 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020237 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020238 cmdbuf.EndCommandBuffer();
20239
20240 VkSubmitInfo submit_info;
20241 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20242 submit_info.pNext = NULL;
20243 submit_info.waitSemaphoreCount = 0;
20244 submit_info.pWaitSemaphores = NULL;
20245 submit_info.pWaitDstStageMask = NULL;
20246 submit_info.commandBufferCount = 1;
20247 submit_info.pCommandBuffers = &cmdbuf.handle();
20248 submit_info.signalSemaphoreCount = 0;
20249 submit_info.pSignalSemaphores = NULL;
20250
20251 m_errorMonitor->ExpectSuccess();
20252 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20253 m_errorMonitor->VerifyNotFound();
20254
20255 vkQueueWaitIdle(m_device->m_queue);
20256 vkDestroyFence(m_device->device(), fence, nullptr);
20257 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20258 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20259}
20260
20261// This is a positive test. No errors should be generated.
Mike Weiblene4e225d2017-03-07 23:15:43 -070020262TEST_F(VkPositiveLayerTest, BarrierLayoutToImageUsage) {
20263 TEST_DESCRIPTION("Ensure barriers' new and old VkImageLayout are compatible with their images' VkImageUsageFlags");
20264
20265 m_errorMonitor->ExpectSuccess();
20266
20267 ASSERT_NO_FATAL_FAILURE(InitState());
20268 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
20269
20270 VkImageMemoryBarrier img_barrier = {};
20271 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20272 img_barrier.pNext = NULL;
20273 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
20274 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
20275 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20276 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
20277 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20278 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
20279 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
20280 img_barrier.subresourceRange.baseArrayLayer = 0;
20281 img_barrier.subresourceRange.baseMipLevel = 0;
20282 img_barrier.subresourceRange.layerCount = 1;
20283 img_barrier.subresourceRange.levelCount = 1;
20284
20285 {
20286 VkImageObj img_color(m_device);
20287 img_color.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20288 ASSERT_TRUE(img_color.initialized());
20289
20290 VkImageObj img_ds1(m_device);
20291 img_ds1.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20292 ASSERT_TRUE(img_ds1.initialized());
20293
20294 VkImageObj img_ds2(m_device);
20295 img_ds2.init(128, 128, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20296 ASSERT_TRUE(img_ds2.initialized());
20297
20298 VkImageObj img_xfer_src(m_device);
20299 img_xfer_src.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL);
20300 ASSERT_TRUE(img_xfer_src.initialized());
20301
20302 VkImageObj img_xfer_dst(m_device);
20303 img_xfer_dst.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_OPTIMAL);
20304 ASSERT_TRUE(img_xfer_dst.initialized());
20305
20306 VkImageObj img_sampled(m_device);
20307 img_sampled.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL);
20308 ASSERT_TRUE(img_sampled.initialized());
20309
20310 VkImageObj img_input(m_device);
20311 img_input.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL);
20312 ASSERT_TRUE(img_input.initialized());
20313
20314 const struct {
20315 VkImageObj &image_obj;
20316 VkImageLayout old_layout;
20317 VkImageLayout new_layout;
20318 } buffer_layouts[] = {
20319 // clang-format off
20320 {img_color, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20321 {img_ds1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20322 {img_ds2, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20323 {img_sampled, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20324 {img_input, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20325 {img_xfer_src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20326 {img_xfer_dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_GENERAL},
20327 // clang-format on
20328 };
20329 const uint32_t layout_count = sizeof(buffer_layouts) / sizeof(buffer_layouts[0]);
20330
20331 m_commandBuffer->BeginCommandBuffer();
20332 for (uint32_t i = 0; i < layout_count; ++i) {
20333 img_barrier.image = buffer_layouts[i].image_obj.handle();
20334 const VkImageUsageFlags usage = buffer_layouts[i].image_obj.usage();
20335 img_barrier.subresourceRange.aspectMask = (usage == VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)
20336 ? (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)
20337 : VK_IMAGE_ASPECT_COLOR_BIT;
20338
20339 img_barrier.oldLayout = buffer_layouts[i].old_layout;
20340 img_barrier.newLayout = buffer_layouts[i].new_layout;
20341 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20342 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20343
20344 img_barrier.oldLayout = buffer_layouts[i].new_layout;
20345 img_barrier.newLayout = buffer_layouts[i].old_layout;
20346 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT,
20347 VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0, nullptr, 1, &img_barrier);
20348 }
20349 m_commandBuffer->EndCommandBuffer();
20350
20351 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
20352 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
20353 }
20354 m_errorMonitor->VerifyNotFound();
20355}
20356
20357// This is a positive test. No errors should be generated.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020358TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20359 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20360
20361 m_errorMonitor->ExpectSuccess();
20362 ASSERT_NO_FATAL_FAILURE(InitState());
20363
20364 VkEvent event;
20365 VkEventCreateInfo event_create_info{};
20366 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20367 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20368
20369 VkCommandPool command_pool;
20370 VkCommandPoolCreateInfo pool_create_info{};
20371 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20372 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20373 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20374 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20375
20376 VkCommandBuffer command_buffer;
20377 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20378 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20379 command_buffer_allocate_info.commandPool = command_pool;
20380 command_buffer_allocate_info.commandBufferCount = 1;
20381 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20382 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20383
20384 VkQueue queue = VK_NULL_HANDLE;
20385 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20386
20387 {
20388 VkCommandBufferBeginInfo begin_info{};
20389 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20390 vkBeginCommandBuffer(command_buffer, &begin_info);
20391
20392 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 -070020393 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020394 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20395 vkEndCommandBuffer(command_buffer);
20396 }
20397 {
20398 VkSubmitInfo submit_info{};
20399 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20400 submit_info.commandBufferCount = 1;
20401 submit_info.pCommandBuffers = &command_buffer;
20402 submit_info.signalSemaphoreCount = 0;
20403 submit_info.pSignalSemaphores = nullptr;
20404 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20405 }
20406 { vkSetEvent(m_device->device(), event); }
20407
20408 vkQueueWaitIdle(queue);
20409
20410 vkDestroyEvent(m_device->device(), event, nullptr);
20411 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20412 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20413
20414 m_errorMonitor->VerifyNotFound();
20415}
20416// This is a positive test. No errors should be generated.
20417TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20418 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20419
20420 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020421 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020422
20423 m_errorMonitor->ExpectSuccess();
20424
20425 VkQueryPool query_pool;
20426 VkQueryPoolCreateInfo query_pool_create_info{};
20427 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20428 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20429 query_pool_create_info.queryCount = 1;
20430 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20431
20432 VkCommandPool command_pool;
20433 VkCommandPoolCreateInfo pool_create_info{};
20434 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20435 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20436 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20437 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20438
20439 VkCommandBuffer command_buffer;
20440 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20441 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20442 command_buffer_allocate_info.commandPool = command_pool;
20443 command_buffer_allocate_info.commandBufferCount = 1;
20444 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20445 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20446
20447 VkCommandBuffer secondary_command_buffer;
20448 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20449 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20450
20451 VkQueue queue = VK_NULL_HANDLE;
20452 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20453
20454 uint32_t qfi = 0;
20455 VkBufferCreateInfo buff_create_info = {};
20456 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20457 buff_create_info.size = 1024;
20458 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20459 buff_create_info.queueFamilyIndexCount = 1;
20460 buff_create_info.pQueueFamilyIndices = &qfi;
20461
20462 VkResult err;
20463 VkBuffer buffer;
20464 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20465 ASSERT_VK_SUCCESS(err);
20466 VkMemoryAllocateInfo mem_alloc = {};
20467 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20468 mem_alloc.pNext = NULL;
20469 mem_alloc.allocationSize = 1024;
20470 mem_alloc.memoryTypeIndex = 0;
20471
20472 VkMemoryRequirements memReqs;
20473 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20474 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20475 if (!pass) {
20476 vkDestroyBuffer(m_device->device(), buffer, NULL);
20477 return;
20478 }
20479
20480 VkDeviceMemory mem;
20481 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20482 ASSERT_VK_SUCCESS(err);
20483 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20484 ASSERT_VK_SUCCESS(err);
20485
20486 VkCommandBufferInheritanceInfo hinfo = {};
20487 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20488 hinfo.renderPass = VK_NULL_HANDLE;
20489 hinfo.subpass = 0;
20490 hinfo.framebuffer = VK_NULL_HANDLE;
20491 hinfo.occlusionQueryEnable = VK_FALSE;
20492 hinfo.queryFlags = 0;
20493 hinfo.pipelineStatistics = 0;
20494
20495 {
20496 VkCommandBufferBeginInfo begin_info{};
20497 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20498 begin_info.pInheritanceInfo = &hinfo;
20499 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20500
20501 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20502 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20503
20504 vkEndCommandBuffer(secondary_command_buffer);
20505
20506 begin_info.pInheritanceInfo = nullptr;
20507 vkBeginCommandBuffer(command_buffer, &begin_info);
20508
20509 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20510 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20511
20512 vkEndCommandBuffer(command_buffer);
20513 }
20514 {
20515 VkSubmitInfo submit_info{};
20516 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20517 submit_info.commandBufferCount = 1;
20518 submit_info.pCommandBuffers = &command_buffer;
20519 submit_info.signalSemaphoreCount = 0;
20520 submit_info.pSignalSemaphores = nullptr;
20521 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20522 }
20523
20524 vkQueueWaitIdle(queue);
20525
20526 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20527 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20528 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20529 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20530 vkDestroyBuffer(m_device->device(), buffer, NULL);
20531 vkFreeMemory(m_device->device(), mem, NULL);
20532
20533 m_errorMonitor->VerifyNotFound();
20534}
20535
20536// This is a positive test. No errors should be generated.
20537TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20538 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20539
20540 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020541 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020542
20543 m_errorMonitor->ExpectSuccess();
20544
20545 VkQueryPool query_pool;
20546 VkQueryPoolCreateInfo query_pool_create_info{};
20547 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20548 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20549 query_pool_create_info.queryCount = 1;
20550 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20551
20552 VkCommandPool command_pool;
20553 VkCommandPoolCreateInfo pool_create_info{};
20554 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20555 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20556 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20557 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20558
20559 VkCommandBuffer command_buffer[2];
20560 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20561 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20562 command_buffer_allocate_info.commandPool = command_pool;
20563 command_buffer_allocate_info.commandBufferCount = 2;
20564 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20565 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20566
20567 VkQueue queue = VK_NULL_HANDLE;
20568 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20569
20570 uint32_t qfi = 0;
20571 VkBufferCreateInfo buff_create_info = {};
20572 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20573 buff_create_info.size = 1024;
20574 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20575 buff_create_info.queueFamilyIndexCount = 1;
20576 buff_create_info.pQueueFamilyIndices = &qfi;
20577
20578 VkResult err;
20579 VkBuffer buffer;
20580 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20581 ASSERT_VK_SUCCESS(err);
20582 VkMemoryAllocateInfo mem_alloc = {};
20583 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20584 mem_alloc.pNext = NULL;
20585 mem_alloc.allocationSize = 1024;
20586 mem_alloc.memoryTypeIndex = 0;
20587
20588 VkMemoryRequirements memReqs;
20589 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20590 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20591 if (!pass) {
20592 vkDestroyBuffer(m_device->device(), buffer, NULL);
20593 return;
20594 }
20595
20596 VkDeviceMemory mem;
20597 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20598 ASSERT_VK_SUCCESS(err);
20599 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20600 ASSERT_VK_SUCCESS(err);
20601
20602 {
20603 VkCommandBufferBeginInfo begin_info{};
20604 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20605 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20606
20607 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20608 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20609
20610 vkEndCommandBuffer(command_buffer[0]);
20611
20612 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20613
20614 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20615
20616 vkEndCommandBuffer(command_buffer[1]);
20617 }
20618 {
20619 VkSubmitInfo submit_info{};
20620 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20621 submit_info.commandBufferCount = 2;
20622 submit_info.pCommandBuffers = command_buffer;
20623 submit_info.signalSemaphoreCount = 0;
20624 submit_info.pSignalSemaphores = nullptr;
20625 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20626 }
20627
20628 vkQueueWaitIdle(queue);
20629
20630 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20631 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20632 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20633 vkDestroyBuffer(m_device->device(), buffer, NULL);
20634 vkFreeMemory(m_device->device(), mem, NULL);
20635
20636 m_errorMonitor->VerifyNotFound();
20637}
20638
Tony Barbourc46924f2016-11-04 11:49:52 -060020639TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020640 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20641
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020642 ASSERT_NO_FATAL_FAILURE(InitState());
20643 VkEvent event;
20644 VkEventCreateInfo event_create_info{};
20645 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20646 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20647
20648 VkCommandPool command_pool;
20649 VkCommandPoolCreateInfo pool_create_info{};
20650 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20651 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20652 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20653 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20654
20655 VkCommandBuffer command_buffer;
20656 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20657 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20658 command_buffer_allocate_info.commandPool = command_pool;
20659 command_buffer_allocate_info.commandBufferCount = 1;
20660 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20661 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20662
20663 VkQueue queue = VK_NULL_HANDLE;
20664 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20665
20666 {
20667 VkCommandBufferBeginInfo begin_info{};
20668 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20669 vkBeginCommandBuffer(command_buffer, &begin_info);
20670
20671 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020672 vkEndCommandBuffer(command_buffer);
20673 }
20674 {
20675 VkSubmitInfo submit_info{};
20676 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20677 submit_info.commandBufferCount = 1;
20678 submit_info.pCommandBuffers = &command_buffer;
20679 submit_info.signalSemaphoreCount = 0;
20680 submit_info.pSignalSemaphores = nullptr;
20681 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20682 }
20683 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20685 "that is already in use by a "
20686 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020687 vkSetEvent(m_device->device(), event);
20688 m_errorMonitor->VerifyFound();
20689 }
20690
20691 vkQueueWaitIdle(queue);
20692
20693 vkDestroyEvent(m_device->device(), event, nullptr);
20694 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20695 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20696}
20697
20698// This is a positive test. No errors should be generated.
20699TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020700 TEST_DESCRIPTION(
20701 "Two command buffers with two separate fences are each "
20702 "run through a Submit & WaitForFences cycle 3 times. This "
20703 "previously revealed a bug so running this positive test "
20704 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020705 m_errorMonitor->ExpectSuccess();
20706
20707 ASSERT_NO_FATAL_FAILURE(InitState());
20708 VkQueue queue = VK_NULL_HANDLE;
20709 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20710
20711 static const uint32_t NUM_OBJECTS = 2;
20712 static const uint32_t NUM_FRAMES = 3;
20713 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20714 VkFence fences[NUM_OBJECTS] = {};
20715
20716 VkCommandPool cmd_pool;
20717 VkCommandPoolCreateInfo cmd_pool_ci = {};
20718 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20719 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20720 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20721 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20722 ASSERT_VK_SUCCESS(err);
20723
20724 VkCommandBufferAllocateInfo cmd_buf_info = {};
20725 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20726 cmd_buf_info.commandPool = cmd_pool;
20727 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20728 cmd_buf_info.commandBufferCount = 1;
20729
20730 VkFenceCreateInfo fence_ci = {};
20731 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20732 fence_ci.pNext = nullptr;
20733 fence_ci.flags = 0;
20734
20735 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20736 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20737 ASSERT_VK_SUCCESS(err);
20738 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20739 ASSERT_VK_SUCCESS(err);
20740 }
20741
20742 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20743 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20744 // Create empty cmd buffer
20745 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20746 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20747
20748 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20749 ASSERT_VK_SUCCESS(err);
20750 err = vkEndCommandBuffer(cmd_buffers[obj]);
20751 ASSERT_VK_SUCCESS(err);
20752
20753 VkSubmitInfo submit_info = {};
20754 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20755 submit_info.commandBufferCount = 1;
20756 submit_info.pCommandBuffers = &cmd_buffers[obj];
20757 // Submit cmd buffer and wait for fence
20758 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20759 ASSERT_VK_SUCCESS(err);
20760 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20761 ASSERT_VK_SUCCESS(err);
20762 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20763 ASSERT_VK_SUCCESS(err);
20764 }
20765 }
20766 m_errorMonitor->VerifyNotFound();
20767 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20768 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20769 vkDestroyFence(m_device->device(), fences[i], nullptr);
20770 }
20771}
20772// This is a positive test. No errors should be generated.
20773TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020774 TEST_DESCRIPTION(
20775 "Two command buffers, each in a separate QueueSubmit call "
20776 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020777
20778 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020779 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020780
20781 m_errorMonitor->ExpectSuccess();
20782
20783 VkSemaphore semaphore;
20784 VkSemaphoreCreateInfo semaphore_create_info{};
20785 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20786 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20787
20788 VkCommandPool command_pool;
20789 VkCommandPoolCreateInfo pool_create_info{};
20790 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20791 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20792 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20793 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20794
20795 VkCommandBuffer command_buffer[2];
20796 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20797 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20798 command_buffer_allocate_info.commandPool = command_pool;
20799 command_buffer_allocate_info.commandBufferCount = 2;
20800 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20801 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20802
20803 VkQueue queue = VK_NULL_HANDLE;
20804 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20805
20806 {
20807 VkCommandBufferBeginInfo begin_info{};
20808 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20809 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20810
20811 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 -070020812 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020813
20814 VkViewport viewport{};
20815 viewport.maxDepth = 1.0f;
20816 viewport.minDepth = 0.0f;
20817 viewport.width = 512;
20818 viewport.height = 512;
20819 viewport.x = 0;
20820 viewport.y = 0;
20821 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20822 vkEndCommandBuffer(command_buffer[0]);
20823 }
20824 {
20825 VkCommandBufferBeginInfo begin_info{};
20826 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20827 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20828
20829 VkViewport viewport{};
20830 viewport.maxDepth = 1.0f;
20831 viewport.minDepth = 0.0f;
20832 viewport.width = 512;
20833 viewport.height = 512;
20834 viewport.x = 0;
20835 viewport.y = 0;
20836 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20837 vkEndCommandBuffer(command_buffer[1]);
20838 }
20839 {
20840 VkSubmitInfo submit_info{};
20841 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20842 submit_info.commandBufferCount = 1;
20843 submit_info.pCommandBuffers = &command_buffer[0];
20844 submit_info.signalSemaphoreCount = 1;
20845 submit_info.pSignalSemaphores = &semaphore;
20846 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20847 }
20848 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020849 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020850 VkSubmitInfo submit_info{};
20851 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20852 submit_info.commandBufferCount = 1;
20853 submit_info.pCommandBuffers = &command_buffer[1];
20854 submit_info.waitSemaphoreCount = 1;
20855 submit_info.pWaitSemaphores = &semaphore;
20856 submit_info.pWaitDstStageMask = flags;
20857 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20858 }
20859
20860 vkQueueWaitIdle(m_device->m_queue);
20861
20862 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20863 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20864 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20865
20866 m_errorMonitor->VerifyNotFound();
20867}
20868
20869// This is a positive test. No errors should be generated.
20870TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020871 TEST_DESCRIPTION(
20872 "Two command buffers, each in a separate QueueSubmit call "
20873 "submitted on separate queues, the second having a fence"
20874 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020875
20876 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020877 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020878
20879 m_errorMonitor->ExpectSuccess();
20880
20881 VkFence fence;
20882 VkFenceCreateInfo fence_create_info{};
20883 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20884 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20885
20886 VkSemaphore semaphore;
20887 VkSemaphoreCreateInfo semaphore_create_info{};
20888 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20889 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20890
20891 VkCommandPool command_pool;
20892 VkCommandPoolCreateInfo pool_create_info{};
20893 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20894 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20895 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20896 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20897
20898 VkCommandBuffer command_buffer[2];
20899 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20900 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20901 command_buffer_allocate_info.commandPool = command_pool;
20902 command_buffer_allocate_info.commandBufferCount = 2;
20903 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20904 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20905
20906 VkQueue queue = VK_NULL_HANDLE;
20907 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20908
20909 {
20910 VkCommandBufferBeginInfo begin_info{};
20911 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20912 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20913
20914 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 -070020915 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020916
20917 VkViewport viewport{};
20918 viewport.maxDepth = 1.0f;
20919 viewport.minDepth = 0.0f;
20920 viewport.width = 512;
20921 viewport.height = 512;
20922 viewport.x = 0;
20923 viewport.y = 0;
20924 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20925 vkEndCommandBuffer(command_buffer[0]);
20926 }
20927 {
20928 VkCommandBufferBeginInfo begin_info{};
20929 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20930 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20931
20932 VkViewport viewport{};
20933 viewport.maxDepth = 1.0f;
20934 viewport.minDepth = 0.0f;
20935 viewport.width = 512;
20936 viewport.height = 512;
20937 viewport.x = 0;
20938 viewport.y = 0;
20939 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20940 vkEndCommandBuffer(command_buffer[1]);
20941 }
20942 {
20943 VkSubmitInfo submit_info{};
20944 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20945 submit_info.commandBufferCount = 1;
20946 submit_info.pCommandBuffers = &command_buffer[0];
20947 submit_info.signalSemaphoreCount = 1;
20948 submit_info.pSignalSemaphores = &semaphore;
20949 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20950 }
20951 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020952 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020953 VkSubmitInfo submit_info{};
20954 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20955 submit_info.commandBufferCount = 1;
20956 submit_info.pCommandBuffers = &command_buffer[1];
20957 submit_info.waitSemaphoreCount = 1;
20958 submit_info.pWaitSemaphores = &semaphore;
20959 submit_info.pWaitDstStageMask = flags;
20960 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20961 }
20962
20963 vkQueueWaitIdle(m_device->m_queue);
20964
20965 vkDestroyFence(m_device->device(), fence, nullptr);
20966 vkDestroySemaphore(m_device->device(), semaphore, 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, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020975 TEST_DESCRIPTION(
20976 "Two command buffers, each in a separate QueueSubmit call "
20977 "submitted on separate queues, the second having a fence"
20978 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020979
20980 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020981 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020982
20983 m_errorMonitor->ExpectSuccess();
20984
20985 VkFence fence;
20986 VkFenceCreateInfo fence_create_info{};
20987 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20988 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20989
20990 VkSemaphore semaphore;
20991 VkSemaphoreCreateInfo semaphore_create_info{};
20992 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20993 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20994
20995 VkCommandPool command_pool;
20996 VkCommandPoolCreateInfo pool_create_info{};
20997 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20998 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20999 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21000 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21001
21002 VkCommandBuffer command_buffer[2];
21003 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21004 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21005 command_buffer_allocate_info.commandPool = command_pool;
21006 command_buffer_allocate_info.commandBufferCount = 2;
21007 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21008 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21009
21010 VkQueue queue = VK_NULL_HANDLE;
21011 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21012
21013 {
21014 VkCommandBufferBeginInfo begin_info{};
21015 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21016 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21017
21018 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 -070021019 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021020
21021 VkViewport viewport{};
21022 viewport.maxDepth = 1.0f;
21023 viewport.minDepth = 0.0f;
21024 viewport.width = 512;
21025 viewport.height = 512;
21026 viewport.x = 0;
21027 viewport.y = 0;
21028 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21029 vkEndCommandBuffer(command_buffer[0]);
21030 }
21031 {
21032 VkCommandBufferBeginInfo begin_info{};
21033 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21034 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21035
21036 VkViewport viewport{};
21037 viewport.maxDepth = 1.0f;
21038 viewport.minDepth = 0.0f;
21039 viewport.width = 512;
21040 viewport.height = 512;
21041 viewport.x = 0;
21042 viewport.y = 0;
21043 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21044 vkEndCommandBuffer(command_buffer[1]);
21045 }
21046 {
21047 VkSubmitInfo submit_info{};
21048 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21049 submit_info.commandBufferCount = 1;
21050 submit_info.pCommandBuffers = &command_buffer[0];
21051 submit_info.signalSemaphoreCount = 1;
21052 submit_info.pSignalSemaphores = &semaphore;
21053 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21054 }
21055 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021056 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021057 VkSubmitInfo submit_info{};
21058 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21059 submit_info.commandBufferCount = 1;
21060 submit_info.pCommandBuffers = &command_buffer[1];
21061 submit_info.waitSemaphoreCount = 1;
21062 submit_info.pWaitSemaphores = &semaphore;
21063 submit_info.pWaitDstStageMask = flags;
21064 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21065 }
21066
21067 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21068 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21069
21070 vkDestroyFence(m_device->device(), fence, nullptr);
21071 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21072 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21073 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21074
21075 m_errorMonitor->VerifyNotFound();
21076}
21077
21078TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021079 ASSERT_NO_FATAL_FAILURE(InitState());
21080 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021081 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021082 return;
21083 }
21084
21085 VkResult err;
21086
21087 m_errorMonitor->ExpectSuccess();
21088
21089 VkQueue q0 = m_device->m_queue;
21090 VkQueue q1 = nullptr;
21091 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
21092 ASSERT_NE(q1, nullptr);
21093
21094 // An (empty) command buffer. We must have work in the first submission --
21095 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021096 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021097 VkCommandPool pool;
21098 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
21099 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021100 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
21101 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021102 VkCommandBuffer cb;
21103 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
21104 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021105 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021106 err = vkBeginCommandBuffer(cb, &cbbi);
21107 ASSERT_VK_SUCCESS(err);
21108 err = vkEndCommandBuffer(cb);
21109 ASSERT_VK_SUCCESS(err);
21110
21111 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021112 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021113 VkSemaphore s;
21114 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
21115 ASSERT_VK_SUCCESS(err);
21116
21117 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021118 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021119
21120 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
21121 ASSERT_VK_SUCCESS(err);
21122
21123 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021124 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021125 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021126
21127 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
21128 ASSERT_VK_SUCCESS(err);
21129
21130 // Wait for q0 idle
21131 err = vkQueueWaitIdle(q0);
21132 ASSERT_VK_SUCCESS(err);
21133
21134 // Command buffer should have been completed (it was on q0); reset the pool.
21135 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
21136
21137 m_errorMonitor->VerifyNotFound();
21138
21139 // Force device completely idle and clean up resources
21140 vkDeviceWaitIdle(m_device->device());
21141 vkDestroyCommandPool(m_device->device(), pool, nullptr);
21142 vkDestroySemaphore(m_device->device(), s, nullptr);
21143}
21144
21145// This is a positive test. No errors should be generated.
21146TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021147 TEST_DESCRIPTION(
21148 "Two command buffers, each in a separate QueueSubmit call "
21149 "submitted on separate queues, the second having a fence, "
21150 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021151
21152 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021153 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021154
21155 m_errorMonitor->ExpectSuccess();
21156
21157 ASSERT_NO_FATAL_FAILURE(InitState());
21158 VkFence fence;
21159 VkFenceCreateInfo fence_create_info{};
21160 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21161 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21162
21163 VkSemaphore semaphore;
21164 VkSemaphoreCreateInfo semaphore_create_info{};
21165 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21166 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21167
21168 VkCommandPool command_pool;
21169 VkCommandPoolCreateInfo pool_create_info{};
21170 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21171 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21172 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21173 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21174
21175 VkCommandBuffer command_buffer[2];
21176 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21177 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21178 command_buffer_allocate_info.commandPool = command_pool;
21179 command_buffer_allocate_info.commandBufferCount = 2;
21180 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21181 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21182
21183 VkQueue queue = VK_NULL_HANDLE;
21184 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
21185
21186 {
21187 VkCommandBufferBeginInfo begin_info{};
21188 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21189 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21190
21191 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 -070021192 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021193
21194 VkViewport viewport{};
21195 viewport.maxDepth = 1.0f;
21196 viewport.minDepth = 0.0f;
21197 viewport.width = 512;
21198 viewport.height = 512;
21199 viewport.x = 0;
21200 viewport.y = 0;
21201 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21202 vkEndCommandBuffer(command_buffer[0]);
21203 }
21204 {
21205 VkCommandBufferBeginInfo begin_info{};
21206 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21207 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21208
21209 VkViewport viewport{};
21210 viewport.maxDepth = 1.0f;
21211 viewport.minDepth = 0.0f;
21212 viewport.width = 512;
21213 viewport.height = 512;
21214 viewport.x = 0;
21215 viewport.y = 0;
21216 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21217 vkEndCommandBuffer(command_buffer[1]);
21218 }
21219 {
21220 VkSubmitInfo submit_info{};
21221 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21222 submit_info.commandBufferCount = 1;
21223 submit_info.pCommandBuffers = &command_buffer[0];
21224 submit_info.signalSemaphoreCount = 1;
21225 submit_info.pSignalSemaphores = &semaphore;
21226 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21227 }
21228 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021229 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021230 VkSubmitInfo submit_info{};
21231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21232 submit_info.commandBufferCount = 1;
21233 submit_info.pCommandBuffers = &command_buffer[1];
21234 submit_info.waitSemaphoreCount = 1;
21235 submit_info.pWaitSemaphores = &semaphore;
21236 submit_info.pWaitDstStageMask = flags;
21237 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21238 }
21239
21240 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21241
21242 vkDestroyFence(m_device->device(), fence, nullptr);
21243 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21244 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21245 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21246
21247 m_errorMonitor->VerifyNotFound();
21248}
21249
21250// This is a positive test. No errors should be generated.
21251TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021252 TEST_DESCRIPTION(
21253 "Two command buffers, each in a separate QueueSubmit call "
21254 "on the same queue, sharing a signal/wait semaphore, the "
21255 "second having a fence, "
21256 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021257
21258 m_errorMonitor->ExpectSuccess();
21259
21260 ASSERT_NO_FATAL_FAILURE(InitState());
21261 VkFence fence;
21262 VkFenceCreateInfo fence_create_info{};
21263 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21264 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21265
21266 VkSemaphore semaphore;
21267 VkSemaphoreCreateInfo semaphore_create_info{};
21268 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21269 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21270
21271 VkCommandPool command_pool;
21272 VkCommandPoolCreateInfo pool_create_info{};
21273 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21274 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21275 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21276 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21277
21278 VkCommandBuffer command_buffer[2];
21279 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21280 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21281 command_buffer_allocate_info.commandPool = command_pool;
21282 command_buffer_allocate_info.commandBufferCount = 2;
21283 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21284 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21285
21286 {
21287 VkCommandBufferBeginInfo begin_info{};
21288 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21289 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21290
21291 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 -070021292 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021293
21294 VkViewport viewport{};
21295 viewport.maxDepth = 1.0f;
21296 viewport.minDepth = 0.0f;
21297 viewport.width = 512;
21298 viewport.height = 512;
21299 viewport.x = 0;
21300 viewport.y = 0;
21301 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21302 vkEndCommandBuffer(command_buffer[0]);
21303 }
21304 {
21305 VkCommandBufferBeginInfo begin_info{};
21306 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21307 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21308
21309 VkViewport viewport{};
21310 viewport.maxDepth = 1.0f;
21311 viewport.minDepth = 0.0f;
21312 viewport.width = 512;
21313 viewport.height = 512;
21314 viewport.x = 0;
21315 viewport.y = 0;
21316 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21317 vkEndCommandBuffer(command_buffer[1]);
21318 }
21319 {
21320 VkSubmitInfo submit_info{};
21321 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21322 submit_info.commandBufferCount = 1;
21323 submit_info.pCommandBuffers = &command_buffer[0];
21324 submit_info.signalSemaphoreCount = 1;
21325 submit_info.pSignalSemaphores = &semaphore;
21326 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21327 }
21328 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021329 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021330 VkSubmitInfo submit_info{};
21331 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21332 submit_info.commandBufferCount = 1;
21333 submit_info.pCommandBuffers = &command_buffer[1];
21334 submit_info.waitSemaphoreCount = 1;
21335 submit_info.pWaitSemaphores = &semaphore;
21336 submit_info.pWaitDstStageMask = flags;
21337 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21338 }
21339
21340 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21341
21342 vkDestroyFence(m_device->device(), fence, nullptr);
21343 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21344 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21345 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21346
21347 m_errorMonitor->VerifyNotFound();
21348}
21349
21350// This is a positive test. No errors should be generated.
21351TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021352 TEST_DESCRIPTION(
21353 "Two command buffers, each in a separate QueueSubmit call "
21354 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21355 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021356
21357 m_errorMonitor->ExpectSuccess();
21358
21359 ASSERT_NO_FATAL_FAILURE(InitState());
21360 VkFence fence;
21361 VkFenceCreateInfo fence_create_info{};
21362 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21363 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21364
21365 VkCommandPool command_pool;
21366 VkCommandPoolCreateInfo pool_create_info{};
21367 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21368 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21369 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21370 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21371
21372 VkCommandBuffer command_buffer[2];
21373 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21374 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21375 command_buffer_allocate_info.commandPool = command_pool;
21376 command_buffer_allocate_info.commandBufferCount = 2;
21377 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21378 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21379
21380 {
21381 VkCommandBufferBeginInfo begin_info{};
21382 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21383 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21384
21385 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 -070021386 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021387
21388 VkViewport viewport{};
21389 viewport.maxDepth = 1.0f;
21390 viewport.minDepth = 0.0f;
21391 viewport.width = 512;
21392 viewport.height = 512;
21393 viewport.x = 0;
21394 viewport.y = 0;
21395 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21396 vkEndCommandBuffer(command_buffer[0]);
21397 }
21398 {
21399 VkCommandBufferBeginInfo begin_info{};
21400 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21401 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21402
21403 VkViewport viewport{};
21404 viewport.maxDepth = 1.0f;
21405 viewport.minDepth = 0.0f;
21406 viewport.width = 512;
21407 viewport.height = 512;
21408 viewport.x = 0;
21409 viewport.y = 0;
21410 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21411 vkEndCommandBuffer(command_buffer[1]);
21412 }
21413 {
21414 VkSubmitInfo submit_info{};
21415 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21416 submit_info.commandBufferCount = 1;
21417 submit_info.pCommandBuffers = &command_buffer[0];
21418 submit_info.signalSemaphoreCount = 0;
21419 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21420 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21421 }
21422 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021423 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021424 VkSubmitInfo submit_info{};
21425 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21426 submit_info.commandBufferCount = 1;
21427 submit_info.pCommandBuffers = &command_buffer[1];
21428 submit_info.waitSemaphoreCount = 0;
21429 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21430 submit_info.pWaitDstStageMask = flags;
21431 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21432 }
21433
21434 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21435
21436 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21437 ASSERT_VK_SUCCESS(err);
21438
21439 vkDestroyFence(m_device->device(), fence, nullptr);
21440 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21441 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21442
21443 m_errorMonitor->VerifyNotFound();
21444}
21445
21446// This is a positive test. No errors should be generated.
21447TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021448 TEST_DESCRIPTION(
21449 "Two command buffers, each in a separate QueueSubmit call "
21450 "on the same queue, the second having a fence, followed "
21451 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021452
21453 m_errorMonitor->ExpectSuccess();
21454
21455 ASSERT_NO_FATAL_FAILURE(InitState());
21456 VkFence fence;
21457 VkFenceCreateInfo fence_create_info{};
21458 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21459 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21460
21461 VkCommandPool command_pool;
21462 VkCommandPoolCreateInfo pool_create_info{};
21463 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21464 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21465 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21466 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21467
21468 VkCommandBuffer command_buffer[2];
21469 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21470 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21471 command_buffer_allocate_info.commandPool = command_pool;
21472 command_buffer_allocate_info.commandBufferCount = 2;
21473 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21474 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21475
21476 {
21477 VkCommandBufferBeginInfo begin_info{};
21478 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21479 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21480
21481 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 -070021482 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021483
21484 VkViewport viewport{};
21485 viewport.maxDepth = 1.0f;
21486 viewport.minDepth = 0.0f;
21487 viewport.width = 512;
21488 viewport.height = 512;
21489 viewport.x = 0;
21490 viewport.y = 0;
21491 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21492 vkEndCommandBuffer(command_buffer[0]);
21493 }
21494 {
21495 VkCommandBufferBeginInfo begin_info{};
21496 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21497 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21498
21499 VkViewport viewport{};
21500 viewport.maxDepth = 1.0f;
21501 viewport.minDepth = 0.0f;
21502 viewport.width = 512;
21503 viewport.height = 512;
21504 viewport.x = 0;
21505 viewport.y = 0;
21506 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21507 vkEndCommandBuffer(command_buffer[1]);
21508 }
21509 {
21510 VkSubmitInfo submit_info{};
21511 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21512 submit_info.commandBufferCount = 1;
21513 submit_info.pCommandBuffers = &command_buffer[0];
21514 submit_info.signalSemaphoreCount = 0;
21515 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21516 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21517 }
21518 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021519 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021520 VkSubmitInfo submit_info{};
21521 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21522 submit_info.commandBufferCount = 1;
21523 submit_info.pCommandBuffers = &command_buffer[1];
21524 submit_info.waitSemaphoreCount = 0;
21525 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21526 submit_info.pWaitDstStageMask = flags;
21527 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21528 }
21529
21530 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21531
21532 vkDestroyFence(m_device->device(), fence, nullptr);
21533 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21534 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21535
21536 m_errorMonitor->VerifyNotFound();
21537}
21538
21539// This is a positive test. No errors should be generated.
21540TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021541 TEST_DESCRIPTION(
21542 "Two command buffers each in a separate SubmitInfo sent in a single "
21543 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021544 ASSERT_NO_FATAL_FAILURE(InitState());
21545
21546 m_errorMonitor->ExpectSuccess();
21547
21548 VkFence fence;
21549 VkFenceCreateInfo fence_create_info{};
21550 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21551 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21552
21553 VkSemaphore semaphore;
21554 VkSemaphoreCreateInfo semaphore_create_info{};
21555 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21556 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21557
21558 VkCommandPool command_pool;
21559 VkCommandPoolCreateInfo pool_create_info{};
21560 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21561 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21562 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21563 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21564
21565 VkCommandBuffer command_buffer[2];
21566 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21567 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21568 command_buffer_allocate_info.commandPool = command_pool;
21569 command_buffer_allocate_info.commandBufferCount = 2;
21570 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21571 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21572
21573 {
21574 VkCommandBufferBeginInfo begin_info{};
21575 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21576 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21577
21578 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 -070021579 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021580
21581 VkViewport viewport{};
21582 viewport.maxDepth = 1.0f;
21583 viewport.minDepth = 0.0f;
21584 viewport.width = 512;
21585 viewport.height = 512;
21586 viewport.x = 0;
21587 viewport.y = 0;
21588 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21589 vkEndCommandBuffer(command_buffer[0]);
21590 }
21591 {
21592 VkCommandBufferBeginInfo begin_info{};
21593 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21594 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21595
21596 VkViewport viewport{};
21597 viewport.maxDepth = 1.0f;
21598 viewport.minDepth = 0.0f;
21599 viewport.width = 512;
21600 viewport.height = 512;
21601 viewport.x = 0;
21602 viewport.y = 0;
21603 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21604 vkEndCommandBuffer(command_buffer[1]);
21605 }
21606 {
21607 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021608 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021609
21610 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21611 submit_info[0].pNext = NULL;
21612 submit_info[0].commandBufferCount = 1;
21613 submit_info[0].pCommandBuffers = &command_buffer[0];
21614 submit_info[0].signalSemaphoreCount = 1;
21615 submit_info[0].pSignalSemaphores = &semaphore;
21616 submit_info[0].waitSemaphoreCount = 0;
21617 submit_info[0].pWaitSemaphores = NULL;
21618 submit_info[0].pWaitDstStageMask = 0;
21619
21620 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21621 submit_info[1].pNext = NULL;
21622 submit_info[1].commandBufferCount = 1;
21623 submit_info[1].pCommandBuffers = &command_buffer[1];
21624 submit_info[1].waitSemaphoreCount = 1;
21625 submit_info[1].pWaitSemaphores = &semaphore;
21626 submit_info[1].pWaitDstStageMask = flags;
21627 submit_info[1].signalSemaphoreCount = 0;
21628 submit_info[1].pSignalSemaphores = NULL;
21629 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21630 }
21631
21632 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21633
21634 vkDestroyFence(m_device->device(), fence, nullptr);
21635 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21636 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21637 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21638
21639 m_errorMonitor->VerifyNotFound();
21640}
21641
21642TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21643 m_errorMonitor->ExpectSuccess();
21644
21645 ASSERT_NO_FATAL_FAILURE(InitState());
21646 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21647
Tony Barbour552f6c02016-12-21 14:34:07 -070021648 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021649
21650 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21651 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21652 m_errorMonitor->VerifyNotFound();
21653 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21654 m_errorMonitor->VerifyNotFound();
21655 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21656 m_errorMonitor->VerifyNotFound();
21657
21658 m_commandBuffer->EndCommandBuffer();
21659 m_errorMonitor->VerifyNotFound();
21660}
21661
21662TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021663 TEST_DESCRIPTION(
21664 "Positive test where we create a renderpass with an "
21665 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21666 "has a valid layout, and a second subpass then uses a "
21667 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021668 m_errorMonitor->ExpectSuccess();
21669 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021670 auto depth_format = find_depth_stencil_format(m_device);
21671 if (!depth_format) {
21672 printf(" No Depth + Stencil format found. Skipped.\n");
21673 return;
21674 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021675
21676 VkAttachmentReference attach[2] = {};
21677 attach[0].attachment = 0;
21678 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21679 attach[1].attachment = 0;
21680 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21681 VkSubpassDescription subpasses[2] = {};
21682 // First subpass clears DS attach on load
21683 subpasses[0].pDepthStencilAttachment = &attach[0];
21684 // 2nd subpass reads in DS as input attachment
21685 subpasses[1].inputAttachmentCount = 1;
21686 subpasses[1].pInputAttachments = &attach[1];
21687 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021688 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021689 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21690 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21691 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21692 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21693 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21694 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21695 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21696 VkRenderPassCreateInfo rpci = {};
21697 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21698 rpci.attachmentCount = 1;
21699 rpci.pAttachments = &attach_desc;
21700 rpci.subpassCount = 2;
21701 rpci.pSubpasses = subpasses;
21702
21703 // Now create RenderPass and verify no errors
21704 VkRenderPass rp;
21705 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21706 m_errorMonitor->VerifyNotFound();
21707
21708 vkDestroyRenderPass(m_device->device(), rp, NULL);
21709}
21710
Tobin Ehlis01103de2017-02-16 13:22:47 -070021711TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21712 TEST_DESCRIPTION(
21713 "Create a render pass with depth-stencil attachment where layout transition "
21714 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21715 "transition has correctly occurred at queue submit time with no validation errors.");
21716
Tony Barbourf887b162017-03-09 10:06:46 -070021717 ASSERT_NO_FATAL_FAILURE(InitState());
21718 auto depth_format = find_depth_stencil_format(m_device);
21719 if (!depth_format) {
21720 printf(" No Depth + Stencil format found. Skipped.\n");
21721 return;
21722 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021723 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021724 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021725 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21726 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021727 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021728 return;
21729 }
21730
21731 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021732 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21733
21734 // A renderpass with one depth/stencil attachment.
21735 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021736 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021737 VK_SAMPLE_COUNT_1_BIT,
21738 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21739 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21740 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21741 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21742 VK_IMAGE_LAYOUT_UNDEFINED,
21743 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21744
21745 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21746
21747 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21748
21749 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21750
21751 VkRenderPass rp;
21752 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21753 ASSERT_VK_SUCCESS(err);
21754 // A compatible ds image.
21755 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021756 image.init(32, 32, depth_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tobin Ehlis01103de2017-02-16 13:22:47 -070021757 ASSERT_TRUE(image.initialized());
21758
21759 VkImageViewCreateInfo ivci = {
21760 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21761 nullptr,
21762 0,
21763 image.handle(),
21764 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021765 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021766 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21767 VK_COMPONENT_SWIZZLE_IDENTITY},
21768 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21769 };
21770 VkImageView view;
21771 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21772 ASSERT_VK_SUCCESS(err);
21773
21774 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21775 VkFramebuffer fb;
21776 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21777 ASSERT_VK_SUCCESS(err);
21778
21779 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21780 m_commandBuffer->BeginCommandBuffer();
21781 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21782 vkCmdEndRenderPass(m_commandBuffer->handle());
21783 m_commandBuffer->EndCommandBuffer();
21784 QueueCommandBuffer(false);
21785 m_errorMonitor->VerifyNotFound();
21786
21787 // Cleanup
21788 vkDestroyImageView(m_device->device(), view, NULL);
21789 vkDestroyRenderPass(m_device->device(), rp, NULL);
21790 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21791}
21792
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021793TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021794 TEST_DESCRIPTION(
21795 "Test that pipeline validation accepts matrices passed "
21796 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021797 m_errorMonitor->ExpectSuccess();
21798
21799 ASSERT_NO_FATAL_FAILURE(InitState());
21800 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21801
21802 VkVertexInputBindingDescription input_binding;
21803 memset(&input_binding, 0, sizeof(input_binding));
21804
21805 VkVertexInputAttributeDescription input_attribs[2];
21806 memset(input_attribs, 0, sizeof(input_attribs));
21807
21808 for (int i = 0; i < 2; i++) {
21809 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21810 input_attribs[i].location = i;
21811 }
21812
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021813 char const *vsSource =
21814 "#version 450\n"
21815 "\n"
21816 "layout(location=0) in mat2x4 x;\n"
21817 "out gl_PerVertex {\n"
21818 " vec4 gl_Position;\n"
21819 "};\n"
21820 "void main(){\n"
21821 " gl_Position = x[0] + x[1];\n"
21822 "}\n";
21823 char const *fsSource =
21824 "#version 450\n"
21825 "\n"
21826 "layout(location=0) out vec4 color;\n"
21827 "void main(){\n"
21828 " color = vec4(1);\n"
21829 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021830
21831 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21832 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21833
21834 VkPipelineObj pipe(m_device);
21835 pipe.AddColorAttachment();
21836 pipe.AddShader(&vs);
21837 pipe.AddShader(&fs);
21838
21839 pipe.AddVertexInputBindings(&input_binding, 1);
21840 pipe.AddVertexInputAttribs(input_attribs, 2);
21841
21842 VkDescriptorSetObj descriptorSet(m_device);
21843 descriptorSet.AppendDummy();
21844 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21845
21846 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21847
21848 /* expect success */
21849 m_errorMonitor->VerifyNotFound();
21850}
21851
21852TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21853 m_errorMonitor->ExpectSuccess();
21854
21855 ASSERT_NO_FATAL_FAILURE(InitState());
21856 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21857
21858 VkVertexInputBindingDescription input_binding;
21859 memset(&input_binding, 0, sizeof(input_binding));
21860
21861 VkVertexInputAttributeDescription input_attribs[2];
21862 memset(input_attribs, 0, sizeof(input_attribs));
21863
21864 for (int i = 0; i < 2; i++) {
21865 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21866 input_attribs[i].location = i;
21867 }
21868
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021869 char const *vsSource =
21870 "#version 450\n"
21871 "\n"
21872 "layout(location=0) in vec4 x[2];\n"
21873 "out gl_PerVertex {\n"
21874 " vec4 gl_Position;\n"
21875 "};\n"
21876 "void main(){\n"
21877 " gl_Position = x[0] + x[1];\n"
21878 "}\n";
21879 char const *fsSource =
21880 "#version 450\n"
21881 "\n"
21882 "layout(location=0) out vec4 color;\n"
21883 "void main(){\n"
21884 " color = vec4(1);\n"
21885 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021886
21887 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21888 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21889
21890 VkPipelineObj pipe(m_device);
21891 pipe.AddColorAttachment();
21892 pipe.AddShader(&vs);
21893 pipe.AddShader(&fs);
21894
21895 pipe.AddVertexInputBindings(&input_binding, 1);
21896 pipe.AddVertexInputAttribs(input_attribs, 2);
21897
21898 VkDescriptorSetObj descriptorSet(m_device);
21899 descriptorSet.AppendDummy();
21900 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21901
21902 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21903
21904 m_errorMonitor->VerifyNotFound();
21905}
21906
21907TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021908 TEST_DESCRIPTION(
21909 "Test that pipeline validation accepts consuming a vertex attribute "
21910 "through multiple vertex shader inputs, each consuming a different "
21911 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021912 m_errorMonitor->ExpectSuccess();
21913
21914 ASSERT_NO_FATAL_FAILURE(InitState());
21915 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21916
21917 VkVertexInputBindingDescription input_binding;
21918 memset(&input_binding, 0, sizeof(input_binding));
21919
21920 VkVertexInputAttributeDescription input_attribs[3];
21921 memset(input_attribs, 0, sizeof(input_attribs));
21922
21923 for (int i = 0; i < 3; i++) {
21924 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21925 input_attribs[i].location = i;
21926 }
21927
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021928 char const *vsSource =
21929 "#version 450\n"
21930 "\n"
21931 "layout(location=0) in vec4 x;\n"
21932 "layout(location=1) in vec3 y1;\n"
21933 "layout(location=1, component=3) in float y2;\n"
21934 "layout(location=2) in vec4 z;\n"
21935 "out gl_PerVertex {\n"
21936 " vec4 gl_Position;\n"
21937 "};\n"
21938 "void main(){\n"
21939 " gl_Position = x + vec4(y1, y2) + z;\n"
21940 "}\n";
21941 char const *fsSource =
21942 "#version 450\n"
21943 "\n"
21944 "layout(location=0) out vec4 color;\n"
21945 "void main(){\n"
21946 " color = vec4(1);\n"
21947 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021948
21949 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21950 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21951
21952 VkPipelineObj pipe(m_device);
21953 pipe.AddColorAttachment();
21954 pipe.AddShader(&vs);
21955 pipe.AddShader(&fs);
21956
21957 pipe.AddVertexInputBindings(&input_binding, 1);
21958 pipe.AddVertexInputAttribs(input_attribs, 3);
21959
21960 VkDescriptorSetObj descriptorSet(m_device);
21961 descriptorSet.AppendDummy();
21962 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21963
21964 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21965
21966 m_errorMonitor->VerifyNotFound();
21967}
21968
21969TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21970 m_errorMonitor->ExpectSuccess();
21971
21972 ASSERT_NO_FATAL_FAILURE(InitState());
21973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021975 char const *vsSource =
21976 "#version 450\n"
21977 "out gl_PerVertex {\n"
21978 " vec4 gl_Position;\n"
21979 "};\n"
21980 "void main(){\n"
21981 " gl_Position = vec4(0);\n"
21982 "}\n";
21983 char const *fsSource =
21984 "#version 450\n"
21985 "\n"
21986 "layout(location=0) out vec4 color;\n"
21987 "void main(){\n"
21988 " color = vec4(1);\n"
21989 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021990
21991 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21992 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21993
21994 VkPipelineObj pipe(m_device);
21995 pipe.AddColorAttachment();
21996 pipe.AddShader(&vs);
21997 pipe.AddShader(&fs);
21998
21999 VkDescriptorSetObj descriptorSet(m_device);
22000 descriptorSet.AppendDummy();
22001 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22002
22003 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22004
22005 m_errorMonitor->VerifyNotFound();
22006}
22007
22008TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022009 TEST_DESCRIPTION(
22010 "Test that pipeline validation accepts the relaxed type matching rules "
22011 "set out in 14.1.3: fundamental type must match, and producer side must "
22012 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022013 m_errorMonitor->ExpectSuccess();
22014
22015 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
22016
22017 ASSERT_NO_FATAL_FAILURE(InitState());
22018 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22019
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022020 char const *vsSource =
22021 "#version 450\n"
22022 "out gl_PerVertex {\n"
22023 " vec4 gl_Position;\n"
22024 "};\n"
22025 "layout(location=0) out vec3 x;\n"
22026 "layout(location=1) out ivec3 y;\n"
22027 "layout(location=2) out vec3 z;\n"
22028 "void main(){\n"
22029 " gl_Position = vec4(0);\n"
22030 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
22031 "}\n";
22032 char const *fsSource =
22033 "#version 450\n"
22034 "\n"
22035 "layout(location=0) out vec4 color;\n"
22036 "layout(location=0) in float x;\n"
22037 "layout(location=1) flat in int y;\n"
22038 "layout(location=2) in vec2 z;\n"
22039 "void main(){\n"
22040 " color = vec4(1 + x + y + z.x);\n"
22041 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022042
22043 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22044 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22045
22046 VkPipelineObj pipe(m_device);
22047 pipe.AddColorAttachment();
22048 pipe.AddShader(&vs);
22049 pipe.AddShader(&fs);
22050
22051 VkDescriptorSetObj descriptorSet(m_device);
22052 descriptorSet.AppendDummy();
22053 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22054
22055 VkResult err = VK_SUCCESS;
22056 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22057 ASSERT_VK_SUCCESS(err);
22058
22059 m_errorMonitor->VerifyNotFound();
22060}
22061
22062TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022063 TEST_DESCRIPTION(
22064 "Test that pipeline validation accepts per-vertex variables "
22065 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022066 m_errorMonitor->ExpectSuccess();
22067
22068 ASSERT_NO_FATAL_FAILURE(InitState());
22069 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22070
22071 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022072 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022073 return;
22074 }
22075
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022076 char const *vsSource =
22077 "#version 450\n"
22078 "void main(){}\n";
22079 char const *tcsSource =
22080 "#version 450\n"
22081 "layout(location=0) out int x[];\n"
22082 "layout(vertices=3) out;\n"
22083 "void main(){\n"
22084 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
22085 " gl_TessLevelInner[0] = 1;\n"
22086 " x[gl_InvocationID] = gl_InvocationID;\n"
22087 "}\n";
22088 char const *tesSource =
22089 "#version 450\n"
22090 "layout(triangles, equal_spacing, cw) in;\n"
22091 "layout(location=0) in int x[];\n"
22092 "out gl_PerVertex { vec4 gl_Position; };\n"
22093 "void main(){\n"
22094 " gl_Position.xyz = gl_TessCoord;\n"
22095 " gl_Position.w = x[0] + x[1] + x[2];\n"
22096 "}\n";
22097 char const *fsSource =
22098 "#version 450\n"
22099 "layout(location=0) out vec4 color;\n"
22100 "void main(){\n"
22101 " color = vec4(1);\n"
22102 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022103
22104 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22105 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
22106 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
22107 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22108
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022109 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
22110 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022111
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022112 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022113
22114 VkPipelineObj pipe(m_device);
22115 pipe.SetInputAssembly(&iasci);
22116 pipe.SetTessellation(&tsci);
22117 pipe.AddColorAttachment();
22118 pipe.AddShader(&vs);
22119 pipe.AddShader(&tcs);
22120 pipe.AddShader(&tes);
22121 pipe.AddShader(&fs);
22122
22123 VkDescriptorSetObj descriptorSet(m_device);
22124 descriptorSet.AppendDummy();
22125 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22126
22127 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22128
22129 m_errorMonitor->VerifyNotFound();
22130}
22131
22132TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022133 TEST_DESCRIPTION(
22134 "Test that pipeline validation accepts a user-defined "
22135 "interface block passed into the geometry shader. This "
22136 "is interesting because the 'extra' array level is not "
22137 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022138 m_errorMonitor->ExpectSuccess();
22139
22140 ASSERT_NO_FATAL_FAILURE(InitState());
22141 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22142
22143 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022144 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022145 return;
22146 }
22147
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022148 char const *vsSource =
22149 "#version 450\n"
22150 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
22151 "void main(){\n"
22152 " vs_out.x = vec4(1);\n"
22153 "}\n";
22154 char const *gsSource =
22155 "#version 450\n"
22156 "layout(triangles) in;\n"
22157 "layout(triangle_strip, max_vertices=3) out;\n"
22158 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
22159 "out gl_PerVertex { vec4 gl_Position; };\n"
22160 "void main() {\n"
22161 " gl_Position = gs_in[0].x;\n"
22162 " EmitVertex();\n"
22163 "}\n";
22164 char const *fsSource =
22165 "#version 450\n"
22166 "layout(location=0) out vec4 color;\n"
22167 "void main(){\n"
22168 " color = vec4(1);\n"
22169 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022170
22171 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22172 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
22173 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22174
22175 VkPipelineObj pipe(m_device);
22176 pipe.AddColorAttachment();
22177 pipe.AddShader(&vs);
22178 pipe.AddShader(&gs);
22179 pipe.AddShader(&fs);
22180
22181 VkDescriptorSetObj descriptorSet(m_device);
22182 descriptorSet.AppendDummy();
22183 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22184
22185 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22186
22187 m_errorMonitor->VerifyNotFound();
22188}
22189
22190TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022191 TEST_DESCRIPTION(
22192 "Test that pipeline validation accepts basic use of 64bit vertex "
22193 "attributes. This is interesting because they consume multiple "
22194 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022195 m_errorMonitor->ExpectSuccess();
22196
22197 ASSERT_NO_FATAL_FAILURE(InitState());
22198 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22199
22200 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022201 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022202 return;
22203 }
22204
22205 VkVertexInputBindingDescription input_bindings[1];
22206 memset(input_bindings, 0, sizeof(input_bindings));
22207
22208 VkVertexInputAttributeDescription input_attribs[4];
22209 memset(input_attribs, 0, sizeof(input_attribs));
22210 input_attribs[0].location = 0;
22211 input_attribs[0].offset = 0;
22212 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22213 input_attribs[1].location = 2;
22214 input_attribs[1].offset = 32;
22215 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22216 input_attribs[2].location = 4;
22217 input_attribs[2].offset = 64;
22218 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22219 input_attribs[3].location = 6;
22220 input_attribs[3].offset = 96;
22221 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22222
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022223 char const *vsSource =
22224 "#version 450\n"
22225 "\n"
22226 "layout(location=0) in dmat4 x;\n"
22227 "out gl_PerVertex {\n"
22228 " vec4 gl_Position;\n"
22229 "};\n"
22230 "void main(){\n"
22231 " gl_Position = vec4(x[0][0]);\n"
22232 "}\n";
22233 char const *fsSource =
22234 "#version 450\n"
22235 "\n"
22236 "layout(location=0) out vec4 color;\n"
22237 "void main(){\n"
22238 " color = vec4(1);\n"
22239 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022240
22241 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22242 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22243
22244 VkPipelineObj pipe(m_device);
22245 pipe.AddColorAttachment();
22246 pipe.AddShader(&vs);
22247 pipe.AddShader(&fs);
22248
22249 pipe.AddVertexInputBindings(input_bindings, 1);
22250 pipe.AddVertexInputAttribs(input_attribs, 4);
22251
22252 VkDescriptorSetObj descriptorSet(m_device);
22253 descriptorSet.AppendDummy();
22254 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22255
22256 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22257
22258 m_errorMonitor->VerifyNotFound();
22259}
22260
22261TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22262 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22263 m_errorMonitor->ExpectSuccess();
22264
22265 ASSERT_NO_FATAL_FAILURE(InitState());
22266
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022267 char const *vsSource =
22268 "#version 450\n"
22269 "\n"
22270 "out gl_PerVertex {\n"
22271 " vec4 gl_Position;\n"
22272 "};\n"
22273 "void main(){\n"
22274 " gl_Position = vec4(1);\n"
22275 "}\n";
22276 char const *fsSource =
22277 "#version 450\n"
22278 "\n"
22279 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22280 "layout(location=0) out vec4 color;\n"
22281 "void main() {\n"
22282 " color = subpassLoad(x);\n"
22283 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022284
22285 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22286 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22287
22288 VkPipelineObj pipe(m_device);
22289 pipe.AddShader(&vs);
22290 pipe.AddShader(&fs);
22291 pipe.AddColorAttachment();
22292 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22293
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022294 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22295 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022296 VkDescriptorSetLayout dsl;
22297 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22298 ASSERT_VK_SUCCESS(err);
22299
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022300 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022301 VkPipelineLayout pl;
22302 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22303 ASSERT_VK_SUCCESS(err);
22304
22305 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022306 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22307 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22308 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22309 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22310 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 -060022311 };
22312 VkAttachmentReference color = {
22313 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22314 };
22315 VkAttachmentReference input = {
22316 1, VK_IMAGE_LAYOUT_GENERAL,
22317 };
22318
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022319 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022320
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022321 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022322 VkRenderPass rp;
22323 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22324 ASSERT_VK_SUCCESS(err);
22325
22326 // should be OK. would go wrong here if it's going to...
22327 pipe.CreateVKPipeline(pl, rp);
22328
22329 m_errorMonitor->VerifyNotFound();
22330
22331 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22332 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22333 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22334}
22335
22336TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022337 TEST_DESCRIPTION(
22338 "Test that pipeline validation accepts a compute pipeline which declares a "
22339 "descriptor-backed resource which is not provided, but the shader does not "
22340 "statically use it. This is interesting because it requires compute pipelines "
22341 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022342 m_errorMonitor->ExpectSuccess();
22343
22344 ASSERT_NO_FATAL_FAILURE(InitState());
22345
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022346 char const *csSource =
22347 "#version 450\n"
22348 "\n"
22349 "layout(local_size_x=1) in;\n"
22350 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22351 "void main(){\n"
22352 " // x is not used.\n"
22353 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022354
22355 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22356
22357 VkDescriptorSetObj descriptorSet(m_device);
22358 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22359
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022360 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22361 nullptr,
22362 0,
22363 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22364 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22365 descriptorSet.GetPipelineLayout(),
22366 VK_NULL_HANDLE,
22367 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022368
22369 VkPipeline pipe;
22370 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22371
22372 m_errorMonitor->VerifyNotFound();
22373
22374 if (err == VK_SUCCESS) {
22375 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22376 }
22377}
22378
22379TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022380 TEST_DESCRIPTION(
22381 "Test that pipeline validation accepts a shader consuming only the "
22382 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022383 m_errorMonitor->ExpectSuccess();
22384
22385 ASSERT_NO_FATAL_FAILURE(InitState());
22386
22387 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022388 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22389 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22390 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022391 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022392 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022393 VkDescriptorSetLayout dsl;
22394 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22395 ASSERT_VK_SUCCESS(err);
22396
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022397 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022398 VkPipelineLayout pl;
22399 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22400 ASSERT_VK_SUCCESS(err);
22401
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022402 char const *csSource =
22403 "#version 450\n"
22404 "\n"
22405 "layout(local_size_x=1) in;\n"
22406 "layout(set=0, binding=0) uniform sampler s;\n"
22407 "layout(set=0, binding=1) uniform texture2D t;\n"
22408 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22409 "void main() {\n"
22410 " x = texture(sampler2D(t, s), vec2(0));\n"
22411 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022412 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22413
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022414 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22415 nullptr,
22416 0,
22417 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22418 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22419 pl,
22420 VK_NULL_HANDLE,
22421 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022422
22423 VkPipeline pipe;
22424 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22425
22426 m_errorMonitor->VerifyNotFound();
22427
22428 if (err == VK_SUCCESS) {
22429 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22430 }
22431
22432 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22433 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22434}
22435
22436TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022437 TEST_DESCRIPTION(
22438 "Test that pipeline validation accepts a shader consuming only the "
22439 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022440 m_errorMonitor->ExpectSuccess();
22441
22442 ASSERT_NO_FATAL_FAILURE(InitState());
22443
22444 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022445 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22446 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22447 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022448 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022449 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022450 VkDescriptorSetLayout dsl;
22451 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22452 ASSERT_VK_SUCCESS(err);
22453
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022454 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022455 VkPipelineLayout pl;
22456 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22457 ASSERT_VK_SUCCESS(err);
22458
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022459 char const *csSource =
22460 "#version 450\n"
22461 "\n"
22462 "layout(local_size_x=1) in;\n"
22463 "layout(set=0, binding=0) uniform texture2D t;\n"
22464 "layout(set=0, binding=1) uniform sampler s;\n"
22465 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22466 "void main() {\n"
22467 " x = texture(sampler2D(t, s), vec2(0));\n"
22468 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022469 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22470
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022471 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22472 nullptr,
22473 0,
22474 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22475 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22476 pl,
22477 VK_NULL_HANDLE,
22478 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022479
22480 VkPipeline pipe;
22481 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22482
22483 m_errorMonitor->VerifyNotFound();
22484
22485 if (err == VK_SUCCESS) {
22486 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22487 }
22488
22489 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22490 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22491}
22492
22493TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022494 TEST_DESCRIPTION(
22495 "Test that pipeline validation accepts a shader consuming "
22496 "both the sampler and the image of a combined image+sampler "
22497 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022498 m_errorMonitor->ExpectSuccess();
22499
22500 ASSERT_NO_FATAL_FAILURE(InitState());
22501
22502 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022503 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22504 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022505 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022506 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022507 VkDescriptorSetLayout dsl;
22508 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22509 ASSERT_VK_SUCCESS(err);
22510
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022511 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022512 VkPipelineLayout pl;
22513 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22514 ASSERT_VK_SUCCESS(err);
22515
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022516 char const *csSource =
22517 "#version 450\n"
22518 "\n"
22519 "layout(local_size_x=1) in;\n"
22520 "layout(set=0, binding=0) uniform texture2D t;\n"
22521 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22522 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22523 "void main() {\n"
22524 " x = texture(sampler2D(t, s), vec2(0));\n"
22525 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022526 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22527
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022528 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22529 nullptr,
22530 0,
22531 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22532 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22533 pl,
22534 VK_NULL_HANDLE,
22535 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022536
22537 VkPipeline pipe;
22538 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22539
22540 m_errorMonitor->VerifyNotFound();
22541
22542 if (err == VK_SUCCESS) {
22543 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22544 }
22545
22546 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22547 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22548}
22549
Mark Lobodzinskidf784fc2017-03-14 09:18:40 -060022550// This test class enables the Maintenance1 extension for related validation tests
22551TEST_F(VkMaintenance1LayerTest, Maintenance1Tests) {
22552 TEST_DESCRIPTION("Validate various special cases for the Maintenance1_KHR extension");
22553
22554 // Ensure that extension is available and enabled.
22555 uint32_t extension_count = 0;
22556 bool supports_maintenance1_extension = false;
22557 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22558 ASSERT_VK_SUCCESS(err);
22559 if (extension_count > 0) {
22560 std::vector<VkExtensionProperties> available_extensions(extension_count);
22561
22562 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22563 ASSERT_VK_SUCCESS(err);
22564 for (const auto &extension_props : available_extensions) {
22565 if (strcmp(extension_props.extensionName, VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) {
22566 supports_maintenance1_extension = true;
22567 }
22568 }
22569 }
22570
22571 // Proceed if extension is supported by hardware
22572 if (!supports_maintenance1_extension) {
22573 printf(" Maintenance1 Extension not supported, skipping tests\n");
22574 return;
22575 }
22576 ASSERT_NO_FATAL_FAILURE(InitState());
22577
22578 m_errorMonitor->ExpectSuccess();
22579
22580 VkCommandBuffer cmd_buf;
22581 VkCommandBufferAllocateInfo alloc_info;
22582 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
22583 alloc_info.pNext = NULL;
22584 alloc_info.commandBufferCount = 1;
22585 alloc_info.commandPool = m_commandPool;
22586 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
22587 vkAllocateCommandBuffers(m_device->device(), &alloc_info, &cmd_buf);
22588
22589 VkCommandBufferBeginInfo cb_binfo;
22590 cb_binfo.pNext = NULL;
22591 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
22592 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
22593 cb_binfo.flags = 0;
22594 vkBeginCommandBuffer(cmd_buf, &cb_binfo);
22595 // Set Negative height, should give error if Maintenance 1 is not enabled
22596 VkViewport viewport = {0, 0, 16, -16, 0, 1};
22597 vkCmdSetViewport(cmd_buf, 0, 1, &viewport);
22598 vkEndCommandBuffer(cmd_buf);
22599
22600 m_errorMonitor->VerifyNotFound();
22601}
22602
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022603TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22604 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22605
22606 ASSERT_NO_FATAL_FAILURE(InitState());
22607
22608 // Positive test to check parameter_validation and unique_objects support
22609 // for NV_dedicated_allocation
22610 uint32_t extension_count = 0;
22611 bool supports_nv_dedicated_allocation = false;
22612 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22613 ASSERT_VK_SUCCESS(err);
22614
22615 if (extension_count > 0) {
22616 std::vector<VkExtensionProperties> available_extensions(extension_count);
22617
22618 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22619 ASSERT_VK_SUCCESS(err);
22620
22621 for (const auto &extension_props : available_extensions) {
22622 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22623 supports_nv_dedicated_allocation = true;
22624 }
22625 }
22626 }
22627
22628 if (supports_nv_dedicated_allocation) {
22629 m_errorMonitor->ExpectSuccess();
22630
22631 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22632 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22633 dedicated_buffer_create_info.pNext = nullptr;
22634 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22635
22636 uint32_t queue_family_index = 0;
22637 VkBufferCreateInfo buffer_create_info = {};
22638 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22639 buffer_create_info.pNext = &dedicated_buffer_create_info;
22640 buffer_create_info.size = 1024;
22641 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22642 buffer_create_info.queueFamilyIndexCount = 1;
22643 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22644
22645 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022646 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022647 ASSERT_VK_SUCCESS(err);
22648
22649 VkMemoryRequirements memory_reqs;
22650 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22651
22652 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22653 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22654 dedicated_memory_info.pNext = nullptr;
22655 dedicated_memory_info.buffer = buffer;
22656 dedicated_memory_info.image = VK_NULL_HANDLE;
22657
22658 VkMemoryAllocateInfo memory_info = {};
22659 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22660 memory_info.pNext = &dedicated_memory_info;
22661 memory_info.allocationSize = memory_reqs.size;
22662
22663 bool pass;
22664 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22665 ASSERT_TRUE(pass);
22666
22667 VkDeviceMemory buffer_memory;
22668 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22669 ASSERT_VK_SUCCESS(err);
22670
22671 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22672 ASSERT_VK_SUCCESS(err);
22673
22674 vkDestroyBuffer(m_device->device(), buffer, NULL);
22675 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22676
22677 m_errorMonitor->VerifyNotFound();
22678 }
22679}
22680
22681TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22682 VkResult err;
22683
22684 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22685
22686 ASSERT_NO_FATAL_FAILURE(InitState());
22687 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22688
22689 std::vector<const char *> device_extension_names;
22690 auto features = m_device->phy().features();
22691 // Artificially disable support for non-solid fill modes
22692 features.fillModeNonSolid = false;
22693 // The sacrificial device object
22694 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22695
22696 VkRenderpassObj render_pass(&test_device);
22697
22698 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22699 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22700 pipeline_layout_ci.setLayoutCount = 0;
22701 pipeline_layout_ci.pSetLayouts = NULL;
22702
22703 VkPipelineLayout pipeline_layout;
22704 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22705 ASSERT_VK_SUCCESS(err);
22706
22707 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22708 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22709 rs_ci.pNext = nullptr;
22710 rs_ci.lineWidth = 1.0f;
22711 rs_ci.rasterizerDiscardEnable = true;
22712
22713 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22714 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22715
22716 // Set polygonMode=FILL. No error is expected
22717 m_errorMonitor->ExpectSuccess();
22718 {
22719 VkPipelineObj pipe(&test_device);
22720 pipe.AddShader(&vs);
22721 pipe.AddShader(&fs);
22722 pipe.AddColorAttachment();
22723 // Set polygonMode to a good value
22724 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22725 pipe.SetRasterization(&rs_ci);
22726 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22727 }
22728 m_errorMonitor->VerifyNotFound();
22729
22730 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22731}
22732
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022733#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022734TEST_F(VkPositiveLayerTest, LongFenceChain)
22735{
22736 m_errorMonitor->ExpectSuccess();
22737
22738 ASSERT_NO_FATAL_FAILURE(InitState());
22739 VkResult err;
22740
22741 std::vector<VkFence> fences;
22742
22743 const int chainLength = 32768;
22744
22745 for (int i = 0; i < chainLength; i++) {
22746 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22747 VkFence fence;
22748 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22749 ASSERT_VK_SUCCESS(err);
22750
22751 fences.push_back(fence);
22752
22753 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22754 0, nullptr, 0, nullptr };
22755 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22756 ASSERT_VK_SUCCESS(err);
22757
22758 }
22759
22760 // BOOM, stack overflow.
22761 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22762
22763 for (auto fence : fences)
22764 vkDestroyFence(m_device->device(), fence, nullptr);
22765
22766 m_errorMonitor->VerifyNotFound();
22767}
22768#endif
22769
Cody Northrop1242dfd2016-07-13 17:24:59 -060022770#if defined(ANDROID) && defined(VALIDATION_APK)
22771static bool initialized = false;
22772static bool active = false;
22773
22774// Convert Intents to argv
22775// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022776std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022777 std::vector<std::string> args;
22778 JavaVM &vm = *app.activity->vm;
22779 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022780 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022781
22782 JNIEnv &env = *p_env;
22783 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022784 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022785 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022786 jmethodID get_string_extra_method =
22787 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022788 jvalue get_string_extra_args;
22789 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022790 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022791
22792 std::string args_str;
22793 if (extra_str) {
22794 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22795 args_str = extra_utf;
22796 env.ReleaseStringUTFChars(extra_str, extra_utf);
22797 env.DeleteLocalRef(extra_str);
22798 }
22799
22800 env.DeleteLocalRef(get_string_extra_args.l);
22801 env.DeleteLocalRef(intent);
22802 vm.DetachCurrentThread();
22803
22804 // split args_str
22805 std::stringstream ss(args_str);
22806 std::string arg;
22807 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022808 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022809 }
22810
22811 return args;
22812}
22813
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022814static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022815
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022816static void processCommand(struct android_app *app, int32_t cmd) {
22817 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022818 case APP_CMD_INIT_WINDOW: {
22819 if (app->window) {
22820 initialized = true;
22821 }
22822 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022823 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022824 case APP_CMD_GAINED_FOCUS: {
22825 active = true;
22826 break;
22827 }
22828 case APP_CMD_LOST_FOCUS: {
22829 active = false;
22830 break;
22831 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022832 }
22833}
22834
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022835void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022836 app_dummy();
22837
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022838 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022839
22840 int vulkanSupport = InitVulkan();
22841 if (vulkanSupport == 0) {
22842 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22843 return;
22844 }
22845
22846 app->onAppCmd = processCommand;
22847 app->onInputEvent = processInput;
22848
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022849 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022850 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022851 struct android_poll_source *source;
22852 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022853 if (source) {
22854 source->process(app, source);
22855 }
22856
22857 if (app->destroyRequested != 0) {
22858 VkTestFramework::Finish();
22859 return;
22860 }
22861 }
22862
22863 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022864 // Use the following key to send arguments to gtest, i.e.
22865 // --es args "--gtest_filter=-VkLayerTest.foo"
22866 const char key[] = "args";
22867 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022868
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022869 std::string filter = "";
22870 if (args.size() > 0) {
22871 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22872 filter += args[0];
22873 } else {
22874 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22875 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022876
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022877 int argc = 2;
22878 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22879 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022880
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022881 // Route output to files until we can override the gtest output
22882 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22883 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022884
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022885 ::testing::InitGoogleTest(&argc, argv);
22886 VkTestFramework::InitArgs(&argc, argv);
22887 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022888
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022889 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022890
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022891 if (result != 0) {
22892 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22893 } else {
22894 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22895 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022896
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022897 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022899 fclose(stdout);
22900 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022901
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022902 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022903 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022904 }
22905 }
22906}
22907#endif
22908
Tony Barbour300a6082015-04-07 13:44:53 -060022909int main(int argc, char **argv) {
22910 int result;
22911
Cody Northrop8e54a402016-03-08 22:25:52 -070022912#ifdef ANDROID
22913 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022914 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022915#endif
22916
Tony Barbour300a6082015-04-07 13:44:53 -060022917 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022918 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022919
22920 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22921
22922 result = RUN_ALL_TESTS();
22923
Tony Barbour6918cd52015-04-09 12:58:51 -060022924 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022925 return result;
22926}