blob: a71797cfb085d2208160a8611b33bdf36783df70 [file] [log] [blame]
Karl Schultz6addd812016-02-02 17:17:23 -07001/*
Mike Weiblen40b160e2017-02-06 19:21:52 -07002 * Copyright (c) 2015-2017 The Khronos Group Inc.
3 * Copyright (c) 2015-2017 Valve Corporation
4 * Copyright (c) 2015-2017 LunarG, Inc.
5 * Copyright (c) 2015-2017 Google, Inc.
Karl Schultz6addd812016-02-02 17:17:23 -07006 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -06007 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
Karl Schultz6addd812016-02-02 17:17:23 -070010 *
Jon Ashburn3ebf1252016-04-19 11:30:31 -060011 * http://www.apache.org/licenses/LICENSE-2.0
Karl Schultz6addd812016-02-02 17:17:23 -070012 *
13 * Author: Chia-I Wu <olvaffe@gmail.com>
14 * Author: Chris Forbes <chrisf@ijw.co.nz>
15 * Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
16 * Author: Mark Lobodzinski <mark@lunarg.com>
17 * Author: Mike Stroyan <mike@LunarG.com>
18 * Author: Tobin Ehlis <tobine@google.com>
19 * Author: Tony Barbour <tony@LunarG.com>
Cody Northrop1242dfd2016-07-13 17:24:59 -060020 * Author: Cody Northrop <cnorthrop@google.com>
Dave Houlton59a20702017-02-02 17:26:23 -070021 * Author: Dave Houlton <daveh@lunarg.com>
Karl Schultz6addd812016-02-02 17:17:23 -070022 */
Tony Barbour65c48b32015-11-17 10:02:56 -070023
Cody Northrop8e54a402016-03-08 22:25:52 -070024#ifdef ANDROID
25#include "vulkan_wrapper.h"
26#else
David Pinedo9316d3b2015-11-06 12:54:48 -070027#include <vulkan/vulkan.h>
Cody Northrop8e54a402016-03-08 22:25:52 -070028#endif
Cody Northrop1242dfd2016-07-13 17:24:59 -060029
30#if defined(ANDROID) && defined(VALIDATION_APK)
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#endif
34
Jon Ashburn7fa7e222016-02-02 12:08:10 -070035#include "icd-spv.h"
Mark Lobodzinskice751c62016-09-08 10:45:35 -060036#include "test_common.h"
37#include "vk_layer_config.h"
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060038#include "vk_validation_error_messages.h"
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060039#include "vkrenderframework.h"
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070040
41#include <algorithm>
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060042#include <limits.h>
43#include <unordered_set>
Tony Barbour300a6082015-04-07 13:44:53 -060044
Mark Lobodzinski3780e142015-05-14 15:08:13 -050045#define GLM_FORCE_RADIANS
46#include "glm/glm.hpp"
47#include <glm/gtc/matrix_transform.hpp>
48
49//--------------------------------------------------------------------------------------
50// Mesh and VertexFormat Data
51//--------------------------------------------------------------------------------------
Karl Schultz6addd812016-02-02 17:17:23 -070052struct Vertex {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070053 float posX, posY, posZ, posW; // Position data
54 float r, g, b, a; // Color
Mark Lobodzinski3780e142015-05-14 15:08:13 -050055};
56
Karl Schultz6addd812016-02-02 17:17:23 -070057#define XYZ1(_x_, _y_, _z_) (_x_), (_y_), (_z_), 1.f
Mark Lobodzinski3780e142015-05-14 15:08:13 -050058
59typedef enum _BsoFailSelect {
Karl Schultz6addd812016-02-02 17:17:23 -070060 BsoFailNone = 0x00000000,
61 BsoFailLineWidth = 0x00000001,
62 BsoFailDepthBias = 0x00000002,
63 BsoFailViewport = 0x00000004,
64 BsoFailScissor = 0x00000008,
65 BsoFailBlend = 0x00000010,
66 BsoFailDepthBounds = 0x00000020,
67 BsoFailStencilReadMask = 0x00000040,
68 BsoFailStencilWriteMask = 0x00000080,
69 BsoFailStencilReference = 0x00000100,
Mark Muellerd4914412016-06-13 17:52:06 -060070 BsoFailCmdClearAttachments = 0x00000200,
Tobin Ehlis379ba3b2016-07-19 11:22:29 -060071 BsoFailIndexBuffer = 0x00000400,
Mark Lobodzinski3780e142015-05-14 15:08:13 -050072} BsoFailSelect;
73
74struct vktriangle_vs_uniform {
75 // Must start with MVP
Karl Schultz6addd812016-02-02 17:17:23 -070076 float mvp[4][4];
77 float position[3][4];
78 float color[3][4];
Mark Lobodzinski3780e142015-05-14 15:08:13 -050079};
80
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070081static const char bindStateVertShaderText[] =
82 "#version 450\n"
83 "vec2 vertices[3];\n"
84 "out gl_PerVertex {\n"
85 " vec4 gl_Position;\n"
86 "};\n"
87 "void main() {\n"
88 " vertices[0] = vec2(-1.0, -1.0);\n"
89 " vertices[1] = vec2( 1.0, -1.0);\n"
90 " vertices[2] = vec2( 0.0, 1.0);\n"
91 " gl_Position = vec4(vertices[gl_VertexIndex % 3], 0.0, 1.0);\n"
92 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -050093
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070094static const char bindStateFragShaderText[] =
95 "#version 450\n"
96 "\n"
97 "layout(location = 0) out vec4 uFragColor;\n"
98 "void main(){\n"
99 " uFragColor = vec4(0,1,0,1);\n"
100 "}\n";
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500101
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600102static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
103 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
104 void *pUserData);
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600105
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600106// ErrorMonitor Usage:
107//
Dave Houltonfbf52152017-01-06 12:55:29 -0700108// Call SetDesiredFailureMsg with a string to be compared against all
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600109// encountered log messages, or a validation error enum identifying
110// desired error message. Passing NULL or VALIDATION_ERROR_MAX_ENUM
111// will match all log messages. logMsg will return true for skipCall
112// only if msg is matched or NULL.
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600113//
Dave Houltonfbf52152017-01-06 12:55:29 -0700114// Call VerifyFound to determine if all desired failure messages
115// were encountered. Call VerifyNotFound to determine if any unexpected
116// failure was encountered.
Tony Barbour300a6082015-04-07 13:44:53 -0600117class ErrorMonitor {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700118 public:
Karl Schultz6addd812016-02-02 17:17:23 -0700119 ErrorMonitor() {
Dave Houltonfbf52152017-01-06 12:55:29 -0700120 test_platform_thread_create_mutex(&mutex_);
121 test_platform_thread_lock_mutex(&mutex_);
122 Reset();
123 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600124 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600125
Dave Houltonfbf52152017-01-06 12:55:29 -0700126 ~ErrorMonitor() { test_platform_thread_delete_mutex(&mutex_); }
Dustin Graves48458142016-04-29 16:11:55 -0600127
Dave Houltonfbf52152017-01-06 12:55:29 -0700128 // Set monitor to pristine state
129 void Reset() {
130 message_flags_ = VK_DEBUG_REPORT_ERROR_BIT_EXT;
131 bailout_ = NULL;
132 message_found_ = VK_FALSE;
133 failure_message_strings_.clear();
134 desired_message_strings_.clear();
135 desired_message_ids_.clear();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700136 ignore_message_strings_.clear();
Dave Houltonfbf52152017-01-06 12:55:29 -0700137 other_messages_.clear();
138 message_outstanding_count_ = 0;
139 }
140
141 // ErrorMonitor will look for an error message containing the specified string(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700142 void SetDesiredFailureMsg(const VkFlags msgFlags, const char *const msgString) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700143 test_platform_thread_lock_mutex(&mutex_);
144 desired_message_strings_.insert(msgString);
145 message_flags_ |= msgFlags;
146 message_outstanding_count_++;
147 test_platform_thread_unlock_mutex(&mutex_);
Tony Barbour300a6082015-04-07 13:44:53 -0600148 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600149
Jeremy Hayesde6d96c2017-02-01 15:22:32 -0700150 // ErrorMonitor will look for an error message containing the specified string(s)
151 template <typename Iter>
152 void SetDesiredFailureMsg(const VkFlags msgFlags, Iter iter, const Iter end) {
153 for (; iter != end; ++iter) {
154 SetDesiredFailureMsg(msgFlags, *iter);
155 }
156 }
157
Dave Houltonfbf52152017-01-06 12:55:29 -0700158 // ErrorMonitor will look for a message ID matching the specified one(s)
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700159 void SetDesiredFailureMsg(const VkFlags msgFlags, const UNIQUE_VALIDATION_ERROR_CODE msg_id) {
Dave Houltonfbf52152017-01-06 12:55:29 -0700160 test_platform_thread_lock_mutex(&mutex_);
161 desired_message_ids_.insert(msg_id);
162 message_flags_ |= msgFlags;
163 message_outstanding_count_++;
164 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600165 }
166
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700167 // Set an error that the error monitor will ignore. Do not use this function if you are creating a new test.
168 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
169 // function and its definition.
170 void SetUnexpectedError(const char *const msg) {
171 test_platform_thread_lock_mutex(&mutex_);
172
173 ignore_message_strings_.emplace_back(msg);
174
175 test_platform_thread_unlock_mutex(&mutex_);
176 }
177
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700178 VkBool32 CheckForDesiredMsg(const uint32_t message_code, const char *const msgString) {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600179 VkBool32 result = VK_FALSE;
Dave Houltonfbf52152017-01-06 12:55:29 -0700180 test_platform_thread_lock_mutex(&mutex_);
181 if (bailout_ != NULL) {
182 *bailout_ = true;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600183 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600184 string errorString(msgString);
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600185 bool found_expected = false;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600186
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700187 if (!IgnoreMessage(errorString)) {
188 for (auto desired_msg : desired_message_strings_) {
189 if (desired_msg.length() == 0) {
190 // An empty desired_msg string "" indicates a positive test - not expecting an error.
191 // Return true to avoid calling layers/driver with this error.
192 // And don't erase the "" string, so it remains if another error is found.
193 result = VK_TRUE;
194 found_expected = true;
195 message_found_ = VK_TRUE;
196 failure_message_strings_.insert(errorString);
197 } else if (errorString.find(desired_msg) != string::npos) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600198 found_expected = true;
Dave Houltonfbf52152017-01-06 12:55:29 -0700199 message_outstanding_count_--;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700200 failure_message_strings_.insert(errorString);
Dave Houltonfbf52152017-01-06 12:55:29 -0700201 message_found_ = VK_TRUE;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700202 result = VK_TRUE;
203 // We only want one match for each expected error so remove from set here
204 // Since we're about the break the loop it's ok to remove from set we're iterating over
205 desired_message_strings_.erase(desired_msg);
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600206 break;
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600207 }
208 }
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700209 for (auto desired_id : desired_message_ids_) {
210 if (desired_id == VALIDATION_ERROR_MAX_ENUM) {
211 // A message ID set to MAX_ENUM indicates a positive test - not expecting an error.
212 // Return true to avoid calling layers/driver with this error.
213 result = VK_TRUE;
214 } else if (desired_id == message_code) {
215 // Double-check that the string matches the error enum
216 if (errorString.find(validation_error_map[desired_id]) != string::npos) {
217 found_expected = true;
218 message_outstanding_count_--;
219 result = VK_TRUE;
220 message_found_ = VK_TRUE;
221 desired_message_ids_.erase(desired_id);
222 break;
223 } else {
224 // Treat this message as a regular unexpected error, but print a warning jic
225 printf("Message (%s) from MessageID %d does not correspond to expected message from error Database (%s)\n",
226 errorString.c_str(), desired_id, validation_error_map[desired_id]);
227 }
228 }
229 }
230
231 if (!found_expected) {
232 printf("Unexpected: %s\n", msgString);
233 other_messages_.push_back(errorString);
234 }
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600235 }
236
Dave Houltonfbf52152017-01-06 12:55:29 -0700237 test_platform_thread_unlock_mutex(&mutex_);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600238 return result;
Mike Stroyanaccf7692015-05-12 16:00:45 -0600239 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600240
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700241 vector<string> GetOtherFailureMsgs(void) const { return other_messages_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600242
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700243 VkDebugReportFlagsEXT GetMessageFlags(void) const { return message_flags_; }
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600244
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700245 VkBool32 AnyDesiredMsgFound(void) const { return message_found_; }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600246
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700247 VkBool32 AllDesiredMsgsFound(void) const { return (0 == message_outstanding_count_); }
Dave Houltonfbf52152017-01-06 12:55:29 -0700248
249 void SetBailout(bool *bailout) { bailout_ = bailout; }
Tony Barbour300a6082015-04-07 13:44:53 -0600250
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700251 void DumpFailureMsgs(void) const {
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600252 vector<string> otherMsgs = GetOtherFailureMsgs();
Tony Barbour59b42282016-11-03 13:31:28 -0600253 if (otherMsgs.size()) {
254 cout << "Other error messages logged for this test were:" << endl;
255 for (auto iter = otherMsgs.begin(); iter != otherMsgs.end(); iter++) {
256 cout << " " << *iter << endl;
257 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -0600258 }
259 }
260
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600261 // Helpers
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200262
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600263 // ExpectSuccess now takes an optional argument allowing a custom combination of debug flags
Jeremy Hayesf967b0e2017-01-27 11:59:02 -0700264 void ExpectSuccess(VkDebugReportFlagsEXT const message_flag_mask = VK_DEBUG_REPORT_ERROR_BIT_EXT) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600265 // Match ANY message matching specified type
266 SetDesiredFailureMsg(message_flag_mask, "");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700267 message_flags_ = message_flag_mask; // override mask handling in SetDesired...
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200268 }
269
270 void VerifyFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600271 // Not seeing the desired message is a failure. /Before/ throwing, dump any other messages.
Dave Houltonfbf52152017-01-06 12:55:29 -0700272 if (!AllDesiredMsgsFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200273 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700274 for (auto desired_msg : desired_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700275 ADD_FAILURE() << "Did not receive expected error '" << desired_msg << "'";
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600276 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700277 for (auto desired_id : desired_message_ids_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700278 ADD_FAILURE() << "Did not receive expected error ENUM '" << desired_id << "'";
Tony Barbour59b42282016-11-03 13:31:28 -0600279 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200280 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700281 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200282 }
283
284 void VerifyNotFound() {
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600285 // ExpectSuccess() configured us to match anything. Any error is a failure.
Dave Houltonfbf52152017-01-06 12:55:29 -0700286 if (AnyDesiredMsgFound()) {
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200287 DumpFailureMsgs();
Dave Houltonfbf52152017-01-06 12:55:29 -0700288 for (auto msg : failure_message_strings_) {
Dave Houltond5507dd2017-01-24 15:29:02 -0700289 ADD_FAILURE() << "Expected to succeed but got error: " << msg;
Tobin Ehlise2eeffa2016-09-21 17:32:26 -0600290 }
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200291 }
Dave Houltonfbf52152017-01-06 12:55:29 -0700292 Reset();
Chris Forbes8f36a8a2016-04-07 13:21:07 +1200293 }
294
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700295 private:
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700296 // TODO: This is stopgap to block new unexpected errors from being introduced. The long-term goal is to remove the use of this
297 // function and its definition.
298 bool IgnoreMessage(std::string const &msg) const {
299 if (ignore_message_strings_.empty()) {
300 return false;
301 }
302
303 return std::find_if(ignore_message_strings_.begin(), ignore_message_strings_.end(), [&msg](std::string const &str) {
304 return msg.find(str) != std::string::npos;
305 }) != ignore_message_strings_.end();
306 }
307
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700308 VkFlags message_flags_;
309 std::unordered_set<uint32_t> desired_message_ids_;
310 std::unordered_set<string> desired_message_strings_;
311 std::unordered_set<string> failure_message_strings_;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -0700312 std::vector<std::string> ignore_message_strings_;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -0700313 vector<string> other_messages_;
314 test_platform_thread_mutex mutex_;
315 bool *bailout_;
316 VkBool32 message_found_;
317 int message_outstanding_count_;
Tony Barbour300a6082015-04-07 13:44:53 -0600318};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500319
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600320static VKAPI_ATTR VkBool32 VKAPI_CALL myDbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject,
321 size_t location, int32_t msgCode, const char *pLayerPrefix, const char *pMsg,
322 void *pUserData) {
Mark Lobodzinski7a588452016-08-03 14:04:26 -0600323 ErrorMonitor *errMonitor = (ErrorMonitor *)pUserData;
324 if (msgFlags & errMonitor->GetMessageFlags()) {
Mark Lobodzinski629d47b2016-10-18 13:34:58 -0600325 return errMonitor->CheckForDesiredMsg(msgCode, pMsg);
Tony Barbour0b4d9562015-04-09 10:48:04 -0600326 }
Courtney Goeltzenleuchter06640832015-09-04 13:52:24 -0600327 return false;
Tony Barbour300a6082015-04-07 13:44:53 -0600328}
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500329
Karl Schultz6addd812016-02-02 17:17:23 -0700330class VkLayerTest : public VkRenderFramework {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700331 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600332 void VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask);
333 void GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet,
Karl Schultz6addd812016-02-02 17:17:23 -0700334 BsoFailSelect failMask);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600335 void GenericDrawPreparation(VkPipelineObj &pipelineobj, VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
336 GenericDrawPreparation(m_commandBuffer, pipelineobj, descriptorSet, failMask);
Karl Schultz6addd812016-02-02 17:17:23 -0700337 }
Tony Barbour300a6082015-04-07 13:44:53 -0600338
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600339 void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance) {
340 m_commandBuffer->Draw(vertexCount, instanceCount, firstVertex, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700341 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600342 void DrawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset,
Karl Schultz6addd812016-02-02 17:17:23 -0700343 uint32_t firstInstance) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600344 m_commandBuffer->DrawIndexed(indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
Karl Schultz6addd812016-02-02 17:17:23 -0700345 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600346 void QueueCommandBuffer(bool checkSuccess = true) { m_commandBuffer->QueueCommandBuffer(checkSuccess); }
347 void QueueCommandBuffer(const VkFence &fence) { m_commandBuffer->QueueCommandBuffer(fence); }
348 void BindVertexBuffer(VkConstantBufferObj *vertexBuffer, VkDeviceSize offset, uint32_t binding) {
Karl Schultz6addd812016-02-02 17:17:23 -0700349 m_commandBuffer->BindVertexBuffer(vertexBuffer, offset, binding);
350 }
351 void BindIndexBuffer(VkIndexBufferObj *indexBuffer, VkDeviceSize offset) {
352 m_commandBuffer->BindIndexBuffer(indexBuffer, offset);
353 }
354
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700355 protected:
Karl Schultz6addd812016-02-02 17:17:23 -0700356 ErrorMonitor *m_errorMonitor;
Ian Elliott2c1daf52016-05-12 09:41:46 -0600357 bool m_enableWSI;
Tony Barbour300a6082015-04-07 13:44:53 -0600358
359 virtual void SetUp() {
Courtney Goeltzenleuchtercd69eee2015-07-06 09:10:47 -0600360 std::vector<const char *> instance_layer_names;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600361 std::vector<const char *> instance_extension_names;
362 std::vector<const char *> device_extension_names;
Tony Barbour3fdff9e2015-04-23 12:55:36 -0600363
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -0700364 instance_extension_names.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
Courtney Goeltzenleuchterc2b06fe2015-06-16 15:59:11 -0600365 /*
366 * Since CreateDbgMsgCallback is an instance level extension call
367 * any extension / layer that utilizes that feature also needs
368 * to be enabled at create instance time.
369 */
Karl Schultz6addd812016-02-02 17:17:23 -0700370 // Use Threading layer first to protect others from
371 // ThreadCommandBufferCollision test
Courtney Goeltzenleuchter76885322016-02-06 17:11:22 -0700372 instance_layer_names.push_back("VK_LAYER_GOOGLE_threading");
Tobin Ehlis24aab042016-03-24 10:54:18 -0600373 instance_layer_names.push_back("VK_LAYER_LUNARG_parameter_validation");
Michael Lentine03107b42015-12-11 10:49:51 -0800374 instance_layer_names.push_back("VK_LAYER_LUNARG_object_tracker");
Tobin Ehlisc96f8062016-03-09 16:12:48 -0700375 instance_layer_names.push_back("VK_LAYER_LUNARG_core_validation");
Ian Elliotte48a1382016-04-28 14:22:58 -0600376 instance_layer_names.push_back("VK_LAYER_LUNARG_swapchain");
Dustin Graveseaa78cd2016-01-26 16:30:22 -0700377 instance_layer_names.push_back("VK_LAYER_GOOGLE_unique_objects");
Courtney Goeltzenleuchterd971b612015-06-17 20:51:59 -0600378
Ian Elliott2c1daf52016-05-12 09:41:46 -0600379 if (m_enableWSI) {
380 instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
381 device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
382#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
383#if defined(VK_USE_PLATFORM_ANDROID_KHR)
384 instance_extension_names.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700385#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600386#if defined(VK_USE_PLATFORM_MIR_KHR)
387 instance_extension_names.push_back(VK_KHR_MIR_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700388#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600389#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
390 instance_extension_names.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700391#endif // VK_USE_PLATFORM_WAYLAND_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600392#if defined(VK_USE_PLATFORM_WIN32_KHR)
393 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700394#endif // VK_USE_PLATFORM_WIN32_KHR
395#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott2c1daf52016-05-12 09:41:46 -0600396#if defined(VK_USE_PLATFORM_XCB_KHR)
397 instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
398#elif defined(VK_USE_PLATFORM_XLIB_KHR)
399 instance_extension_names.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700400#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott2c1daf52016-05-12 09:41:46 -0600401 }
402
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600403 this->app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
Tony Barbour300a6082015-04-07 13:44:53 -0600404 this->app_info.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800405 this->app_info.pApplicationName = "layer_tests";
406 this->app_info.applicationVersion = 1;
Tony Barbour300a6082015-04-07 13:44:53 -0600407 this->app_info.pEngineName = "unittest";
408 this->app_info.engineVersion = 1;
Jon Ashburnc5012ff2016-03-22 13:57:46 -0600409 this->app_info.apiVersion = VK_API_VERSION_1_0;
Tony Barbour300a6082015-04-07 13:44:53 -0600410
Tony Barbour15524c32015-04-29 17:34:29 -0600411 m_errorMonitor = new ErrorMonitor;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600412 InitFramework(instance_layer_names, instance_extension_names, device_extension_names, myDbgFunc, m_errorMonitor);
Tony Barbour300a6082015-04-07 13:44:53 -0600413 }
414
415 virtual void TearDown() {
416 // Clean up resources before we reset
Tony Barbour300a6082015-04-07 13:44:53 -0600417 ShutdownFramework();
Tony Barbour0b4d9562015-04-09 10:48:04 -0600418 delete m_errorMonitor;
Tony Barbour300a6082015-04-07 13:44:53 -0600419 }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600420
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600421 VkLayerTest() { m_enableWSI = false; }
Tony Barbour300a6082015-04-07 13:44:53 -0600422};
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500423
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600424void VkLayerTest::VKTriangleTest(const char *vertShaderText, const char *fragShaderText, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500425 // Create identity matrix
426 int i;
427 struct vktriangle_vs_uniform data;
428
429 glm::mat4 Projection = glm::mat4(1.0f);
Karl Schultz6addd812016-02-02 17:17:23 -0700430 glm::mat4 View = glm::mat4(1.0f);
431 glm::mat4 Model = glm::mat4(1.0f);
432 glm::mat4 MVP = Projection * View * Model;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500433 const int matrixSize = sizeof(MVP);
Karl Schultz6addd812016-02-02 17:17:23 -0700434 const int bufSize = sizeof(vktriangle_vs_uniform) / sizeof(float);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500435
436 memcpy(&data.mvp, &MVP[0][0], matrixSize);
437
Karl Schultz6addd812016-02-02 17:17:23 -0700438 static const Vertex tri_data[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600439 {XYZ1(-1, -1, 0), XYZ1(1.f, 0.f, 0.f)}, {XYZ1(1, -1, 0), XYZ1(0.f, 1.f, 0.f)}, {XYZ1(0, 1, 0), XYZ1(0.f, 0.f, 1.f)},
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500440 };
441
Karl Schultz6addd812016-02-02 17:17:23 -0700442 for (i = 0; i < 3; i++) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500443 data.position[i][0] = tri_data[i].posX;
444 data.position[i][1] = tri_data[i].posY;
445 data.position[i][2] = tri_data[i].posZ;
446 data.position[i][3] = tri_data[i].posW;
Karl Schultz6addd812016-02-02 17:17:23 -0700447 data.color[i][0] = tri_data[i].r;
448 data.color[i][1] = tri_data[i].g;
449 data.color[i][2] = tri_data[i].b;
450 data.color[i][3] = tri_data[i].a;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500451 }
452
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500453 ASSERT_NO_FATAL_FAILURE(InitViewport());
454
Chris Forbesbcfaadd2016-09-16 14:13:53 +1200455 VkConstantBufferObj constantBuffer(m_device, bufSize * 2, sizeof(float), (const void *)&data,
456 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500457
Karl Schultz6addd812016-02-02 17:17:23 -0700458 VkShaderObj vs(m_device, vertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600459 VkShaderObj ps(m_device, fragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500460
461 VkPipelineObj pipelineobj(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +0800462 pipelineobj.AddColorAttachment();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500463 pipelineobj.AddShader(&vs);
464 pipelineobj.AddShader(&ps);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600465 if (failMask & BsoFailLineWidth) {
466 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_LINE_WIDTH);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600467 VkPipelineInputAssemblyStateCreateInfo ia_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600468 ia_state.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600469 ia_state.topology = VK_PRIMITIVE_TOPOLOGY_LINE_LIST;
470 pipelineobj.SetInputAssembly(&ia_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600471 }
472 if (failMask & BsoFailDepthBias) {
473 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BIAS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600474 VkPipelineRasterizationStateCreateInfo rs_state = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600475 rs_state.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600476 rs_state.depthBiasEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -0600477 rs_state.lineWidth = 1.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600478 pipelineobj.SetRasterization(&rs_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600479 }
Rene Lindsayacbf5e62016-12-15 18:47:11 -0700480 // Viewport and scissors must stay in sync or other errors will occur than
Karl Schultz6addd812016-02-02 17:17:23 -0700481 // the ones we want
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600482 if (failMask & BsoFailViewport) {
483 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_VIEWPORT);
484 }
485 if (failMask & BsoFailScissor) {
486 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_SCISSOR);
487 }
488 if (failMask & BsoFailBlend) {
489 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_BLEND_CONSTANTS);
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600490 VkPipelineColorBlendAttachmentState att_state = {};
491 att_state.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
492 att_state.blendEnable = VK_TRUE;
493 pipelineobj.AddColorAttachment(0, &att_state);
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600494 }
495 if (failMask & BsoFailDepthBounds) {
496 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_DEPTH_BOUNDS);
497 }
498 if (failMask & BsoFailStencilReadMask) {
499 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_COMPARE_MASK);
500 }
501 if (failMask & BsoFailStencilWriteMask) {
502 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_WRITE_MASK);
503 }
504 if (failMask & BsoFailStencilReference) {
505 pipelineobj.MakeDynamic(VK_DYNAMIC_STATE_STENCIL_REFERENCE);
506 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500507
508 VkDescriptorSetObj descriptorSet(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600509 descriptorSet.AppendBuffer(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, constantBuffer);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500510
511 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barbour552f6c02016-12-21 14:34:07 -0700512 m_commandBuffer->BeginCommandBuffer();
513 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500514
Tony Barbourfe3351b2015-07-28 10:17:20 -0600515 GenericDrawPreparation(pipelineobj, descriptorSet, failMask);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500516
517 // render triangle
Tobin Ehlis379ba3b2016-07-19 11:22:29 -0600518 if (failMask & BsoFailIndexBuffer) {
519 // Use DrawIndexed w/o an index buffer bound
520 DrawIndexed(3, 1, 0, 0, 0);
521 } else {
522 Draw(3, 1, 0, 0);
523 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500524
Mark Muellerd4914412016-06-13 17:52:06 -0600525 if (failMask & BsoFailCmdClearAttachments) {
526 VkClearAttachment color_attachment = {};
527 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700528 color_attachment.colorAttachment = 1; // Someone who knew what they were doing would use 0 for the index;
Mark Muellerd4914412016-06-13 17:52:06 -0600529 VkClearRect clear_rect = {{{0, 0}, {static_cast<uint32_t>(m_width), static_cast<uint32_t>(m_height)}}, 0, 0};
530
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600531 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Muellerd4914412016-06-13 17:52:06 -0600532 }
533
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500534 // finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -0700535 m_commandBuffer->EndRenderPass();
536 m_commandBuffer->EndCommandBuffer();
Tony Barbourfe3351b2015-07-28 10:17:20 -0600537 QueueCommandBuffer();
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500538}
539
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600540void VkLayerTest::GenericDrawPreparation(VkCommandBufferObj *commandBuffer, VkPipelineObj &pipelineobj,
541 VkDescriptorSetObj &descriptorSet, BsoFailSelect failMask) {
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500542 if (m_depthStencil->Initialized()) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600543 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, m_depthStencil);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500544 } else {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600545 commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500546 }
547
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800548 commandBuffer->PrepareAttachments();
Karl Schultz6addd812016-02-02 17:17:23 -0700549 // Make sure depthWriteEnable is set so that Depth fail test will work
550 // correctly
551 // Make sure stencilTestEnable is set so that Stencil fail test will work
552 // correctly
Tony Barboureb254902015-07-15 12:50:33 -0600553 VkStencilOpState stencil = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +0800554 stencil.failOp = VK_STENCIL_OP_KEEP;
555 stencil.passOp = VK_STENCIL_OP_KEEP;
556 stencil.depthFailOp = VK_STENCIL_OP_KEEP;
557 stencil.compareOp = VK_COMPARE_OP_NEVER;
Tony Barboureb254902015-07-15 12:50:33 -0600558
559 VkPipelineDepthStencilStateCreateInfo ds_ci = {};
560 ds_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600561 ds_ci.pNext = NULL;
562 ds_ci.depthTestEnable = VK_FALSE;
563 ds_ci.depthWriteEnable = VK_TRUE;
564 ds_ci.depthCompareOp = VK_COMPARE_OP_NEVER;
565 ds_ci.depthBoundsTestEnable = VK_FALSE;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600566 if (failMask & BsoFailDepthBounds) {
567 ds_ci.depthBoundsTestEnable = VK_TRUE;
Tobin Ehlis21c88352016-05-26 06:15:45 -0600568 ds_ci.maxDepthBounds = 0.0f;
569 ds_ci.minDepthBounds = 0.0f;
Tobin Ehlis7a1d2352016-03-28 11:18:19 -0600570 }
Courtney Goeltzenleuchter507ba972015-09-30 16:16:57 -0600571 ds_ci.stencilTestEnable = VK_TRUE;
572 ds_ci.front = stencil;
573 ds_ci.back = stencil;
Tony Barboureb254902015-07-15 12:50:33 -0600574
Tobin Ehlis4bf96d12015-06-25 11:58:41 -0600575 pipelineobj.SetDepthStencil(&ds_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -0600576 pipelineobj.SetViewport(m_viewports);
577 pipelineobj.SetScissor(m_scissors);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800578 descriptorSet.CreateVKDescriptorSet(commandBuffer);
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600579 VkResult err = pipelineobj.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Cody Northrop29a08f22015-08-27 10:20:35 -0600580 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +0800581 commandBuffer->BindPipeline(pipelineobj);
582 commandBuffer->BindDescriptorSet(descriptorSet);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500583}
584
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600585class VkPositiveLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700586 public:
587 protected:
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600588};
589
Ian Elliott2c1daf52016-05-12 09:41:46 -0600590class VkWsiEnabledLayerTest : public VkLayerTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700591 public:
592 protected:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600593 VkWsiEnabledLayerTest() { m_enableWSI = true; }
Ian Elliott2c1daf52016-05-12 09:41:46 -0600594};
595
Mark Muellerdfe37552016-07-07 14:47:42 -0600596class VkBufferTest {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700597 public:
Mark Muellerdfe37552016-07-07 14:47:42 -0600598 enum eTestEnFlags {
599 eDoubleDelete,
600 eInvalidDeviceOffset,
601 eInvalidMemoryOffset,
602 eBindNullBuffer,
603 eFreeInvalidHandle,
Mark Mueller4042b652016-09-05 22:52:21 -0600604 eNone,
Mark Muellerdfe37552016-07-07 14:47:42 -0600605 };
606
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600607 enum eTestConditions { eOffsetAlignment = 1 };
Mark Muellerdfe37552016-07-07 14:47:42 -0600608
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600609 static bool GetTestConditionValid(VkDeviceObj *aVulkanDevice, eTestEnFlags aTestFlag, VkBufferUsageFlags aBufferUsage = 0) {
610 if (eInvalidDeviceOffset != aTestFlag && eInvalidMemoryOffset != aTestFlag) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600611 return true;
612 }
613 VkDeviceSize offset_limit = 0;
614 if (eInvalidMemoryOffset == aTestFlag) {
615 VkBuffer vulkanBuffer;
616 VkBufferCreateInfo buffer_create_info = {};
617 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
618 buffer_create_info.size = 32;
619 buffer_create_info.usage = aBufferUsage;
620
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600621 vkCreateBuffer(aVulkanDevice->device(), &buffer_create_info, nullptr, &vulkanBuffer);
Mark Mueller4042b652016-09-05 22:52:21 -0600622 VkMemoryRequirements memory_reqs = {};
Mark Muellerdfe37552016-07-07 14:47:42 -0600623
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600624 vkGetBufferMemoryRequirements(aVulkanDevice->device(), vulkanBuffer, &memory_reqs);
Mark Muellerdfe37552016-07-07 14:47:42 -0600625 vkDestroyBuffer(aVulkanDevice->device(), vulkanBuffer, nullptr);
626 offset_limit = memory_reqs.alignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600627 } else if ((VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT) & aBufferUsage) {
628 offset_limit = aVulkanDevice->props.limits.minTexelBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600629 } else if (VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600630 offset_limit = aVulkanDevice->props.limits.minUniformBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600631 } else if (VK_BUFFER_USAGE_STORAGE_BUFFER_BIT & aBufferUsage) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600632 offset_limit = aVulkanDevice->props.limits.minStorageBufferOffsetAlignment;
Mark Muellerdfe37552016-07-07 14:47:42 -0600633 }
634 if (eOffsetAlignment < offset_limit) {
635 return true;
636 }
637 return false;
638 }
639
640 // A constructor which performs validation tests within construction.
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600641 VkBufferTest(VkDeviceObj *aVulkanDevice, VkBufferUsageFlags aBufferUsage, eTestEnFlags aTestFlag = eNone)
642 : AllocateCurrent(false), BoundCurrent(false), CreateCurrent(false), VulkanDevice(aVulkanDevice->device()) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600643 if (eBindNullBuffer == aTestFlag) {
644 VulkanMemory = 0;
645 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, 0);
646 } else {
647 VkBufferCreateInfo buffer_create_info = {};
648 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
649 buffer_create_info.size = 32;
650 buffer_create_info.usage = aBufferUsage;
651
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600652 vkCreateBuffer(VulkanDevice, &buffer_create_info, nullptr, &VulkanBuffer);
Mark Muellerdfe37552016-07-07 14:47:42 -0600653
654 CreateCurrent = true;
655
656 VkMemoryRequirements memory_requirements;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600657 vkGetBufferMemoryRequirements(VulkanDevice, VulkanBuffer, &memory_requirements);
Mark Muellerdfe37552016-07-07 14:47:42 -0600658
659 VkMemoryAllocateInfo memory_allocate_info = {};
660 memory_allocate_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Stratton77a0d592017-02-17 13:14:13 -0800661 memory_allocate_info.allocationSize = memory_requirements.size + eOffsetAlignment;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600662 bool pass = aVulkanDevice->phy().set_memory_type(memory_requirements.memoryTypeBits, &memory_allocate_info,
663 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Muellerdfe37552016-07-07 14:47:42 -0600664 if (!pass) {
665 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
666 return;
667 }
668
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600669 vkAllocateMemory(VulkanDevice, &memory_allocate_info, NULL, &VulkanMemory);
Mark Muellerdfe37552016-07-07 14:47:42 -0600670 AllocateCurrent = true;
671 // NB: 1 is intentionally an invalid offset value
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600672 const bool offset_en = eInvalidDeviceOffset == aTestFlag || eInvalidMemoryOffset == aTestFlag;
673 vkBindBufferMemory(VulkanDevice, VulkanBuffer, VulkanMemory, offset_en ? eOffsetAlignment : 0);
Mark Muellerdfe37552016-07-07 14:47:42 -0600674 BoundCurrent = true;
675
676 InvalidDeleteEn = (eFreeInvalidHandle == aTestFlag);
677 }
678 }
679
680 ~VkBufferTest() {
681 if (CreateCurrent) {
682 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
683 }
684 if (AllocateCurrent) {
685 if (InvalidDeleteEn) {
686 union {
687 VkDeviceMemory device_memory;
688 unsigned long long index_access;
689 } bad_index;
690
691 bad_index.device_memory = VulkanMemory;
692 bad_index.index_access++;
693
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600694 vkFreeMemory(VulkanDevice, bad_index.device_memory, nullptr);
Mark Muellerdfe37552016-07-07 14:47:42 -0600695 }
696 vkFreeMemory(VulkanDevice, VulkanMemory, nullptr);
697 }
698 }
699
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600700 bool GetBufferCurrent() { return AllocateCurrent && BoundCurrent && CreateCurrent; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600701
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600702 const VkBuffer &GetBuffer() { return VulkanBuffer; }
Mark Muellerdfe37552016-07-07 14:47:42 -0600703
704 void TestDoubleDestroy() {
705 // Destroy the buffer but leave the flag set, which will cause
706 // the buffer to be destroyed again in the destructor.
707 vkDestroyBuffer(VulkanDevice, VulkanBuffer, nullptr);
708 }
709
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700710 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600711 bool AllocateCurrent;
712 bool BoundCurrent;
713 bool CreateCurrent;
714 bool InvalidDeleteEn;
715
716 VkBuffer VulkanBuffer;
717 VkDevice VulkanDevice;
718 VkDeviceMemory VulkanMemory;
Mark Muellerdfe37552016-07-07 14:47:42 -0600719};
720
721class VkVerticesObj {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700722 public:
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600723 VkVerticesObj(VkDeviceObj *aVulkanDevice, unsigned aAttributeCount, unsigned aBindingCount, unsigned aByteStride,
Mark Muellerdfe37552016-07-07 14:47:42 -0600724 VkDeviceSize aVertexCount, const float *aVerticies)
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700725 : BoundCurrent(false),
726 AttributeCount(aAttributeCount),
727 BindingCount(aBindingCount),
728 BindId(BindIdGenerator),
Mark Muellerdfe37552016-07-07 14:47:42 -0600729 PipelineVertexInputStateCreateInfo(),
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600730 VulkanMemoryBuffer(aVulkanDevice, 1, static_cast<int>(aByteStride * aVertexCount),
731 reinterpret_cast<const void *>(aVerticies), VK_BUFFER_USAGE_VERTEX_BUFFER_BIT) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700732 BindIdGenerator++; // NB: This can wrap w/misuse
Mark Muellerdfe37552016-07-07 14:47:42 -0600733
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600734 VertexInputAttributeDescription = new VkVertexInputAttributeDescription[AttributeCount];
735 VertexInputBindingDescription = new VkVertexInputBindingDescription[BindingCount];
Mark Muellerdfe37552016-07-07 14:47:42 -0600736
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600737 PipelineVertexInputStateCreateInfo.pVertexAttributeDescriptions = VertexInputAttributeDescription;
738 PipelineVertexInputStateCreateInfo.vertexAttributeDescriptionCount = AttributeCount;
739 PipelineVertexInputStateCreateInfo.pVertexBindingDescriptions = VertexInputBindingDescription;
740 PipelineVertexInputStateCreateInfo.vertexBindingDescriptionCount = BindingCount;
741 PipelineVertexInputStateCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -0600742
743 unsigned i = 0;
744 do {
745 VertexInputAttributeDescription[i].binding = BindId;
746 VertexInputAttributeDescription[i].location = i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600747 VertexInputAttributeDescription[i].format = VK_FORMAT_R32G32B32_SFLOAT;
748 VertexInputAttributeDescription[i].offset = sizeof(float) * aByteStride;
Mark Muellerdfe37552016-07-07 14:47:42 -0600749 i++;
750 } while (AttributeCount < i);
751
752 i = 0;
753 do {
754 VertexInputBindingDescription[i].binding = BindId;
755 VertexInputBindingDescription[i].stride = aByteStride;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600756 VertexInputBindingDescription[i].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
Mark Muellerdfe37552016-07-07 14:47:42 -0600757 i++;
758 } while (BindingCount < i);
759 }
760
761 ~VkVerticesObj() {
762 if (VertexInputAttributeDescription) {
763 delete[] VertexInputAttributeDescription;
764 }
765 if (VertexInputBindingDescription) {
766 delete[] VertexInputBindingDescription;
767 }
768 }
769
770 bool AddVertexInputToPipe(VkPipelineObj &aPipelineObj) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600771 aPipelineObj.AddVertexInputAttribs(VertexInputAttributeDescription, AttributeCount);
772 aPipelineObj.AddVertexInputBindings(VertexInputBindingDescription, BindingCount);
Mark Muellerdfe37552016-07-07 14:47:42 -0600773 return true;
774 }
775
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600776 void BindVertexBuffers(VkCommandBuffer aCommandBuffer, unsigned aOffsetCount = 0, VkDeviceSize *aOffsetList = nullptr) {
Mark Muellerdfe37552016-07-07 14:47:42 -0600777 VkDeviceSize *offsetList;
778 unsigned offsetCount;
779
780 if (aOffsetCount) {
781 offsetList = aOffsetList;
782 offsetCount = aOffsetCount;
783 } else {
784 offsetList = new VkDeviceSize[1]();
785 offsetCount = 1;
786 }
787
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600788 vkCmdBindVertexBuffers(aCommandBuffer, BindId, offsetCount, &VulkanMemoryBuffer.handle(), offsetList);
Mark Muellerdfe37552016-07-07 14:47:42 -0600789 BoundCurrent = true;
790
791 if (!aOffsetCount) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600792 delete[] offsetList;
Mark Muellerdfe37552016-07-07 14:47:42 -0600793 }
794 }
795
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700796 protected:
Mark Muellerdfe37552016-07-07 14:47:42 -0600797 static uint32_t BindIdGenerator;
798
799 bool BoundCurrent;
800 unsigned AttributeCount;
801 unsigned BindingCount;
802 uint32_t BindId;
803
804 VkPipelineVertexInputStateCreateInfo PipelineVertexInputStateCreateInfo;
805 VkVertexInputAttributeDescription *VertexInputAttributeDescription;
806 VkVertexInputBindingDescription *VertexInputBindingDescription;
807 VkConstantBufferObj VulkanMemoryBuffer;
808};
809
810uint32_t VkVerticesObj::BindIdGenerator;
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500811// ********************************************************************************************************************
812// ********************************************************************************************************************
813// ********************************************************************************************************************
814// ********************************************************************************************************************
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600815TEST_F(VkLayerTest, RequiredParameter) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700816 TEST_DESCRIPTION(
817 "Specify VK_NULL_HANDLE, NULL, and 0 for required handle, "
818 "pointer, array, and array count parameters");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600819
820 ASSERT_NO_FATAL_FAILURE(InitState());
821
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pFeatures specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600823 // Specify NULL for a pointer to a handle
824 // Expected to trigger an error with
825 // parameter_validation::validate_required_pointer
826 vkGetPhysicalDeviceFeatures(gpu(), NULL);
827 m_errorMonitor->VerifyFound();
828
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600829 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
830 "required parameter pQueueFamilyPropertyCount specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600831 // Specify NULL for pointer to array count
832 // Expected to trigger an error with parameter_validation::validate_array
Dustin Gravesa4bb8c12016-05-16 17:22:51 -0600833 vkGetPhysicalDeviceQueueFamilyProperties(gpu(), NULL, NULL);
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600834 m_errorMonitor->VerifyFound();
835
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600836 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter viewportCount must be greater than 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600837 // Specify 0 for a required array count
838 // Expected to trigger an error with parameter_validation::validate_array
839 VkViewport view_port = {};
840 m_commandBuffer->SetViewport(0, 0, &view_port);
841 m_errorMonitor->VerifyFound();
842
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600843 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pViewports specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600844 // Specify NULL for a required array
845 // Expected to trigger an error with parameter_validation::validate_array
846 m_commandBuffer->SetViewport(0, 1, NULL);
847 m_errorMonitor->VerifyFound();
848
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600849 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter memory specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600850 // Specify VK_NULL_HANDLE for a required handle
851 // Expected to trigger an error with
852 // parameter_validation::validate_required_handle
853 vkUnmapMemory(device(), VK_NULL_HANDLE);
854 m_errorMonitor->VerifyFound();
855
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
857 "required parameter pFences[0] specified as VK_NULL_HANDLE");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600858 // Specify VK_NULL_HANDLE for a required handle array entry
859 // Expected to trigger an error with
860 // parameter_validation::validate_required_handle_array
861 VkFence fence = VK_NULL_HANDLE;
862 vkResetFences(device(), 1, &fence);
863 m_errorMonitor->VerifyFound();
864
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pAllocateInfo specified as NULL");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600866 // Specify NULL for a required struct pointer
867 // Expected to trigger an error with
868 // parameter_validation::validate_struct_type
869 VkDeviceMemory memory = VK_NULL_HANDLE;
870 vkAllocateMemory(device(), NULL, NULL, &memory);
871 m_errorMonitor->VerifyFound();
872
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600873 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of faceMask must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600874 // Specify 0 for a required VkFlags parameter
875 // Expected to trigger an error with parameter_validation::validate_flags
876 m_commandBuffer->SetStencilReference(0, 0);
877 m_errorMonitor->VerifyFound();
878
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600879 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "value of pSubmits[0].pWaitDstStageMask[0] must not be 0");
Dustin Gravesffa90fa2016-05-06 11:20:38 -0600880 // Specify 0 for a required VkFlags array entry
881 // Expected to trigger an error with
882 // parameter_validation::validate_flags_array
883 VkSemaphore semaphore = VK_NULL_HANDLE;
884 VkPipelineStageFlags stageFlags = 0;
885 VkSubmitInfo submitInfo = {};
886 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
887 submitInfo.waitSemaphoreCount = 1;
888 submitInfo.pWaitSemaphores = &semaphore;
889 submitInfo.pWaitDstStageMask = &stageFlags;
890 vkQueueSubmit(m_device->m_queue, 1, &submitInfo, VK_NULL_HANDLE);
891 m_errorMonitor->VerifyFound();
892}
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600893
Dustin Gravesfce74c02016-05-10 11:42:58 -0600894TEST_F(VkLayerTest, ReservedParameter) {
895 TEST_DESCRIPTION("Specify a non-zero value for a reserved parameter");
896
897 ASSERT_NO_FATAL_FAILURE(InitState());
898
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " must be 0");
Dustin Gravesfce74c02016-05-10 11:42:58 -0600900 // Specify 0 for a reserved VkFlags parameter
901 // Expected to trigger an error with
902 // parameter_validation::validate_reserved_flags
903 VkEvent event_handle = VK_NULL_HANDLE;
904 VkEventCreateInfo event_info = {};
905 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
906 event_info.flags = 1;
907 vkCreateEvent(device(), &event_info, NULL, &event_handle);
908 m_errorMonitor->VerifyFound();
909}
910
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600911TEST_F(VkLayerTest, InvalidStructSType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700912 TEST_DESCRIPTION(
913 "Specify an invalid VkStructureType for a Vulkan "
914 "structure's sType field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600915
916 ASSERT_NO_FATAL_FAILURE(InitState());
917
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pAllocateInfo->sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600919 // Zero struct memory, effectively setting sType to
920 // VK_STRUCTURE_TYPE_APPLICATION_INFO
921 // Expected to trigger an error with
922 // parameter_validation::validate_struct_type
923 VkMemoryAllocateInfo alloc_info = {};
924 VkDeviceMemory memory = VK_NULL_HANDLE;
925 vkAllocateMemory(device(), &alloc_info, NULL, &memory);
926 m_errorMonitor->VerifyFound();
927
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pSubmits[0].sType must be");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600929 // Zero struct memory, effectively setting sType to
930 // VK_STRUCTURE_TYPE_APPLICATION_INFO
931 // Expected to trigger an error with
932 // parameter_validation::validate_struct_type_array
933 VkSubmitInfo submit_info = {};
934 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
935 m_errorMonitor->VerifyFound();
936}
937
938TEST_F(VkLayerTest, InvalidStructPNext) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600939 TEST_DESCRIPTION("Specify an invalid value for a Vulkan structure's pNext field");
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600940
941 ASSERT_NO_FATAL_FAILURE(InitState());
942
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "value of pCreateInfo->pNext must be NULL");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600944 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, when pNext must be NULL.
Karl Schultz38b50992016-07-11 16:09:09 -0600945 // Need to pick a function that has no allowed pNext structure types.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600946 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Karl Schultz38b50992016-07-11 16:09:09 -0600947 VkEvent event = VK_NULL_HANDLE;
Karl Schultz70db3902016-07-11 16:22:10 -0600948 VkEventCreateInfo event_alloc_info = {};
Karl Schultz38b50992016-07-11 16:09:09 -0600949 // Zero-initialization will provide the correct sType
950 VkApplicationInfo app_info = {};
951 event_alloc_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
952 event_alloc_info.pNext = &app_info;
953 vkCreateEvent(device(), &event_alloc_info, NULL, &event);
954 m_errorMonitor->VerifyFound();
955
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600956 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
957 " chain includes a structure with unexpected VkStructureType ");
Karl Schultz38b50992016-07-11 16:09:09 -0600958 // Set VkMemoryAllocateInfo::pNext to a non-NULL value, but use
959 // a function that has allowed pNext structure types and specify
960 // a structure type that is not allowed.
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -0600961 // Expected to trigger an error with parameter_validation::validate_struct_pnext
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600962 VkDeviceMemory memory = VK_NULL_HANDLE;
Dustin Graves47b6cba2016-05-10 17:34:38 -0600963 VkMemoryAllocateInfo memory_alloc_info = {};
964 memory_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
965 memory_alloc_info.pNext = &app_info;
966 vkAllocateMemory(device(), &memory_alloc_info, NULL, &memory);
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600967 m_errorMonitor->VerifyFound();
Dustin Gravesc99cf5a2016-05-09 14:40:29 -0600968}
Dustin Graves5d33d532016-05-09 16:21:12 -0600969
970TEST_F(VkLayerTest, UnrecognizedValue) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600971 TEST_DESCRIPTION("Specify unrecognized Vulkan enumeration, flags, and VkBool32 values");
Dustin Graves5d33d532016-05-09 16:21:12 -0600972
973 ASSERT_NO_FATAL_FAILURE(InitState());
974
Mark Lobodzinski64318ba2017-01-26 13:34:13 -0700975 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
976 "does not fall within the begin..end "
977 "range of the core VkFormat "
978 "enumeration tokens");
Dustin Graves5d33d532016-05-09 16:21:12 -0600979 // Specify an invalid VkFormat value
980 // Expected to trigger an error with
981 // parameter_validation::validate_ranged_enum
982 VkFormatProperties format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600983 vkGetPhysicalDeviceFormatProperties(gpu(), static_cast<VkFormat>(8000), &format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600984 m_errorMonitor->VerifyFound();
985
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600986 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600987 // Specify an invalid VkFlags bitmask value
988 // Expected to trigger an error with parameter_validation::validate_flags
989 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600990 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
991 static_cast<VkImageUsageFlags>(1 << 25), 0, &image_format_properties);
Dustin Graves5d33d532016-05-09 16:21:12 -0600992 m_errorMonitor->VerifyFound();
993
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600994 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "contains flag bits that are not recognized members of");
Dustin Graves5d33d532016-05-09 16:21:12 -0600995 // Specify an invalid VkFlags array entry
996 // Expected to trigger an error with
997 // parameter_validation::validate_flags_array
998 VkSemaphore semaphore = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -0600999 VkPipelineStageFlags stage_flags = static_cast<VkPipelineStageFlags>(1 << 25);
Dustin Graves5d33d532016-05-09 16:21:12 -06001000 VkSubmitInfo submit_info = {};
1001 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1002 submit_info.waitSemaphoreCount = 1;
1003 submit_info.pWaitSemaphores = &semaphore;
1004 submit_info.pWaitDstStageMask = &stage_flags;
1005 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
1006 m_errorMonitor->VerifyFound();
1007
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is neither VK_TRUE nor VK_FALSE");
Dustin Graves5d33d532016-05-09 16:21:12 -06001009 // Specify an invalid VkBool32 value
1010 // Expected to trigger a warning with
1011 // parameter_validation::validate_bool32
1012 VkSampler sampler = VK_NULL_HANDLE;
1013 VkSamplerCreateInfo sampler_info = {};
1014 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
1015 sampler_info.pNext = NULL;
1016 sampler_info.magFilter = VK_FILTER_NEAREST;
1017 sampler_info.minFilter = VK_FILTER_NEAREST;
1018 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
1019 sampler_info.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1020 sampler_info.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1021 sampler_info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
1022 sampler_info.mipLodBias = 1.0;
1023 sampler_info.maxAnisotropy = 1;
1024 sampler_info.compareEnable = VK_FALSE;
1025 sampler_info.compareOp = VK_COMPARE_OP_NEVER;
1026 sampler_info.minLod = 1.0;
1027 sampler_info.maxLod = 1.0;
1028 sampler_info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
1029 sampler_info.unnormalizedCoordinates = VK_FALSE;
1030 // Not VK_TRUE or VK_FALSE
1031 sampler_info.anisotropyEnable = 3;
1032 vkCreateSampler(m_device->device(), &sampler_info, NULL, &sampler);
1033 m_errorMonitor->VerifyFound();
1034}
Dustin Gravesfce74c02016-05-10 11:42:58 -06001035
1036TEST_F(VkLayerTest, FailedReturnValue) {
1037 TEST_DESCRIPTION("Check for a message describing a VkResult failure code");
1038
1039 ASSERT_NO_FATAL_FAILURE(InitState());
1040
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001041 // Find an unsupported image format
1042 VkFormat unsupported = VK_FORMAT_UNDEFINED;
1043 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
1044 VkFormat format = static_cast<VkFormat>(f);
1045 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001046 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001047 unsupported = format;
1048 break;
1049 }
1050 }
1051
1052 if (unsupported != VK_FORMAT_UNDEFINED) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001053 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
1054 "the requested format is not supported on this device");
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001055 // Specify an unsupported VkFormat value to generate a
1056 // VK_ERROR_FORMAT_NOT_SUPPORTED return code
1057 // Expected to trigger a warning from
1058 // parameter_validation::validate_result
1059 VkImageFormatProperties image_format_properties;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001060 VkResult err = vkGetPhysicalDeviceImageFormatProperties(gpu(), unsupported, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
1061 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, 0, &image_format_properties);
Dustin Graves13c1e2b2016-05-16 15:31:02 -06001062 ASSERT_TRUE(err == VK_ERROR_FORMAT_NOT_SUPPORTED);
1063 m_errorMonitor->VerifyFound();
1064 }
Dustin Gravesfce74c02016-05-10 11:42:58 -06001065}
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001066
1067TEST_F(VkLayerTest, UpdateBufferAlignment) {
1068 TEST_DESCRIPTION("Check alignment parameters for vkCmdUpdateBuffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001069 uint32_t updateData[] = {1, 2, 3, 4, 5, 6, 7, 8};
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001070
1071 ASSERT_NO_FATAL_FAILURE(InitState());
1072
1073 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1074 vk_testing::Buffer buffer;
1075 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1076
Tony Barbour552f6c02016-12-21 14:34:07 -07001077 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001078 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001080 m_commandBuffer->UpdateBuffer(buffer.handle(), 1, 4, updateData);
1081 m_errorMonitor->VerifyFound();
1082
1083 // Introduce failure by using dataSize that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001085 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 6, updateData);
1086 m_errorMonitor->VerifyFound();
1087
1088 // Introduce failure by using dataSize that is < 0
1089 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001090 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001091 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, -44, updateData);
1092 m_errorMonitor->VerifyFound();
1093
1094 // Introduce failure by using dataSize that is > 65536
1095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001096 "must be greater than zero and less than or equal to 65536");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001097 m_commandBuffer->UpdateBuffer(buffer.handle(), 0, 80000, updateData);
1098 m_errorMonitor->VerifyFound();
1099
Tony Barbour552f6c02016-12-21 14:34:07 -07001100 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001101}
1102
1103TEST_F(VkLayerTest, FillBufferAlignment) {
1104 TEST_DESCRIPTION("Check alignment parameters for vkCmdFillBuffer");
1105
1106 ASSERT_NO_FATAL_FAILURE(InitState());
1107
1108 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1109 vk_testing::Buffer buffer;
1110 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
1111
Tony Barbour552f6c02016-12-21 14:34:07 -07001112 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001113
1114 // Introduce failure by using dstOffset that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001115 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001116 m_commandBuffer->FillBuffer(buffer.handle(), 1, 4, 0x11111111);
1117 m_errorMonitor->VerifyFound();
1118
1119 // Introduce failure by using size that is not multiple of 4
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001120 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is not a multiple of 4");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001121 m_commandBuffer->FillBuffer(buffer.handle(), 0, 6, 0x11111111);
1122 m_errorMonitor->VerifyFound();
1123
1124 // Introduce failure by using size that is zero
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must be greater than zero");
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001126 m_commandBuffer->FillBuffer(buffer.handle(), 0, 0, 0x11111111);
1127 m_errorMonitor->VerifyFound();
1128
Tony Barbour552f6c02016-12-21 14:34:07 -07001129 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskie090fef2016-06-09 17:04:56 -06001130}
Dustin Graves40f35822016-06-23 11:12:53 -06001131
Cortd889ff92016-07-27 09:51:27 -07001132TEST_F(VkLayerTest, PSOPolygonModeInvalid) {
1133 VkResult err;
1134
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001135 TEST_DESCRIPTION(
1136 "Attempt to use a non-solid polygon fill mode in a "
1137 "pipeline when this feature is not enabled.");
Cortd889ff92016-07-27 09:51:27 -07001138
1139 ASSERT_NO_FATAL_FAILURE(InitState());
1140 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1141
1142 std::vector<const char *> device_extension_names;
1143 auto features = m_device->phy().features();
1144 // Artificially disable support for non-solid fill modes
1145 features.fillModeNonSolid = false;
1146 // The sacrificial device object
1147 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
1148
1149 VkRenderpassObj render_pass(&test_device);
1150
1151 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
1152 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
1153 pipeline_layout_ci.setLayoutCount = 0;
1154 pipeline_layout_ci.pSetLayouts = NULL;
1155
1156 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001157 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Cortd889ff92016-07-27 09:51:27 -07001158 ASSERT_VK_SUCCESS(err);
1159
1160 VkPipelineRasterizationStateCreateInfo rs_ci = {};
1161 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
1162 rs_ci.pNext = nullptr;
1163 rs_ci.lineWidth = 1.0f;
1164 rs_ci.rasterizerDiscardEnable = true;
1165
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001166 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
1167 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Cortd889ff92016-07-27 09:51:27 -07001168
Mark Lobodzinski5e644732016-08-15 16:51:19 -06001169 // Set polygonMode to unsupported value POINT, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001170 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1171 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001172 {
1173 VkPipelineObj pipe(&test_device);
1174 pipe.AddShader(&vs);
1175 pipe.AddShader(&fs);
1176 pipe.AddColorAttachment();
1177 // Introduce failure by setting unsupported polygon mode
1178 rs_ci.polygonMode = VK_POLYGON_MODE_POINT;
1179 pipe.SetRasterization(&rs_ci);
1180 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1181 }
1182 m_errorMonitor->VerifyFound();
1183
1184 // Try again with polygonMode=LINE, should fail
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001185 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1186 "polygonMode cannot be VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE");
Cortd889ff92016-07-27 09:51:27 -07001187 {
1188 VkPipelineObj pipe(&test_device);
1189 pipe.AddShader(&vs);
1190 pipe.AddShader(&fs);
1191 pipe.AddColorAttachment();
1192 // Introduce failure by setting unsupported polygon mode
1193 rs_ci.polygonMode = VK_POLYGON_MODE_LINE;
1194 pipe.SetRasterization(&rs_ci);
1195 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
1196 }
1197 m_errorMonitor->VerifyFound();
1198
Cortd889ff92016-07-27 09:51:27 -07001199 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
1200}
1201
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001202#if 0
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001203TEST_F(VkLayerTest, CallResetCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001204{
1205 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001206 VkFenceCreateInfo fenceInfo = {};
1207 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1208 fenceInfo.pNext = NULL;
1209 fenceInfo.flags = 0;
1210
Mike Weiblencce7ec72016-10-17 19:33:05 -06001211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Resetting command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001212
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001213 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourc1eb1a52015-07-20 13:00:10 -06001214
1215 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
1216 vk_testing::Buffer buffer;
1217 buffer.init_as_dst(*m_device, (VkDeviceSize)20, reqs);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001218
Tony Barbourfe3351b2015-07-28 10:17:20 -06001219 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001220 m_commandBuffer->FillBuffer(buffer.handle(), 0, 4, 0x11111111);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001221 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001222
1223 testFence.init(*m_device, fenceInfo);
1224
1225 // Bypass framework since it does the waits automatically
1226 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001227 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001228 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1229 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001230 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001231 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001232 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001233 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001234 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001235 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001236 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001237
1238 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001239 ASSERT_VK_SUCCESS( err );
1240
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001241 // Introduce failure by calling begin again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001242 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001243
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001244 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001245}
1246
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001247TEST_F(VkLayerTest, CallBeginCommandBufferBeforeCompletion)
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001248{
1249 vk_testing::Fence testFence;
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001250 VkFenceCreateInfo fenceInfo = {};
1251 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
1252 fenceInfo.pNext = NULL;
1253 fenceInfo.flags = 0;
1254
Mike Weiblencce7ec72016-10-17 19:33:05 -06001255 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Calling vkBeginCommandBuffer() on active command buffer");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001256
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001257 ASSERT_NO_FATAL_FAILURE(InitState());
1258 ASSERT_NO_FATAL_FAILURE(InitViewport());
1259 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
1260
Tony Barbourfe3351b2015-07-28 10:17:20 -06001261 BeginCommandBuffer();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001262 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbourfe3351b2015-07-28 10:17:20 -06001263 EndCommandBuffer();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001264
1265 testFence.init(*m_device, fenceInfo);
1266
1267 // Bypass framework since it does the waits automatically
1268 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001269 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08001270 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1271 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001272 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001273 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07001274 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08001275 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001276 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08001277 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06001278 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06001279
1280 err = vkQueueSubmit( m_device->m_queue, 1, &submit_info, testFence.handle());
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001281 ASSERT_VK_SUCCESS( err );
1282
Jon Ashburnf19916e2016-01-11 13:12:43 -07001283 VkCommandBufferInheritanceInfo hinfo = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001284 VkCommandBufferBeginInfo info = {};
1285 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
1286 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001287 info.renderPass = VK_NULL_HANDLE;
1288 info.subpass = 0;
1289 info.framebuffer = VK_NULL_HANDLE;
Chia-I Wub8d47ae2015-11-11 10:18:12 +08001290 info.occlusionQueryEnable = VK_FALSE;
1291 info.queryFlags = 0;
1292 info.pipelineStatistics = 0;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06001293
1294 // Introduce failure by calling BCB again before checking fence
Chia-I Wu3432a0c2015-10-27 18:04:07 +08001295 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001296
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001297 m_errorMonitor->VerifyFound();
Mark Lobodzinskiccb2b042015-05-19 10:28:29 -05001298}
Tobin Ehlis8fab6562015-12-01 09:57:09 -07001299#endif
Chris Forbes8f36a8a2016-04-07 13:21:07 +12001300
Mark Lobodzinski833bb552016-12-15 07:41:13 -07001301TEST_F(VkLayerTest, SparseBindingImageBufferCreate) {
1302 TEST_DESCRIPTION("Create buffer/image with sparse attributes but without the sparse_binding bit set");
1303
1304 ASSERT_NO_FATAL_FAILURE(InitState());
1305
1306 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00669);
1307 VkBuffer buffer;
1308 VkBufferCreateInfo buf_info = {};
1309 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1310 buf_info.pNext = NULL;
1311 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
1312 buf_info.size = 2048;
1313 buf_info.queueFamilyIndexCount = 0;
1314 buf_info.pQueueFamilyIndices = NULL;
1315 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1316 buf_info.flags = VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT;
1317 vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1318 m_errorMonitor->VerifyFound();
1319
1320 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02160);
1321 VkImage image;
1322 VkImageCreateInfo image_create_info = {};
1323 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1324 image_create_info.pNext = NULL;
1325 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1326 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1327 image_create_info.extent.width = 512;
1328 image_create_info.extent.height = 64;
1329 image_create_info.extent.depth = 1;
1330 image_create_info.mipLevels = 1;
1331 image_create_info.arrayLayers = 1;
1332 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1333 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1334 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1335 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1336 image_create_info.queueFamilyIndexCount = 0;
1337 image_create_info.pQueueFamilyIndices = NULL;
1338 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1339 image_create_info.flags = VK_BUFFER_CREATE_SPARSE_ALIASED_BIT;
1340 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1341 m_errorMonitor->VerifyFound();
1342}
1343
Dave Houlton829c0d82017-01-24 15:09:17 -07001344TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedTypes) {
1345 TEST_DESCRIPTION("Create images with sparse residency with unsupported types");
1346
1347 // Determine which device feature are available
1348 VkPhysicalDeviceFeatures available_features;
1349 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1350
1351 // Mask out device features we don't want
1352 VkPhysicalDeviceFeatures desired_features = available_features;
1353 desired_features.sparseResidencyImage2D = VK_FALSE;
1354 desired_features.sparseResidencyImage3D = VK_FALSE;
1355 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1356
1357 VkImage image = VK_NULL_HANDLE;
1358 VkResult result = VK_RESULT_MAX_ENUM;
1359 VkImageCreateInfo image_create_info = {};
1360 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1361 image_create_info.pNext = NULL;
1362 image_create_info.imageType = VK_IMAGE_TYPE_1D;
1363 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1364 image_create_info.extent.width = 512;
1365 image_create_info.extent.height = 1;
1366 image_create_info.extent.depth = 1;
1367 image_create_info.mipLevels = 1;
1368 image_create_info.arrayLayers = 1;
1369 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1370 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1371 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1372 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1373 image_create_info.queueFamilyIndexCount = 0;
1374 image_create_info.pQueueFamilyIndices = NULL;
1375 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1376 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1377
1378 // 1D image w/ sparse residency is an error
1379 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02352);
1380 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1381 m_errorMonitor->VerifyFound();
1382 if (VK_SUCCESS == result) {
1383 vkDestroyImage(m_device->device(), image, NULL);
1384 image = VK_NULL_HANDLE;
1385 }
1386
1387 // 2D image w/ sparse residency when feature isn't available
1388 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1389 image_create_info.extent.height = 64;
1390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02144);
1391 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1392 m_errorMonitor->VerifyFound();
1393 if (VK_SUCCESS == result) {
1394 vkDestroyImage(m_device->device(), image, NULL);
1395 image = VK_NULL_HANDLE;
1396 }
1397
1398 // 3D image w/ sparse residency when feature isn't available
1399 image_create_info.imageType = VK_IMAGE_TYPE_3D;
1400 image_create_info.extent.depth = 8;
1401 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02145);
1402 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1403 m_errorMonitor->VerifyFound();
1404 if (VK_SUCCESS == result) {
1405 vkDestroyImage(m_device->device(), image, NULL);
1406 image = VK_NULL_HANDLE;
1407 }
1408}
1409
1410TEST_F(VkLayerTest, SparseResidencyImageCreateUnsupportedSamples) {
1411 TEST_DESCRIPTION("Create images with sparse residency with unsupported tiling or sample counts");
1412
1413 // Determine which device feature are available
1414 VkPhysicalDeviceFeatures available_features;
1415 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&available_features));
1416
1417 // These tests all require that the device support sparse residency for 2D images
1418 if (VK_TRUE != available_features.sparseResidencyImage2D) {
1419 return;
1420 }
1421
1422 // Mask out device features we don't want
1423 VkPhysicalDeviceFeatures desired_features = available_features;
1424 desired_features.sparseResidency2Samples = VK_FALSE;
1425 desired_features.sparseResidency4Samples = VK_FALSE;
1426 desired_features.sparseResidency8Samples = VK_FALSE;
1427 desired_features.sparseResidency16Samples = VK_FALSE;
1428 ASSERT_NO_FATAL_FAILURE(InitState(&desired_features));
1429
1430 VkImage image = VK_NULL_HANDLE;
1431 VkResult result = VK_RESULT_MAX_ENUM;
1432 VkImageCreateInfo image_create_info = {};
1433 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1434 image_create_info.pNext = NULL;
1435 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1436 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1437 image_create_info.extent.width = 64;
1438 image_create_info.extent.height = 64;
1439 image_create_info.extent.depth = 1;
1440 image_create_info.mipLevels = 1;
1441 image_create_info.arrayLayers = 1;
1442 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
1443 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
1444 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1445 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1446 image_create_info.queueFamilyIndexCount = 0;
1447 image_create_info.pQueueFamilyIndices = NULL;
1448 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1449 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_BINDING_BIT;
1450
1451 // 2D image w/ sparse residency and linear tiling is an error
1452 m_errorMonitor->SetDesiredFailureMsg(
1453 VK_DEBUG_REPORT_ERROR_BIT_EXT,
1454 "VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
1455 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1456 m_errorMonitor->VerifyFound();
1457 if (VK_SUCCESS == result) {
1458 vkDestroyImage(m_device->device(), image, NULL);
1459 image = VK_NULL_HANDLE;
1460 }
1461 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
1462
1463 // Multi-sample image w/ sparse residency when feature isn't available (4 flavors)
1464 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
1465 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02146);
1466 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1467 m_errorMonitor->VerifyFound();
1468 if (VK_SUCCESS == result) {
1469 vkDestroyImage(m_device->device(), image, NULL);
1470 image = VK_NULL_HANDLE;
1471 }
1472
1473 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
1474 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02147);
1475 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1476 m_errorMonitor->VerifyFound();
1477 if (VK_SUCCESS == result) {
1478 vkDestroyImage(m_device->device(), image, NULL);
1479 image = VK_NULL_HANDLE;
1480 }
1481
1482 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
1483 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02148);
1484 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1485 m_errorMonitor->VerifyFound();
1486 if (VK_SUCCESS == result) {
1487 vkDestroyImage(m_device->device(), image, NULL);
1488 image = VK_NULL_HANDLE;
1489 }
1490
1491 image_create_info.samples = VK_SAMPLE_COUNT_16_BIT;
1492 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02149);
1493 result = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1494 m_errorMonitor->VerifyFound();
1495 if (VK_SUCCESS == result) {
1496 vkDestroyImage(m_device->device(), image, NULL);
1497 image = VK_NULL_HANDLE;
1498 }
1499}
1500
Tobin Ehlisf11be982016-05-11 13:52:53 -06001501TEST_F(VkLayerTest, InvalidMemoryAliasing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001502 TEST_DESCRIPTION(
1503 "Create a buffer and image, allocate memory, and bind the "
1504 "buffer and image to memory such that they will alias.");
Tobin Ehlisf11be982016-05-11 13:52:53 -06001505 VkResult err;
1506 bool pass;
1507 ASSERT_NO_FATAL_FAILURE(InitState());
1508
Tobin Ehlis077ded32016-05-12 17:39:13 -06001509 VkBuffer buffer, buffer2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001510 VkImage image;
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001511 VkImage image2;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001512 VkDeviceMemory mem; // buffer will be bound first
1513 VkDeviceMemory mem_img; // image bound first
Tobin Ehlis077ded32016-05-12 17:39:13 -06001514 VkMemoryRequirements buff_mem_reqs, img_mem_reqs;
Rene Lindsayd14f5572016-12-16 14:57:18 -07001515 VkMemoryRequirements buff_mem_reqs2, img_mem_reqs2;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001516
1517 VkBufferCreateInfo buf_info = {};
1518 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1519 buf_info.pNext = NULL;
1520 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1521 buf_info.size = 256;
1522 buf_info.queueFamilyIndexCount = 0;
1523 buf_info.pQueueFamilyIndices = NULL;
1524 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1525 buf_info.flags = 0;
1526 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1527 ASSERT_VK_SUCCESS(err);
1528
Tobin Ehlis077ded32016-05-12 17:39:13 -06001529 vkGetBufferMemoryRequirements(m_device->device(), buffer, &buff_mem_reqs);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001530
1531 VkImageCreateInfo image_create_info = {};
1532 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1533 image_create_info.pNext = NULL;
1534 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1535 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
1536 image_create_info.extent.width = 64;
1537 image_create_info.extent.height = 64;
1538 image_create_info.extent.depth = 1;
1539 image_create_info.mipLevels = 1;
1540 image_create_info.arrayLayers = 1;
1541 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis12a4b5e2016-08-08 12:33:11 -06001542 // Image tiling must be optimal to trigger error when aliasing linear buffer
1543 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisf11be982016-05-11 13:52:53 -06001544 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
1545 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1546 image_create_info.queueFamilyIndexCount = 0;
1547 image_create_info.pQueueFamilyIndices = NULL;
1548 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1549 image_create_info.flags = 0;
1550
Tobin Ehlisf11be982016-05-11 13:52:53 -06001551 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
1552 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001553 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
1554 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001555
Tobin Ehlis077ded32016-05-12 17:39:13 -06001556 vkGetImageMemoryRequirements(m_device->device(), image, &img_mem_reqs);
1557
1558 VkMemoryAllocateInfo alloc_info = {};
1559 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1560 alloc_info.pNext = NULL;
1561 alloc_info.memoryTypeIndex = 0;
1562 // Ensure memory is big enough for both bindings
1563 alloc_info.allocationSize = buff_mem_reqs.size + img_mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001564 pass = m_device->phy().set_memory_type(buff_mem_reqs.memoryTypeBits & img_mem_reqs.memoryTypeBits, &alloc_info,
1565 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001566 if (!pass) {
Tobin Ehlis077ded32016-05-12 17:39:13 -06001567 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001568 vkDestroyImage(m_device->device(), image, NULL);
Mark Lobodzinskid2d2d4c2017-02-16 11:51:58 -07001569 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001570 return;
1571 }
Tobin Ehlis077ded32016-05-12 17:39:13 -06001572 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1573 ASSERT_VK_SUCCESS(err);
1574 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
1575 ASSERT_VK_SUCCESS(err);
1576
Rene Lindsayd14f5572016-12-16 14:57:18 -07001577 vkGetImageMemoryRequirements(m_device->device(), image2, &img_mem_reqs2);
1578
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " is aliased with linear buffer 0x");
Tobin Ehlis077ded32016-05-12 17:39:13 -06001580 // VALIDATION FAILURE due to image mapping overlapping buffer mapping
Tobin Ehlisf11be982016-05-11 13:52:53 -06001581 err = vkBindImageMemory(m_device->device(), image, mem, 0);
1582 m_errorMonitor->VerifyFound();
1583
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001584 // Now correctly bind image2 to second mem allocation before incorrectly
Tobin Ehlis077ded32016-05-12 17:39:13 -06001585 // aliasing buffer2
1586 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer2);
1587 ASSERT_VK_SUCCESS(err);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001588 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem_img);
1589 ASSERT_VK_SUCCESS(err);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001590 err = vkBindImageMemory(m_device->device(), image2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001591 ASSERT_VK_SUCCESS(err);
Tobin Ehlis32b2bbc2016-12-13 17:33:41 -07001592 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "is aliased with non-linear image 0x");
Rene Lindsayd14f5572016-12-16 14:57:18 -07001593 vkGetBufferMemoryRequirements(m_device->device(), buffer2, &buff_mem_reqs2);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001594 err = vkBindBufferMemory(m_device->device(), buffer2, mem_img, 0);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001595 m_errorMonitor->VerifyFound();
1596
1597 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlis077ded32016-05-12 17:39:13 -06001598 vkDestroyBuffer(m_device->device(), buffer2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001599 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlis6cd67182016-09-21 18:32:11 -06001600 vkDestroyImage(m_device->device(), image2, NULL);
Tobin Ehlisf11be982016-05-11 13:52:53 -06001601 vkFreeMemory(m_device->device(), mem, NULL);
1602 vkFreeMemory(m_device->device(), mem_img, NULL);
1603}
1604
Tobin Ehlis35372522016-05-12 08:32:31 -06001605TEST_F(VkLayerTest, InvalidMemoryMapping) {
1606 TEST_DESCRIPTION("Attempt to map memory in a number of incorrect ways");
1607 VkResult err;
1608 bool pass;
1609 ASSERT_NO_FATAL_FAILURE(InitState());
1610
1611 VkBuffer buffer;
1612 VkDeviceMemory mem;
1613 VkMemoryRequirements mem_reqs;
1614
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001615 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
1616
Tobin Ehlis35372522016-05-12 08:32:31 -06001617 VkBufferCreateInfo buf_info = {};
1618 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
1619 buf_info.pNext = NULL;
1620 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
1621 buf_info.size = 256;
1622 buf_info.queueFamilyIndexCount = 0;
1623 buf_info.pQueueFamilyIndices = NULL;
1624 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1625 buf_info.flags = 0;
1626 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
1627 ASSERT_VK_SUCCESS(err);
1628
1629 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
1630 VkMemoryAllocateInfo alloc_info = {};
1631 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1632 alloc_info.pNext = NULL;
1633 alloc_info.memoryTypeIndex = 0;
1634
1635 // Ensure memory is big enough for both bindings
1636 static const VkDeviceSize allocation_size = 0x10000;
1637 alloc_info.allocationSize = allocation_size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001638 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001639 if (!pass) {
1640 vkDestroyBuffer(m_device->device(), buffer, NULL);
1641 return;
1642 }
1643 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
1644 ASSERT_VK_SUCCESS(err);
1645
1646 uint8_t *pData;
1647 // Attempt to map memory size 0 is invalid
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "VkMapMemory: Attempting to map memory range of size zero");
Tobin Ehlis35372522016-05-12 08:32:31 -06001649 err = vkMapMemory(m_device->device(), mem, 0, 0, 0, (void **)&pData);
1650 m_errorMonitor->VerifyFound();
1651 // Map memory twice
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001652 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001653 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001654 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1655 "VkMapMemory: Attempting to map memory on an already-mapped object ");
1656 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001657 m_errorMonitor->VerifyFound();
1658
1659 // Unmap the memory to avoid re-map error
1660 vkUnmapMemory(m_device->device(), mem);
1661 // overstep allocation with VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001662 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1663 " with size of VK_WHOLE_SIZE oversteps total array size 0x");
1664 err = vkMapMemory(m_device->device(), mem, allocation_size + 1, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001665 m_errorMonitor->VerifyFound();
1666 // overstep allocation w/o VK_WHOLE_SIZE
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001667 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " oversteps total array size 0x");
1668 err = vkMapMemory(m_device->device(), mem, 1, allocation_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001669 m_errorMonitor->VerifyFound();
1670 // Now error due to unmapping memory that's not mapped
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001671 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Unmapping Memory without memory being mapped: ");
Tobin Ehlis35372522016-05-12 08:32:31 -06001672 vkUnmapMemory(m_device->device(), mem);
1673 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001674
Tobin Ehlis35372522016-05-12 08:32:31 -06001675 // Now map memory and cause errors due to flushing invalid ranges
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001676 err = vkMapMemory(m_device->device(), mem, 4 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001677 ASSERT_VK_SUCCESS(err);
1678 VkMappedMemoryRange mmr = {};
Chris Forbes3aec0892016-06-13 10:29:26 +12001679 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
Tobin Ehlis35372522016-05-12 08:32:31 -06001680 mmr.memory = mem;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001681 mmr.offset = atom_size; // Error b/c offset less than offset of mapped mem
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001682 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
Tobin Ehlis35372522016-05-12 08:32:31 -06001683 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1684 m_errorMonitor->VerifyFound();
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001685
Tobin Ehlis35372522016-05-12 08:32:31 -06001686 // Now flush range that oversteps mapped range
1687 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001688 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
Tobin Ehlis35372522016-05-12 08:32:31 -06001689 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001690 mmr.offset = atom_size;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001691 mmr.size = 4 * atom_size; // Flushing bounds exceed mapped bounds
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001692 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00642);
1693 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1694 m_errorMonitor->VerifyFound();
1695
1696 // Now flush range with VK_WHOLE_SIZE that oversteps offset
1697 vkUnmapMemory(m_device->device(), mem);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001698 err = vkMapMemory(m_device->device(), mem, 2 * atom_size, 4 * atom_size, 0, (void **)&pData);
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001699 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski65741a42016-11-15 09:14:24 -07001700 mmr.offset = atom_size;
Mark Lobodzinskib3c675e2016-11-15 08:56:03 -07001701 mmr.size = VK_WHOLE_SIZE;
1702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00643);
Tobin Ehlis35372522016-05-12 08:32:31 -06001703 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1704 m_errorMonitor->VerifyFound();
1705
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001706#if 0 // Planning discussion with working group on this validation check.
Mark Lobodzinski3826a4f2016-11-15 09:38:51 -07001707 // Some platforms have an atomsize of 1 which makes the test meaningless
1708 if (atom_size > 3) {
1709 // Now with an offset NOT a multiple of the device limit
1710 vkUnmapMemory(m_device->device(), mem);
1711 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1712 ASSERT_VK_SUCCESS(err);
1713 mmr.offset = 3; // Not a multiple of atom_size
1714 mmr.size = VK_WHOLE_SIZE;
1715 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00644);
1716 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1717 m_errorMonitor->VerifyFound();
1718
1719 // Now with a size NOT a multiple of the device limit
1720 vkUnmapMemory(m_device->device(), mem);
1721 err = vkMapMemory(m_device->device(), mem, 0, 4 * atom_size, 0, (void **)&pData);
1722 ASSERT_VK_SUCCESS(err);
1723 mmr.offset = atom_size;
1724 mmr.size = 2 * atom_size + 1; // Not a multiple of atom_size
1725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00645);
1726 vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
1727 m_errorMonitor->VerifyFound();
1728 }
Tony Barboure3975eb2016-12-15 14:52:44 -07001729#endif
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001730 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
1731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Tobin Ehlis35372522016-05-12 08:32:31 -06001732 if (!pass) {
1733 vkFreeMemory(m_device->device(), mem, NULL);
1734 vkDestroyBuffer(m_device->device(), buffer, NULL);
1735 return;
1736 }
1737 // TODO : If we can get HOST_VISIBLE w/o HOST_COHERENT we can test cases of
1738 // MEMTRACK_INVALID_MAP in validateAndCopyNoncoherentMemoryToDriver()
1739
1740 vkDestroyBuffer(m_device->device(), buffer, NULL);
1741 vkFreeMemory(m_device->device(), mem, NULL);
1742}
1743
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001744#if 0 // disabled until PV gets real extension enable checks
Ian Elliott1c32c772016-04-28 14:47:13 -06001745TEST_F(VkLayerTest, EnableWsiBeforeUse) {
1746 VkResult err;
1747 bool pass;
1748
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001749 // FIXME: After we turn on this code for non-Linux platforms, uncomment the
1750 // following declaration (which is temporarily being moved below):
1751 // VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott1c32c772016-04-28 14:47:13 -06001752 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001753 VkSwapchainCreateInfoKHR swapchain_create_info = {VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
Ian Elliott1c32c772016-04-28 14:47:13 -06001754 uint32_t swapchain_image_count = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001755 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
Ian Elliott1c32c772016-04-28 14:47:13 -06001756 uint32_t image_index = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001757 // VkPresentInfoKHR present_info = {};
Ian Elliott1c32c772016-04-28 14:47:13 -06001758
1759 ASSERT_NO_FATAL_FAILURE(InitState());
1760
Ian Elliott3f06ce52016-04-29 14:46:21 -06001761#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
1762#if defined(VK_USE_PLATFORM_ANDROID_KHR)
1763 // Use the functions from the VK_KHR_android_surface extension without
1764 // enabling that extension:
1765
1766 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001767 VkAndroidSurfaceCreateInfoKHR android_create_info = {VK_STRUCTURE_TYPE_ANDROID_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001768 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1769 err = vkCreateAndroidSurfaceKHR(instance(), &android_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001770 pass = (err != VK_SUCCESS);
1771 ASSERT_TRUE(pass);
1772 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001773#endif // VK_USE_PLATFORM_ANDROID_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001774
Ian Elliott3f06ce52016-04-29 14:46:21 -06001775#if defined(VK_USE_PLATFORM_MIR_KHR)
1776 // Use the functions from the VK_KHR_mir_surface extension without enabling
1777 // that extension:
1778
1779 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001780 VkMirSurfaceCreateInfoKHR mir_create_info = {VK_STRUCTURE_TYPE_MIR_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001781 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott3f06ce52016-04-29 14:46:21 -06001782 err = vkCreateMirSurfaceKHR(instance(), &mir_create_info, NULL, &surface);
1783 pass = (err != VK_SUCCESS);
1784 ASSERT_TRUE(pass);
1785 m_errorMonitor->VerifyFound();
1786
1787 // Tell whether an mir_connection supports presentation:
1788 MirConnection *mir_connection = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001789 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1790 vkGetPhysicalDeviceMirPresentationSupportKHR(gpu(), 0, mir_connection, visual_id);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001791 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001792#endif // VK_USE_PLATFORM_MIR_KHR
Ian Elliott3f06ce52016-04-29 14:46:21 -06001793
Ian Elliott3f06ce52016-04-29 14:46:21 -06001794#if defined(VK_USE_PLATFORM_WAYLAND_KHR)
1795 // Use the functions from the VK_KHR_wayland_surface extension without
1796 // enabling that extension:
1797
1798 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001799 VkWaylandSurfaceCreateInfoKHR wayland_create_info = {VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1801 err = vkCreateWaylandSurfaceKHR(instance(), &wayland_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001802 pass = (err != VK_SUCCESS);
1803 ASSERT_TRUE(pass);
1804 m_errorMonitor->VerifyFound();
1805
1806 // Tell whether an wayland_display supports presentation:
1807 struct wl_display wayland_display = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1809 vkGetPhysicalDeviceWaylandPresentationSupportKHR(gpu(), 0, &wayland_display);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001810 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001811#endif // VK_USE_PLATFORM_WAYLAND_KHR
1812#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott3f06ce52016-04-29 14:46:21 -06001813
Ian Elliott3f06ce52016-04-29 14:46:21 -06001814#if defined(VK_USE_PLATFORM_WIN32_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001815 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1816 // TO NON-LINUX PLATFORMS:
1817 VkSurfaceKHR surface = VK_NULL_HANDLE;
Ian Elliott3f06ce52016-04-29 14:46:21 -06001818 // Use the functions from the VK_KHR_win32_surface extension without
1819 // enabling that extension:
1820
1821 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001822 VkWin32SurfaceCreateInfoKHR win32_create_info = {VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1824 err = vkCreateWin32SurfaceKHR(instance(), &win32_create_info, NULL, &surface);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001825 pass = (err != VK_SUCCESS);
1826 ASSERT_TRUE(pass);
1827 m_errorMonitor->VerifyFound();
1828
1829 // Tell whether win32 supports presentation:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001830 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott489eec02016-05-05 14:12:44 -06001831 vkGetPhysicalDeviceWin32PresentationSupportKHR(gpu(), 0);
Ian Elliott3f06ce52016-04-29 14:46:21 -06001832 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001833// Set this (for now, until all platforms are supported and tested):
1834#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001835#endif // VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07001836#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001837 // FIXME: REMOVE THIS HERE, AND UNCOMMENT ABOVE, WHEN THIS TEST HAS BEEN PORTED
1838 // TO NON-LINUX PLATFORMS:
1839 VkSurfaceKHR surface = VK_NULL_HANDLE;
Tony Barbour2e7bd402016-11-14 14:46:33 -07001840#endif
1841#if defined(VK_USE_PLATFORM_XCB_KHR)
Ian Elliott1c32c772016-04-28 14:47:13 -06001842 // Use the functions from the VK_KHR_xcb_surface extension without enabling
1843 // that extension:
1844
1845 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001846 VkXcbSurfaceCreateInfoKHR xcb_create_info = {VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001847 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001848 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
1849 pass = (err != VK_SUCCESS);
1850 ASSERT_TRUE(pass);
1851 m_errorMonitor->VerifyFound();
1852
1853 // Tell whether an xcb_visualid_t supports presentation:
Ian Elliott3f06ce52016-04-29 14:46:21 -06001854 xcb_connection_t *xcb_connection = NULL;
Ian Elliott1c32c772016-04-28 14:47:13 -06001855 xcb_visualid_t visual_id = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001856 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1857 vkGetPhysicalDeviceXcbPresentationSupportKHR(gpu(), 0, xcb_connection, visual_id);
Ian Elliott1c32c772016-04-28 14:47:13 -06001858 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001859// Set this (for now, until all platforms are supported and tested):
1860#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001861#endif // VK_USE_PLATFORM_XCB_KHR
Ian Elliott1c32c772016-04-28 14:47:13 -06001862
Ian Elliott12630812016-04-29 14:35:43 -06001863#if defined(VK_USE_PLATFORM_XLIB_KHR)
1864 // Use the functions from the VK_KHR_xlib_surface extension without enabling
1865 // that extension:
1866
1867 // Create a surface:
Chris Forbes0ad0ee12016-11-02 17:25:01 +13001868 VkXlibSurfaceCreateInfoKHR xlib_create_info = {VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001869 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001870 err = vkCreateXlibSurfaceKHR(instance(), &xlib_create_info, NULL, &surface);
1871 pass = (err != VK_SUCCESS);
1872 ASSERT_TRUE(pass);
1873 m_errorMonitor->VerifyFound();
1874
1875 // Tell whether an Xlib VisualID supports presentation:
1876 Display *dpy = NULL;
1877 VisualID visual = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott12630812016-04-29 14:35:43 -06001879 vkGetPhysicalDeviceXlibPresentationSupportKHR(gpu(), 0, dpy, visual);
1880 m_errorMonitor->VerifyFound();
Ian Elliott489eec02016-05-05 14:12:44 -06001881// Set this (for now, until all platforms are supported and tested):
1882#define NEED_TO_TEST_THIS_ON_PLATFORM
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001883#endif // VK_USE_PLATFORM_XLIB_KHR
Ian Elliott12630812016-04-29 14:35:43 -06001884
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001885// Use the functions from the VK_KHR_surface extension without enabling
1886// that extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001887
Ian Elliott489eec02016-05-05 14:12:44 -06001888#ifdef NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001889 // Destroy a surface:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001890 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001891 vkDestroySurfaceKHR(instance(), surface, NULL);
1892 m_errorMonitor->VerifyFound();
1893
1894 // Check if surface supports presentation:
1895 VkBool32 supported = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001897 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
1898 pass = (err != VK_SUCCESS);
1899 ASSERT_TRUE(pass);
1900 m_errorMonitor->VerifyFound();
1901
1902 // Check surface capabilities:
1903 VkSurfaceCapabilitiesKHR capabilities = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1905 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &capabilities);
Ian Elliott1c32c772016-04-28 14:47:13 -06001906 pass = (err != VK_SUCCESS);
1907 ASSERT_TRUE(pass);
1908 m_errorMonitor->VerifyFound();
1909
1910 // Check surface formats:
1911 uint32_t format_count = 0;
1912 VkSurfaceFormatKHR *formats = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001913 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1914 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &format_count, formats);
Ian Elliott1c32c772016-04-28 14:47:13 -06001915 pass = (err != VK_SUCCESS);
1916 ASSERT_TRUE(pass);
1917 m_errorMonitor->VerifyFound();
1918
1919 // Check surface present modes:
1920 uint32_t present_mode_count = 0;
1921 VkSurfaceFormatKHR *present_modes = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001922 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1923 err = vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &present_mode_count, present_modes);
Ian Elliott1c32c772016-04-28 14:47:13 -06001924 pass = (err != VK_SUCCESS);
1925 ASSERT_TRUE(pass);
1926 m_errorMonitor->VerifyFound();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07001927#endif // NEED_TO_TEST_THIS_ON_PLATFORM
Ian Elliott1c32c772016-04-28 14:47:13 -06001928
Ian Elliott1c32c772016-04-28 14:47:13 -06001929 // Use the functions from the VK_KHR_swapchain extension without enabling
1930 // that extension:
1931
1932 // Create a swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001933 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001934 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1935 swapchain_create_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001936 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
Ian Elliott1c32c772016-04-28 14:47:13 -06001937 pass = (err != VK_SUCCESS);
1938 ASSERT_TRUE(pass);
1939 m_errorMonitor->VerifyFound();
1940
1941 // Get the images from the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
1943 err = vkGetSwapchainImagesKHR(m_device->device(), swapchain, &swapchain_image_count, NULL);
Ian Elliott1c32c772016-04-28 14:47:13 -06001944 pass = (err != VK_SUCCESS);
1945 ASSERT_TRUE(pass);
1946 m_errorMonitor->VerifyFound();
1947
Chris Forbeseb7d5502016-09-13 18:19:21 +12001948 // Add a fence to avoid (justifiable) error about not providing fence OR semaphore
1949 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
1950 VkFence fence;
1951 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
1952
Ian Elliott1c32c772016-04-28 14:47:13 -06001953 // Try to acquire an image:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001954 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Chris Forbeseb7d5502016-09-13 18:19:21 +12001955 err = vkAcquireNextImageKHR(m_device->device(), swapchain, 0, VK_NULL_HANDLE, fence, &image_index);
Ian Elliott1c32c772016-04-28 14:47:13 -06001956 pass = (err != VK_SUCCESS);
1957 ASSERT_TRUE(pass);
1958 m_errorMonitor->VerifyFound();
1959
Chris Forbeseb7d5502016-09-13 18:19:21 +12001960 vkDestroyFence(m_device->device(), fence, nullptr);
1961
Ian Elliott1c32c772016-04-28 14:47:13 -06001962 // Try to present an image:
Ian Elliott2c1daf52016-05-12 09:41:46 -06001963 //
1964 // NOTE: Currently can't test this because a real swapchain is needed (as
1965 // opposed to the fake one we created) in order for the layer to lookup the
1966 // VkDevice used to enable the extension:
Ian Elliott1c32c772016-04-28 14:47:13 -06001967
1968 // Destroy the swapchain:
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "extension was not enabled for this");
Ian Elliott1c32c772016-04-28 14:47:13 -06001970 vkDestroySwapchainKHR(m_device->device(), swapchain, NULL);
1971 m_errorMonitor->VerifyFound();
1972}
Chris Forbes09368e42016-10-13 11:59:22 +13001973#endif
Ian Elliott1c32c772016-04-28 14:47:13 -06001974
Karl Schultz6addd812016-02-02 17:17:23 -07001975TEST_F(VkLayerTest, MapMemWithoutHostVisibleBit) {
1976 VkResult err;
1977 bool pass;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001978
Mark Lobodzinskice751c62016-09-08 10:45:35 -06001979 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
1980 "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06001981
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001982 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001983
1984 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07001985 VkImage image;
1986 VkDeviceMemory mem;
1987 VkMemoryRequirements mem_reqs;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001988
Karl Schultz6addd812016-02-02 17:17:23 -07001989 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
1990 const int32_t tex_width = 32;
1991 const int32_t tex_height = 32;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001992
Tony Barboureb254902015-07-15 12:50:33 -06001993 VkImageCreateInfo image_create_info = {};
1994 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07001995 image_create_info.pNext = NULL;
1996 image_create_info.imageType = VK_IMAGE_TYPE_2D;
1997 image_create_info.format = tex_format;
1998 image_create_info.extent.width = tex_width;
1999 image_create_info.extent.height = tex_height;
2000 image_create_info.extent.depth = 1;
2001 image_create_info.mipLevels = 1;
2002 image_create_info.arrayLayers = 1;
2003 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2004 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2005 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2006 image_create_info.flags = 0;
Chris Forbese65e4d02016-09-13 17:39:18 +12002007 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002008
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002009 VkMemoryAllocateInfo mem_alloc = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002010 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -07002011 mem_alloc.pNext = NULL;
2012 mem_alloc.allocationSize = 0;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002013
Chia-I Wuf7458c52015-10-26 21:10:41 +08002014 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002015 ASSERT_VK_SUCCESS(err);
2016
Karl Schultz6addd812016-02-02 17:17:23 -07002017 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002018
Mark Lobodzinski23065352015-05-29 09:32:35 -05002019 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002020
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002021 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002022 if (!pass) { // If we can't find any unmappable memory this test doesn't
2023 // make sense
Chia-I Wuf7458c52015-10-26 21:10:41 +08002024 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbour02fdc7d2015-08-04 16:13:01 -06002025 return;
Mike Stroyand1c84a52015-08-18 14:40:24 -06002026 }
Mike Stroyan713b2d72015-08-04 10:49:29 -06002027
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002028 // allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002029 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002030 ASSERT_VK_SUCCESS(err);
2031
2032 // Try to bind free memory that has been freed
Tony Barbour67e99152015-07-10 14:10:27 -06002033 err = vkBindImageMemory(m_device->device(), image, mem, 0);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002034 ASSERT_VK_SUCCESS(err);
2035
2036 // Map memory as if to initialize the image
2037 void *mappedAddress = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002038 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, &mappedAddress);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002039
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002040 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002041
Chia-I Wuf7458c52015-10-26 21:10:41 +08002042 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06002043 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002044}
2045
Karl Schultz6addd812016-02-02 17:17:23 -07002046TEST_F(VkLayerTest, RebindMemory) {
2047 VkResult err;
2048 bool pass;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002049
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002050 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which has already been bound to mem object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002051
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002052 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002053
2054 // Create an image, allocate memory, free it, and then try to bind it
Karl Schultz6addd812016-02-02 17:17:23 -07002055 VkImage image;
2056 VkDeviceMemory mem1;
2057 VkDeviceMemory mem2;
2058 VkMemoryRequirements mem_reqs;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002059
Karl Schultz6addd812016-02-02 17:17:23 -07002060 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2061 const int32_t tex_width = 32;
2062 const int32_t tex_height = 32;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002063
Tony Barboureb254902015-07-15 12:50:33 -06002064 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002065 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2066 image_create_info.pNext = NULL;
2067 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2068 image_create_info.format = tex_format;
2069 image_create_info.extent.width = tex_width;
2070 image_create_info.extent.height = tex_height;
2071 image_create_info.extent.depth = 1;
2072 image_create_info.mipLevels = 1;
2073 image_create_info.arrayLayers = 1;
2074 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2075 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2076 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2077 image_create_info.flags = 0;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002078
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002079 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002080 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2081 mem_alloc.pNext = NULL;
2082 mem_alloc.allocationSize = 0;
2083 mem_alloc.memoryTypeIndex = 0;
Tony Barboureb254902015-07-15 12:50:33 -06002084
Karl Schultz6addd812016-02-02 17:17:23 -07002085 // Introduce failure, do NOT set memProps to
2086 // VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
Tony Barboureb254902015-07-15 12:50:33 -06002087 mem_alloc.memoryTypeIndex = 1;
Chia-I Wuf7458c52015-10-26 21:10:41 +08002088 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002089 ASSERT_VK_SUCCESS(err);
2090
Karl Schultz6addd812016-02-02 17:17:23 -07002091 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002092
2093 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002094 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002095 ASSERT_TRUE(pass);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002096
2097 // allocate 2 memory objects
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002098 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem1);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002099 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002100 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem2);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002101 ASSERT_VK_SUCCESS(err);
2102
2103 // Bind first memory object to Image object
Tony Barbour67e99152015-07-10 14:10:27 -06002104 err = vkBindImageMemory(m_device->device(), image, mem1, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002105 ASSERT_VK_SUCCESS(err);
2106
Karl Schultz6addd812016-02-02 17:17:23 -07002107 // Introduce validation failure, try to bind a different memory object to
2108 // the same image object
Tony Barbour67e99152015-07-10 14:10:27 -06002109 err = vkBindImageMemory(m_device->device(), image, mem2, 0);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002110
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002111 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002112
Chia-I Wuf7458c52015-10-26 21:10:41 +08002113 vkDestroyImage(m_device->device(), image, NULL);
2114 vkFreeMemory(m_device->device(), mem1, NULL);
2115 vkFreeMemory(m_device->device(), mem2, NULL);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002116}
Mark Lobodzinski3780e142015-05-14 15:08:13 -05002117
Karl Schultz6addd812016-02-02 17:17:23 -07002118TEST_F(VkLayerTest, SubmitSignaledFence) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002119 vk_testing::Fence testFence;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002120
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002121 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
2122 "submitted in SIGNALED state. Fences "
2123 "must be reset before being submitted");
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06002124
2125 VkFenceCreateInfo fenceInfo = {};
Tony Barbour0b4d9562015-04-09 10:48:04 -06002126 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2127 fenceInfo.pNext = NULL;
2128 fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
Tony Barbour300a6082015-04-07 13:44:53 -06002129
Tony Barbour300a6082015-04-07 13:44:53 -06002130 ASSERT_NO_FATAL_FAILURE(InitState());
2131 ASSERT_NO_FATAL_FAILURE(InitViewport());
2132 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2133
Tony Barbour552f6c02016-12-21 14:34:07 -07002134 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002135 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07002136 m_commandBuffer->EndCommandBuffer();
Tony Barbour300a6082015-04-07 13:44:53 -06002137
2138 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002139
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002140 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08002141 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
2142 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002143 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002144 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07002145 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08002146 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002147 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08002148 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06002149 submit_info.pSignalSemaphores = NULL;
Courtney Goeltzenleuchter646b9072015-10-20 18:04:07 -06002150
2151 vkQueueSubmit(m_device->m_queue, 1, &submit_info, testFence.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07002152 vkQueueWaitIdle(m_device->m_queue);
Mark Lobodzinski5fcc4212015-09-14 17:43:42 -06002153
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002154 m_errorMonitor->VerifyFound();
Tony Barbour0b4d9562015-04-09 10:48:04 -06002155}
Chris Forbes4e44c912016-06-16 10:20:00 +12002156
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002157TEST_F(VkLayerTest, InvalidUsageBits) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002158 TEST_DESCRIPTION(
2159 "Specify wrong usage for image then create conflicting view of image "
2160 "Initialize buffer with wrong usage then perform copy expecting errors "
2161 "from both the image and the buffer (2 calls)");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid usage flag for image ");
Tobin Ehlis41376e12015-07-03 08:45:14 -06002163
2164 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002165
Tony Barbourf887b162017-03-09 10:06:46 -07002166 auto format = find_depth_stencil_format(m_device);
2167 if (!format) {
2168 printf(" No Depth + Stencil format found. Skipped.\n");
2169 return;
2170 }
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002171
Tony Barbourf92621a2016-05-02 14:28:12 -06002172 VkImageObj image(m_device);
Tony Barbour75d79f02016-08-30 09:39:07 -06002173 // Initialize image with USAGE_TRANSIENT_ATTACHMENT
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002174 image.init(128, 128, format, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Karl Schultzb5bc11e2016-05-04 08:36:08 -06002175 ASSERT_TRUE(image.initialized());
Tobin Ehlis41376e12015-07-03 08:45:14 -06002176
Tony Barbourf92621a2016-05-02 14:28:12 -06002177 VkImageView dsv;
2178 VkImageViewCreateInfo dsvci = {};
2179 dsvci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
2180 dsvci.image = image.handle();
2181 dsvci.viewType = VK_IMAGE_VIEW_TYPE_2D;
Chris Forbesd2b5fe42016-11-28 18:00:00 +13002182 dsvci.format = format;
Tony Barbourf92621a2016-05-02 14:28:12 -06002183 dsvci.subresourceRange.layerCount = 1;
2184 dsvci.subresourceRange.baseMipLevel = 0;
2185 dsvci.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002186 dsvci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis41376e12015-07-03 08:45:14 -06002187
Tony Barbourf92621a2016-05-02 14:28:12 -06002188 // Create a view with depth / stencil aspect for image with different usage
2189 vkCreateImageView(m_device->device(), &dsvci, NULL, &dsv);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002190
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002191 m_errorMonitor->VerifyFound();
Tony Barbourf92621a2016-05-02 14:28:12 -06002192
2193 // Initialize buffer with TRANSFER_DST usage
2194 vk_testing::Buffer buffer;
2195 VkMemoryPropertyFlags reqs = 0;
2196 buffer.init_as_dst(*m_device, 128 * 128, reqs);
2197 VkBufferImageCopy region = {};
2198 region.bufferRowLength = 128;
2199 region.bufferImageHeight = 128;
Mark Lobodzinski80871462017-02-16 10:37:27 -07002200 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Tony Barbourf92621a2016-05-02 14:28:12 -06002201 region.imageSubresource.layerCount = 1;
2202 region.imageExtent.height = 16;
2203 region.imageExtent.width = 16;
2204 region.imageExtent.depth = 1;
2205
Mark Lobodzinski80871462017-02-16 10:37:27 -07002206 // Buffer usage not set to TRANSFER_SRC and image usage not set to TRANSFER_DST
Tony Barbour552f6c02016-12-21 14:34:07 -07002207 m_commandBuffer->BeginCommandBuffer();
Tony Barbourf92621a2016-05-02 14:28:12 -06002208
Chris Forbesda581202016-10-06 18:25:26 +13002209 // two separate errors from this call:
2210 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "image should have VK_IMAGE_USAGE_TRANSFER_DST_BIT");
2211 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "buffer should have VK_BUFFER_USAGE_TRANSFER_SRC_BIT");
2212
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002213 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
2214 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Tony Barbourf92621a2016-05-02 14:28:12 -06002215 m_errorMonitor->VerifyFound();
Tobin Ehlis41376e12015-07-03 08:45:14 -06002216}
Tony Barbour75d79f02016-08-30 09:39:07 -06002217
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002218TEST_F(VkLayerTest, LeakAnObject) {
2219 VkResult err;
2220
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002221 TEST_DESCRIPTION("Create a fence and destroy its device without first destroying the fence.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002222
2223 // Note that we have to create a new device since destroying the
2224 // framework's device causes Teardown() to fail and just calling Teardown
2225 // will destroy the errorMonitor.
2226
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002227 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "has not been destroyed.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002228
2229 ASSERT_NO_FATAL_FAILURE(InitState());
2230
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002231 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002232 std::vector<VkDeviceQueueCreateInfo> queue_info;
2233 queue_info.reserve(queue_props.size());
2234 std::vector<std::vector<float>> queue_priorities;
2235 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
2236 VkDeviceQueueCreateInfo qi = {};
2237 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2238 qi.pNext = NULL;
2239 qi.queueFamilyIndex = i;
2240 qi.queueCount = queue_props[i].queueCount;
2241 queue_priorities.emplace_back(qi.queueCount, 0.0f);
2242 qi.pQueuePriorities = queue_priorities[i].data();
2243 queue_info.push_back(qi);
2244 }
2245
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002246 std::vector<const char *> device_extension_names;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002247
2248 // The sacrificial device object
2249 VkDevice testDevice;
2250 VkDeviceCreateInfo device_create_info = {};
2251 auto features = m_device->phy().features();
2252 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2253 device_create_info.pNext = NULL;
2254 device_create_info.queueCreateInfoCount = queue_info.size();
2255 device_create_info.pQueueCreateInfos = queue_info.data();
Tony Barbour4c70d102016-08-08 16:06:56 -06002256 device_create_info.enabledLayerCount = 0;
2257 device_create_info.ppEnabledLayerNames = NULL;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002258 device_create_info.pEnabledFeatures = &features;
2259 err = vkCreateDevice(gpu(), &device_create_info, NULL, &testDevice);
2260 ASSERT_VK_SUCCESS(err);
2261
2262 VkFence fence;
2263 VkFenceCreateInfo fence_create_info = {};
2264 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
2265 fence_create_info.pNext = NULL;
2266 fence_create_info.flags = 0;
2267 err = vkCreateFence(testDevice, &fence_create_info, NULL, &fence);
2268 ASSERT_VK_SUCCESS(err);
2269
2270 // Induce failure by not calling vkDestroyFence
2271 vkDestroyDevice(testDevice, NULL);
2272 m_errorMonitor->VerifyFound();
2273}
2274
2275TEST_F(VkLayerTest, InvalidCommandPoolConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002276 TEST_DESCRIPTION(
2277 "Allocate command buffers from one command pool and "
2278 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002279
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002280 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeCommandBuffers is attempting to free Command Buffer");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002281
Cody Northropc31a84f2016-08-22 10:41:47 -06002282 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002283 VkCommandPool command_pool_one;
2284 VkCommandPool command_pool_two;
2285
2286 VkCommandPoolCreateInfo pool_create_info{};
2287 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
2288 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
2289 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
2290
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002291 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002292
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002293 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002294
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002295 VkCommandBuffer cb;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002296 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002297 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002298 command_buffer_allocate_info.commandPool = command_pool_one;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002299 command_buffer_allocate_info.commandBufferCount = 1;
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002300 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002301 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002302
Chris Forbes5ab04ec2016-11-28 18:03:11 +13002303 vkFreeCommandBuffers(m_device->device(), command_pool_two, 1, &cb);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002304
2305 m_errorMonitor->VerifyFound();
2306
2307 vkDestroyCommandPool(m_device->device(), command_pool_one, NULL);
2308 vkDestroyCommandPool(m_device->device(), command_pool_two, NULL);
2309}
2310
2311TEST_F(VkLayerTest, InvalidDescriptorPoolConsistency) {
2312 VkResult err;
2313
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002314 TEST_DESCRIPTION(
2315 "Allocate descriptor sets from one DS pool and "
2316 "attempt to delete them from another.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002317
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002318 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "FreeDescriptorSets is attempting to free descriptorSet");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002319
2320 ASSERT_NO_FATAL_FAILURE(InitState());
2321 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2322
2323 VkDescriptorPoolSize ds_type_count = {};
2324 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
2325 ds_type_count.descriptorCount = 1;
2326
2327 VkDescriptorPoolCreateInfo ds_pool_ci = {};
2328 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2329 ds_pool_ci.pNext = NULL;
2330 ds_pool_ci.flags = 0;
2331 ds_pool_ci.maxSets = 1;
2332 ds_pool_ci.poolSizeCount = 1;
2333 ds_pool_ci.pPoolSizes = &ds_type_count;
2334
2335 VkDescriptorPool ds_pool_one;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002336 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_one);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002337 ASSERT_VK_SUCCESS(err);
2338
2339 // Create a second descriptor pool
2340 VkDescriptorPool ds_pool_two;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002341 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool_two);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002342 ASSERT_VK_SUCCESS(err);
2343
2344 VkDescriptorSetLayoutBinding dsl_binding = {};
2345 dsl_binding.binding = 0;
2346 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
2347 dsl_binding.descriptorCount = 1;
2348 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2349 dsl_binding.pImmutableSamplers = NULL;
2350
2351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
2352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2353 ds_layout_ci.pNext = NULL;
2354 ds_layout_ci.bindingCount = 1;
2355 ds_layout_ci.pBindings = &dsl_binding;
2356
2357 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002358 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002359 ASSERT_VK_SUCCESS(err);
2360
2361 VkDescriptorSet descriptorSet;
2362 VkDescriptorSetAllocateInfo alloc_info = {};
2363 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
2364 alloc_info.descriptorSetCount = 1;
2365 alloc_info.descriptorPool = ds_pool_one;
2366 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002367 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002368 ASSERT_VK_SUCCESS(err);
2369
2370 err = vkFreeDescriptorSets(m_device->device(), ds_pool_two, 1, &descriptorSet);
2371
2372 m_errorMonitor->VerifyFound();
2373
2374 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2375 vkDestroyDescriptorPool(m_device->device(), ds_pool_one, NULL);
2376 vkDestroyDescriptorPool(m_device->device(), ds_pool_two, NULL);
2377}
2378
2379TEST_F(VkLayerTest, CreateUnknownObject) {
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002380 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00788);
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002381
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002382 TEST_DESCRIPTION("Pass an invalid image object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002383
2384 ASSERT_NO_FATAL_FAILURE(InitState());
2385
2386 // Pass bogus handle into GetImageMemoryRequirements
2387 VkMemoryRequirements mem_reqs;
2388 uint64_t fakeImageHandle = 0xCADECADE;
2389 VkImage fauxImage = reinterpret_cast<VkImage &>(fakeImageHandle);
2390
2391 vkGetImageMemoryRequirements(m_device->device(), fauxImage, &mem_reqs);
2392
2393 m_errorMonitor->VerifyFound();
2394}
2395
Mike Schuchardt17838902017-02-21 09:48:06 -07002396TEST_F(VkLayerTest, UseObjectWithWrongDevice) {
2397 TEST_DESCRIPTION(
2398 "Try to destroy a render pass object using a device other than the one it was created on. "
2399 "This should generate a distinct error from the invalid handle error.");
2400 // Create first device and renderpass
2401 ASSERT_NO_FATAL_FAILURE(InitState());
2402 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
2403
2404 // Create second device
2405 float priorities[] = {1.0f};
2406 VkDeviceQueueCreateInfo queue_info{};
2407 queue_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
2408 queue_info.pNext = NULL;
2409 queue_info.flags = 0;
2410 queue_info.queueFamilyIndex = 0;
2411 queue_info.queueCount = 1;
2412 queue_info.pQueuePriorities = &priorities[0];
2413
2414 VkDeviceCreateInfo device_create_info = {};
2415 auto features = m_device->phy().features();
2416 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
2417 device_create_info.pNext = NULL;
2418 device_create_info.queueCreateInfoCount = 1;
2419 device_create_info.pQueueCreateInfos = &queue_info;
2420 device_create_info.enabledLayerCount = 0;
2421 device_create_info.ppEnabledLayerNames = NULL;
2422 device_create_info.pEnabledFeatures = &features;
2423
2424 VkDevice second_device;
2425 ASSERT_VK_SUCCESS(vkCreateDevice(gpu(), &device_create_info, NULL, &second_device));
2426
2427 // Try to destroy the renderpass from the first device using the second device
2428 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00399);
2429 vkDestroyRenderPass(second_device, m_renderPass, NULL);
2430 m_errorMonitor->VerifyFound();
2431
2432 vkDestroyDevice(second_device, NULL);
2433}
2434
Karl Schultz6addd812016-02-02 17:17:23 -07002435TEST_F(VkLayerTest, PipelineNotBound) {
2436 VkResult err;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002437
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002438 TEST_DESCRIPTION("Pass in an invalid pipeline object handle into a Vulkan API call.");
Mark Lobodzinskifc5cc662016-05-02 17:17:41 -06002439
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002441
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002442 ASSERT_NO_FATAL_FAILURE(InitState());
2443 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002444
Chia-I Wu1b99bb22015-10-27 19:25:11 +08002445 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002446 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2447 ds_type_count.descriptorCount = 1;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002448
2449 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002450 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
2451 ds_pool_ci.pNext = NULL;
2452 ds_pool_ci.maxSets = 1;
2453 ds_pool_ci.poolSizeCount = 1;
2454 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002455
2456 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002457 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002458 ASSERT_VK_SUCCESS(err);
2459
2460 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002461 dsl_binding.binding = 0;
2462 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
2463 dsl_binding.descriptorCount = 1;
2464 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
2465 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002466
2467 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002468 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
2469 ds_layout_ci.pNext = NULL;
2470 ds_layout_ci.bindingCount = 1;
2471 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002472
2473 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002474 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002475 ASSERT_VK_SUCCESS(err);
2476
2477 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002478 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08002479 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07002480 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06002481 alloc_info.descriptorPool = ds_pool;
2482 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002483 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002484 ASSERT_VK_SUCCESS(err);
2485
2486 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002487 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
2488 pipeline_layout_ci.pNext = NULL;
2489 pipeline_layout_ci.setLayoutCount = 1;
2490 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002491
2492 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002493 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002494 ASSERT_VK_SUCCESS(err);
2495
Mark Youngad779052016-01-06 14:26:04 -07002496 VkPipeline badPipeline = (VkPipeline)((size_t)0xbaadb1be);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002497
Tony Barbour552f6c02016-12-21 14:34:07 -07002498 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002499 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, badPipeline);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002500
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002501 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002502
Chia-I Wuf7458c52015-10-26 21:10:41 +08002503 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
2504 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
2505 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002506}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002507
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002508TEST_F(VkLayerTest, BindImageInvalidMemoryType) {
2509 VkResult err;
2510
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07002511 TEST_DESCRIPTION(
2512 "Test validation check for an invalid memory type index "
2513 "during bind[Buffer|Image]Memory time");
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002514
Mark Lobodzinskibc185762016-06-15 16:28:53 -06002515 ASSERT_NO_FATAL_FAILURE(InitState());
2516
2517 // Create an image, allocate memory, set a bad typeIndex and then try to
2518 // bind it
2519 VkImage image;
2520 VkDeviceMemory mem;
2521 VkMemoryRequirements mem_reqs;
2522 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2523 const int32_t tex_width = 32;
2524 const int32_t tex_height = 32;
2525
2526 VkImageCreateInfo image_create_info = {};
2527 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2528 image_create_info.pNext = NULL;
2529 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2530 image_create_info.format = tex_format;
2531 image_create_info.extent.width = tex_width;
2532 image_create_info.extent.height = tex_height;
2533 image_create_info.extent.depth = 1;
2534 image_create_info.mipLevels = 1;
2535 image_create_info.arrayLayers = 1;
2536 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2537 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
2538 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2539 image_create_info.flags = 0;
2540
2541 VkMemoryAllocateInfo mem_alloc = {};
2542 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2543 mem_alloc.pNext = NULL;
2544 mem_alloc.allocationSize = 0;
2545 mem_alloc.memoryTypeIndex = 0;
2546
2547 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
2548 ASSERT_VK_SUCCESS(err);
2549
2550 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
2551 mem_alloc.allocationSize = mem_reqs.size;
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002552
2553 // Introduce Failure, select invalid TypeIndex
2554 VkPhysicalDeviceMemoryProperties memory_info;
2555
2556 vkGetPhysicalDeviceMemoryProperties(gpu(), &memory_info);
2557 unsigned int i;
2558 for (i = 0; i < memory_info.memoryTypeCount; i++) {
2559 if ((mem_reqs.memoryTypeBits & (1 << i)) == 0) {
2560 mem_alloc.memoryTypeIndex = i;
2561 break;
2562 }
2563 }
2564 if (i >= memory_info.memoryTypeCount) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002565 printf(" No invalid memory type index could be found; skipped.\n");
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002566 vkDestroyImage(m_device->device(), image, NULL);
2567 return;
2568 }
2569
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002570 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 -06002571
2572 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
2573 ASSERT_VK_SUCCESS(err);
2574
2575 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2576 (void)err;
2577
2578 m_errorMonitor->VerifyFound();
2579
2580 vkDestroyImage(m_device->device(), image, NULL);
2581 vkFreeMemory(m_device->device(), mem, NULL);
2582}
Mike Stroyan80fc6c32016-06-20 15:42:29 -06002583
Karl Schultz6addd812016-02-02 17:17:23 -07002584TEST_F(VkLayerTest, BindInvalidMemory) {
2585 VkResult err;
2586 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002587
2588 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002589
Cortf801b982017-01-17 18:10:21 -08002590 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
Cort Strattonde748202017-02-17 12:50:01 -08002591 const int32_t tex_width = 256;
2592 const int32_t tex_height = 256;
Tobin Ehlisec598302015-09-15 15:02:17 -06002593
2594 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002595 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2596 image_create_info.pNext = NULL;
2597 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2598 image_create_info.format = tex_format;
2599 image_create_info.extent.width = tex_width;
2600 image_create_info.extent.height = tex_height;
2601 image_create_info.extent.depth = 1;
2602 image_create_info.mipLevels = 1;
2603 image_create_info.arrayLayers = 1;
2604 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002605 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Karl Schultz6addd812016-02-02 17:17:23 -07002606 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2607 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002608
Cortf801b982017-01-17 18:10:21 -08002609 VkBufferCreateInfo buffer_create_info = {};
2610 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
2611 buffer_create_info.pNext = NULL;
2612 buffer_create_info.flags = 0;
Cort Strattonde748202017-02-17 12:50:01 -08002613 buffer_create_info.size = 4 * 1024 * 1024;
2614 buffer_create_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
Cortf801b982017-01-17 18:10:21 -08002615 buffer_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tobin Ehlisec598302015-09-15 15:02:17 -06002616
Cortf801b982017-01-17 18:10:21 -08002617 // Create an image/buffer, allocate memory, free it, and then try to bind it
2618 {
2619 VkImage image = VK_NULL_HANDLE;
2620 VkBuffer buffer = VK_NULL_HANDLE;
2621 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2622 ASSERT_VK_SUCCESS(err);
2623 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2624 ASSERT_VK_SUCCESS(err);
2625 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2626 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2627 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002628
Cortf801b982017-01-17 18:10:21 -08002629 VkMemoryAllocateInfo image_mem_alloc = {}, buffer_mem_alloc = {};
2630 image_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2631 image_mem_alloc.allocationSize = image_mem_reqs.size;
2632 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_mem_alloc, 0);
2633 ASSERT_TRUE(pass);
2634 buffer_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2635 buffer_mem_alloc.allocationSize = buffer_mem_reqs.size;
2636 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_mem_alloc, 0);
2637 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002638
Cortf801b982017-01-17 18:10:21 -08002639 VkDeviceMemory image_mem = VK_NULL_HANDLE, buffer_mem = VK_NULL_HANDLE;
2640 err = vkAllocateMemory(device(), &image_mem_alloc, NULL, &image_mem);
2641 ASSERT_VK_SUCCESS(err);
2642 err = vkAllocateMemory(device(), &buffer_mem_alloc, NULL, &buffer_mem);
2643 ASSERT_VK_SUCCESS(err);
Tobin Ehlisec598302015-09-15 15:02:17 -06002644
Cortf801b982017-01-17 18:10:21 -08002645 vkFreeMemory(device(), image_mem, NULL);
2646 vkFreeMemory(device(), buffer_mem, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002647
Cortf801b982017-01-17 18:10:21 -08002648 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00809);
2649 err = vkBindImageMemory(device(), image, image_mem, 0);
2650 (void)err; // This may very well return an error.
2651 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002652
Cortf801b982017-01-17 18:10:21 -08002653 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00800);
2654 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2655 (void)err; // This may very well return an error.
2656 m_errorMonitor->VerifyFound();
Tobin Ehlisec598302015-09-15 15:02:17 -06002657
Cortf801b982017-01-17 18:10:21 -08002658 vkDestroyImage(m_device->device(), image, NULL);
2659 vkDestroyBuffer(m_device->device(), buffer, NULL);
2660 }
Cort Strattonc21601b2017-01-28 14:16:16 -08002661
2662 // Try to bind memory to an object that already has a memory binding
2663 {
2664 VkImage image = VK_NULL_HANDLE;
2665 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2666 ASSERT_VK_SUCCESS(err);
2667 VkBuffer buffer = VK_NULL_HANDLE;
2668 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2669 ASSERT_VK_SUCCESS(err);
2670 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2671 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2672 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2673 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2674 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2675 image_alloc_info.allocationSize = image_mem_reqs.size;
2676 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2677 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
2678 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2679 ASSERT_TRUE(pass);
2680 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2681 ASSERT_TRUE(pass);
2682 VkDeviceMemory image_mem, buffer_mem;
2683 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2684 ASSERT_VK_SUCCESS(err);
2685 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2686 ASSERT_VK_SUCCESS(err);
2687
2688 err = vkBindImageMemory(device(), image, image_mem, 0);
2689 ASSERT_VK_SUCCESS(err);
2690 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00803);
2691 err = vkBindImageMemory(device(), image, image_mem, 0);
2692 (void)err; // This may very well return an error.
2693 m_errorMonitor->VerifyFound();
2694
2695 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2696 ASSERT_VK_SUCCESS(err);
2697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00791);
2698 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2699 (void)err; // This may very well return an error.
2700 m_errorMonitor->VerifyFound();
2701
2702 vkFreeMemory(device(), image_mem, NULL);
2703 vkFreeMemory(device(), buffer_mem, NULL);
2704 vkDestroyImage(device(), image, NULL);
2705 vkDestroyBuffer(device(), buffer, NULL);
2706 }
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002707
Cort Strattonde748202017-02-17 12:50:01 -08002708 // Try to bind memory to an object with an invalid memoryOffset
Cort6c7dff72017-01-27 18:34:50 -08002709 {
2710 VkImage image = VK_NULL_HANDLE;
2711 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2712 ASSERT_VK_SUCCESS(err);
2713 VkBuffer buffer = VK_NULL_HANDLE;
2714 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2715 ASSERT_VK_SUCCESS(err);
2716 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2717 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2718 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2719 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2720 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002721 // Leave some extra space for alignment wiggle room
2722 image_alloc_info.allocationSize = image_mem_reqs.size + image_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002723 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Cort Strattonde748202017-02-17 12:50:01 -08002724 buffer_alloc_info.allocationSize = buffer_mem_reqs.size + buffer_mem_reqs.alignment;
Cort6c7dff72017-01-27 18:34:50 -08002725 pass = m_device->phy().set_memory_type(image_mem_reqs.memoryTypeBits, &image_alloc_info, 0);
2726 ASSERT_TRUE(pass);
2727 pass = m_device->phy().set_memory_type(buffer_mem_reqs.memoryTypeBits, &buffer_alloc_info, 0);
2728 ASSERT_TRUE(pass);
2729 VkDeviceMemory image_mem, buffer_mem;
2730 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2731 ASSERT_VK_SUCCESS(err);
2732 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2733 ASSERT_VK_SUCCESS(err);
2734
Cort Strattonde748202017-02-17 12:50:01 -08002735 // Test unaligned memory offset
2736 {
2737 if (image_mem_reqs.alignment > 1) {
2738 VkDeviceSize image_offset = 1;
2739 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02178);
2740 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2741 (void)err; // This may very well return an error.
2742 m_errorMonitor->VerifyFound();
2743 }
Cort6c7dff72017-01-27 18:34:50 -08002744
Cort Strattonde748202017-02-17 12:50:01 -08002745 if (buffer_mem_reqs.alignment > 1) {
2746 VkDeviceSize buffer_offset = 1;
2747 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02174);
2748 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2749 (void)err; // This may very well return an error.
2750 m_errorMonitor->VerifyFound();
2751 }
2752 }
2753
2754 // Test memory offsets outside the memory allocation
2755 {
2756 VkDeviceSize image_offset =
2757 (image_alloc_info.allocationSize + image_mem_reqs.alignment) & ~(image_mem_reqs.alignment - 1);
2758 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00805);
2759 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2760 (void)err; // This may very well return an error.
2761 m_errorMonitor->VerifyFound();
2762
2763 VkDeviceSize buffer_offset =
2764 (buffer_alloc_info.allocationSize + buffer_mem_reqs.alignment) & ~(buffer_mem_reqs.alignment - 1);
2765 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00793);
2766 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2767 (void)err; // This may very well return an error.
2768 m_errorMonitor->VerifyFound();
2769 }
2770
2771 // Test memory offsets within the memory allocation, but which leave too little memory for
2772 // the resource.
2773 {
2774 VkDeviceSize image_offset = (image_mem_reqs.size - 1) & ~(image_mem_reqs.alignment - 1);
2775 if (image_offset > 0) {
2776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02179);
2777 err = vkBindImageMemory(device(), image, image_mem, image_offset);
2778 (void)err; // This may very well return an error.
2779 m_errorMonitor->VerifyFound();
2780 }
2781
2782 VkDeviceSize buffer_offset = (buffer_mem_reqs.size - 1) & ~(buffer_mem_reqs.alignment - 1);
2783 if (buffer_offset > 0) {
2784 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02175);
2785 err = vkBindBufferMemory(device(), buffer, buffer_mem, buffer_offset);
2786 (void)err; // This may very well return an error.
2787 m_errorMonitor->VerifyFound();
2788 }
2789 }
Cort6c7dff72017-01-27 18:34:50 -08002790
2791 vkFreeMemory(device(), image_mem, NULL);
2792 vkFreeMemory(device(), buffer_mem, NULL);
2793 vkDestroyImage(device(), image, NULL);
2794 vkDestroyBuffer(device(), buffer, NULL);
2795 }
2796
Cort Stratton4c38bb52017-01-28 13:33:10 -08002797 // Try to bind memory to an object with an invalid memory type
2798 {
2799 VkImage image = VK_NULL_HANDLE;
2800 err = vkCreateImage(device(), &image_create_info, NULL, &image);
2801 ASSERT_VK_SUCCESS(err);
2802 VkBuffer buffer = VK_NULL_HANDLE;
2803 err = vkCreateBuffer(device(), &buffer_create_info, NULL, &buffer);
2804 ASSERT_VK_SUCCESS(err);
2805 VkMemoryRequirements image_mem_reqs = {}, buffer_mem_reqs = {};
2806 vkGetImageMemoryRequirements(device(), image, &image_mem_reqs);
2807 vkGetBufferMemoryRequirements(device(), buffer, &buffer_mem_reqs);
2808 VkMemoryAllocateInfo image_alloc_info = {}, buffer_alloc_info = {};
2809 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2810 image_alloc_info.allocationSize = image_mem_reqs.size;
2811 buffer_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2812 buffer_alloc_info.allocationSize = buffer_mem_reqs.size;
Cort Strattonccc90e32017-02-04 13:47:42 -08002813 // Create a mask of available memory types *not* supported by these resources,
2814 // and try to use one of them.
Cort Stratton4c38bb52017-01-28 13:33:10 -08002815 VkPhysicalDeviceMemoryProperties memory_properties = {};
2816 vkGetPhysicalDeviceMemoryProperties(m_device->phy().handle(), &memory_properties);
Cort Strattonccc90e32017-02-04 13:47:42 -08002817 VkDeviceMemory image_mem, buffer_mem;
2818
Cort Stratton4c38bb52017-01-28 13:33:10 -08002819 uint32_t image_unsupported_mem_type_bits = ((1 << memory_properties.memoryTypeCount) - 1) & ~image_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002820 if (image_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002821 pass = m_device->phy().set_memory_type(image_unsupported_mem_type_bits, &image_alloc_info, 0);
2822 ASSERT_TRUE(pass);
2823 err = vkAllocateMemory(device(), &image_alloc_info, NULL, &image_mem);
2824 ASSERT_VK_SUCCESS(err);
2825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00806);
2826 err = vkBindImageMemory(device(), image, image_mem, 0);
2827 (void)err; // This may very well return an error.
2828 m_errorMonitor->VerifyFound();
2829 vkFreeMemory(device(), image_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002830 }
2831
Cort Stratton4c38bb52017-01-28 13:33:10 -08002832 uint32_t buffer_unsupported_mem_type_bits =
2833 ((1 << memory_properties.memoryTypeCount) - 1) & ~buffer_mem_reqs.memoryTypeBits;
Cort Strattonccc90e32017-02-04 13:47:42 -08002834 if (buffer_unsupported_mem_type_bits != 0) {
Dave Houlton584d51e2017-02-16 12:52:54 -07002835 pass = m_device->phy().set_memory_type(buffer_unsupported_mem_type_bits, &buffer_alloc_info, 0);
2836 ASSERT_TRUE(pass);
2837 err = vkAllocateMemory(device(), &buffer_alloc_info, NULL, &buffer_mem);
2838 ASSERT_VK_SUCCESS(err);
2839 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00797);
2840 err = vkBindBufferMemory(device(), buffer, buffer_mem, 0);
2841 (void)err; // This may very well return an error.
2842 m_errorMonitor->VerifyFound();
2843 vkFreeMemory(device(), buffer_mem, NULL);
Cort Strattonccc90e32017-02-04 13:47:42 -08002844 }
Cort Stratton4c38bb52017-01-28 13:33:10 -08002845
Cort Stratton4c38bb52017-01-28 13:33:10 -08002846 vkDestroyImage(device(), image, NULL);
2847 vkDestroyBuffer(device(), buffer, NULL);
2848 }
2849
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002850 // Try to bind memory to an image created with sparse memory flags
2851 {
2852 VkImageCreateInfo sparse_image_create_info = image_create_info;
2853 sparse_image_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2854 VkImageFormatProperties image_format_properties = {};
2855 err = vkGetPhysicalDeviceImageFormatProperties(m_device->phy().handle(), sparse_image_create_info.format,
2856 sparse_image_create_info.imageType, sparse_image_create_info.tiling,
2857 sparse_image_create_info.usage, sparse_image_create_info.flags,
2858 &image_format_properties);
2859 if (!m_device->phy().features().sparseResidencyImage2D || err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
2860 // most likely means sparse formats aren't supported here; skip this test.
2861 } else {
2862 ASSERT_VK_SUCCESS(err);
2863 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07002864 printf(" Sparse image format not supported; skipped.\n");
Cort Strattonf1d8a4a2017-01-28 14:17:04 -08002865 return;
2866 } else {
2867 VkImage sparse_image = VK_NULL_HANDLE;
2868 err = vkCreateImage(m_device->device(), &sparse_image_create_info, NULL, &sparse_image);
2869 ASSERT_VK_SUCCESS(err);
2870 VkMemoryRequirements sparse_mem_reqs = {};
2871 vkGetImageMemoryRequirements(m_device->device(), sparse_image, &sparse_mem_reqs);
2872 if (sparse_mem_reqs.memoryTypeBits != 0) {
2873 VkMemoryAllocateInfo sparse_mem_alloc = {};
2874 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2875 sparse_mem_alloc.pNext = NULL;
2876 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2877 sparse_mem_alloc.memoryTypeIndex = 0;
2878 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2879 ASSERT_TRUE(pass);
2880 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2881 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2882 ASSERT_VK_SUCCESS(err);
2883 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00804);
2884 err = vkBindImageMemory(m_device->device(), sparse_image, sparse_mem, 0);
2885 // This may very well return an error.
2886 (void)err;
2887 m_errorMonitor->VerifyFound();
2888 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2889 }
2890 vkDestroyImage(m_device->device(), sparse_image, NULL);
2891 }
2892 }
2893 }
2894
2895 // Try to bind memory to a buffer created with sparse memory flags
2896 {
2897 VkBufferCreateInfo sparse_buffer_create_info = buffer_create_info;
2898 sparse_buffer_create_info.flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
2899 if (!m_device->phy().features().sparseResidencyBuffer) {
2900 // most likely means sparse formats aren't supported here; skip this test.
2901 } else {
2902 VkBuffer sparse_buffer = VK_NULL_HANDLE;
2903 err = vkCreateBuffer(m_device->device(), &sparse_buffer_create_info, NULL, &sparse_buffer);
2904 ASSERT_VK_SUCCESS(err);
2905 VkMemoryRequirements sparse_mem_reqs = {};
2906 vkGetBufferMemoryRequirements(m_device->device(), sparse_buffer, &sparse_mem_reqs);
2907 if (sparse_mem_reqs.memoryTypeBits != 0) {
2908 VkMemoryAllocateInfo sparse_mem_alloc = {};
2909 sparse_mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2910 sparse_mem_alloc.pNext = NULL;
2911 sparse_mem_alloc.allocationSize = sparse_mem_reqs.size;
2912 sparse_mem_alloc.memoryTypeIndex = 0;
2913 pass = m_device->phy().set_memory_type(sparse_mem_reqs.memoryTypeBits, &sparse_mem_alloc, 0);
2914 ASSERT_TRUE(pass);
2915 VkDeviceMemory sparse_mem = VK_NULL_HANDLE;
2916 err = vkAllocateMemory(m_device->device(), &sparse_mem_alloc, NULL, &sparse_mem);
2917 ASSERT_VK_SUCCESS(err);
2918 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00792);
2919 err = vkBindBufferMemory(m_device->device(), sparse_buffer, sparse_mem, 0);
2920 // This may very well return an error.
2921 (void)err;
2922 m_errorMonitor->VerifyFound();
2923 vkFreeMemory(m_device->device(), sparse_mem, NULL);
2924 }
2925 vkDestroyBuffer(m_device->device(), sparse_buffer, NULL);
2926 }
2927 }
Tobin Ehlisec598302015-09-15 15:02:17 -06002928}
2929
Karl Schultz6addd812016-02-02 17:17:23 -07002930TEST_F(VkLayerTest, BindMemoryToDestroyedObject) {
2931 VkResult err;
2932 bool pass;
Tobin Ehlisec598302015-09-15 15:02:17 -06002933
Karl Schultzf78bcdd2016-11-30 12:36:01 -07002934 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00808);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06002935
Tobin Ehlisec598302015-09-15 15:02:17 -06002936 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisec598302015-09-15 15:02:17 -06002937
Karl Schultz6addd812016-02-02 17:17:23 -07002938 // Create an image object, allocate memory, destroy the object and then try
2939 // to bind it
2940 VkImage image;
2941 VkDeviceMemory mem;
2942 VkMemoryRequirements mem_reqs;
Tobin Ehlisec598302015-09-15 15:02:17 -06002943
Karl Schultz6addd812016-02-02 17:17:23 -07002944 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
2945 const int32_t tex_width = 32;
2946 const int32_t tex_height = 32;
Tobin Ehlisec598302015-09-15 15:02:17 -06002947
2948 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002949 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
2950 image_create_info.pNext = NULL;
2951 image_create_info.imageType = VK_IMAGE_TYPE_2D;
2952 image_create_info.format = tex_format;
2953 image_create_info.extent.width = tex_width;
2954 image_create_info.extent.height = tex_height;
2955 image_create_info.extent.depth = 1;
2956 image_create_info.mipLevels = 1;
2957 image_create_info.arrayLayers = 1;
2958 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
2959 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
2960 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
2961 image_create_info.flags = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002962
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002963 VkMemoryAllocateInfo mem_alloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -07002964 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
2965 mem_alloc.pNext = NULL;
2966 mem_alloc.allocationSize = 0;
2967 mem_alloc.memoryTypeIndex = 0;
Tobin Ehlisec598302015-09-15 15:02:17 -06002968
Chia-I Wuf7458c52015-10-26 21:10:41 +08002969 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlisec598302015-09-15 15:02:17 -06002970 ASSERT_VK_SUCCESS(err);
2971
Karl Schultz6addd812016-02-02 17:17:23 -07002972 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
Tobin Ehlisec598302015-09-15 15:02:17 -06002973
2974 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06002975 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -06002976 ASSERT_TRUE(pass);
Tobin Ehlisec598302015-09-15 15:02:17 -06002977
2978 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +08002979 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlisec598302015-09-15 15:02:17 -06002980 ASSERT_VK_SUCCESS(err);
2981
2982 // Introduce validation failure, destroy Image object before binding
Chia-I Wuf7458c52015-10-26 21:10:41 +08002983 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehlisec598302015-09-15 15:02:17 -06002984 ASSERT_VK_SUCCESS(err);
2985
2986 // Now Try to bind memory to this destroyed object
2987 err = vkBindImageMemory(m_device->device(), image, mem, 0);
2988 // This may very well return an error.
Karl Schultz6addd812016-02-02 17:17:23 -07002989 (void)err;
Tobin Ehlisec598302015-09-15 15:02:17 -06002990
Chris Forbes8f36a8a2016-04-07 13:21:07 +12002991 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06002992
Chia-I Wuf7458c52015-10-26 21:10:41 +08002993 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06002994}
Tobin Ehlisa1c28562015-10-23 16:00:08 -06002995
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07002996TEST_F(VkLayerTest, CreatePipelineBadVertexAttributeFormat) {
2997 TEST_DESCRIPTION("Test that pipeline validation catches invalid vertex attribute formats");
2998
2999 ASSERT_NO_FATAL_FAILURE(InitState());
3000 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3001
3002 VkVertexInputBindingDescription input_binding;
3003 memset(&input_binding, 0, sizeof(input_binding));
3004
3005 VkVertexInputAttributeDescription input_attribs;
3006 memset(&input_attribs, 0, sizeof(input_attribs));
3007
3008 // Pick a really bad format for this purpose and make sure it should fail
3009 input_attribs.format = VK_FORMAT_BC2_UNORM_BLOCK;
3010 VkFormatProperties format_props = m_device->format_properties(input_attribs.format);
3011 if ((format_props.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) != 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07003012 printf(" Format unsuitable for test; skipped.\n");
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003013 return;
3014 }
3015
3016 input_attribs.location = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003017 char const *vsSource =
3018 "#version 450\n"
3019 "\n"
3020 "out gl_PerVertex {\n"
3021 " vec4 gl_Position;\n"
3022 "};\n"
3023 "void main(){\n"
3024 " gl_Position = vec4(1);\n"
3025 "}\n";
3026 char const *fsSource =
3027 "#version 450\n"
3028 "\n"
3029 "layout(location=0) out vec4 color;\n"
3030 "void main(){\n"
3031 " color = vec4(1);\n"
3032 "}\n";
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -07003033
3034 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01413);
3035 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3036 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3037
3038 VkPipelineObj pipe(m_device);
3039 pipe.AddColorAttachment();
3040 pipe.AddShader(&vs);
3041 pipe.AddShader(&fs);
3042
3043 pipe.AddVertexInputBindings(&input_binding, 1);
3044 pipe.AddVertexInputAttribs(&input_attribs, 1);
3045
3046 VkDescriptorSetObj descriptorSet(m_device);
3047 descriptorSet.AppendDummy();
3048 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
3049
3050 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
3051
3052 m_errorMonitor->VerifyFound();
3053}
3054
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003055TEST_F(VkLayerTest, ImageSampleCounts) {
Jeremy Hayes0d104082017-02-21 10:24:16 -07003056 TEST_DESCRIPTION("Use bad sample counts in image transfer calls to trigger validation errors.");
3057 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003058
3059 VkMemoryPropertyFlags reqs = 0;
3060 VkImageCreateInfo image_create_info = {};
3061 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3062 image_create_info.pNext = NULL;
3063 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3064 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3065 image_create_info.extent.width = 256;
3066 image_create_info.extent.height = 256;
3067 image_create_info.extent.depth = 1;
3068 image_create_info.mipLevels = 1;
3069 image_create_info.arrayLayers = 1;
3070 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3071 image_create_info.flags = 0;
3072
3073 VkImageBlit blit_region = {};
3074 blit_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3075 blit_region.srcSubresource.baseArrayLayer = 0;
3076 blit_region.srcSubresource.layerCount = 1;
3077 blit_region.srcSubresource.mipLevel = 0;
3078 blit_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3079 blit_region.dstSubresource.baseArrayLayer = 0;
3080 blit_region.dstSubresource.layerCount = 1;
3081 blit_region.dstSubresource.mipLevel = 0;
3082
3083 // Create two images, the source with sampleCount = 2, and attempt to blit
3084 // between them
3085 {
3086 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003087 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003088 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003089 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003090 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003091 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003092 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003093 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003094 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003095 m_errorMonitor->SetDesiredFailureMsg(
3096 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3097 "was created with a sample count of VK_SAMPLE_COUNT_2_BIT but must be VK_SAMPLE_COUNT_1_BIT");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003098 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3099 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003100 m_errorMonitor->VerifyFound();
3101 m_commandBuffer->EndCommandBuffer();
3102 }
3103
3104 // Create two images, the dest with sampleCount = 4, and attempt to blit
3105 // between them
3106 {
3107 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003108 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003109 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003110 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003111 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003112 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003113 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003114 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003115 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003116 m_errorMonitor->SetDesiredFailureMsg(
3117 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3118 "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 -06003119 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3120 dst_image.handle(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, 1, &blit_region, VK_FILTER_NEAREST);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003121 m_errorMonitor->VerifyFound();
3122 m_commandBuffer->EndCommandBuffer();
3123 }
3124
3125 VkBufferImageCopy copy_region = {};
3126 copy_region.bufferRowLength = 128;
3127 copy_region.bufferImageHeight = 128;
3128 copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3129 copy_region.imageSubresource.layerCount = 1;
3130 copy_region.imageExtent.height = 64;
3131 copy_region.imageExtent.width = 64;
3132 copy_region.imageExtent.depth = 1;
3133
3134 // Create src buffer and dst image with sampleCount = 4 and attempt to copy
3135 // buffer to image
3136 {
3137 vk_testing::Buffer src_buffer;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003138 src_buffer.init_as_src(*m_device, 128 * 128 * 4, reqs);
3139 image_create_info.samples = VK_SAMPLE_COUNT_8_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003140 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003141 vk_testing::Image dst_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003142 dst_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003143 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003144 m_errorMonitor->SetDesiredFailureMsg(
3145 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3146 "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 -06003147 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), src_buffer.handle(), dst_image.handle(),
3148 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &copy_region);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003149 m_errorMonitor->VerifyFound();
3150 m_commandBuffer->EndCommandBuffer();
3151 }
3152
3153 // Create dst buffer and src image with sampleCount = 2 and attempt to copy
3154 // image to buffer
3155 {
3156 vk_testing::Buffer dst_buffer;
3157 dst_buffer.init_as_dst(*m_device, 128 * 128 * 4, reqs);
3158 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003159 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003160 vk_testing::Image src_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003161 src_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003162 m_commandBuffer->BeginCommandBuffer();
Jeremy Hayes0d104082017-02-21 10:24:16 -07003163 m_errorMonitor->SetDesiredFailureMsg(
3164 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3165 "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 -06003166 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), src_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
Mark Lobodzinski9cfc1292016-08-23 16:18:17 -06003167 dst_buffer.handle(), 1, &copy_region);
3168 m_errorMonitor->VerifyFound();
3169 m_commandBuffer->EndCommandBuffer();
3170 }
3171}
3172
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003173TEST_F(VkLayerTest, BlitImageFormats) {
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003174 ASSERT_NO_FATAL_FAILURE(InitState());
3175
3176 VkImageObj src_image(m_device);
3177 src_image.init(64, 64, VK_FORMAT_A2B10G10R10_UINT_PACK32, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
3178 VkImageObj dst_image(m_device);
3179 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
3180 VkImageObj dst_image2(m_device);
Mike Stroyan131f3e72016-10-18 11:10:23 -06003181 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 -06003182
3183 VkImageBlit blitRegion = {};
3184 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3185 blitRegion.srcSubresource.baseArrayLayer = 0;
3186 blitRegion.srcSubresource.layerCount = 1;
3187 blitRegion.srcSubresource.mipLevel = 0;
3188 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3189 blitRegion.dstSubresource.baseArrayLayer = 0;
3190 blitRegion.dstSubresource.layerCount = 1;
3191 blitRegion.dstSubresource.mipLevel = 0;
3192
Dave Houlton34df4cb2016-12-01 16:43:06 -07003193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
3194
3195 // TODO: there are 9 permutations of signed, unsigned, & other for source and dest
3196 // this test is only checking 2 of them at the moment
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003197
3198 // Unsigned int vs not an int
Tony Barbour552f6c02016-12-21 14:34:07 -07003199 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003200 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image.image(), dst_image.layout(), 1,
3201 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003202
3203 m_errorMonitor->VerifyFound();
3204
Dave Houlton34df4cb2016-12-01 16:43:06 -07003205 // Test should generate 2 VU failures
3206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02190);
3207 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02191);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003208
3209 // Unsigned int vs signed int
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003210 vkCmdBlitImage(m_commandBuffer->handle(), src_image.image(), src_image.layout(), dst_image2.image(), dst_image2.layout(), 1,
3211 &blitRegion, VK_FILTER_NEAREST);
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003212
Dave Houlton34df4cb2016-12-01 16:43:06 -07003213 // TODO: Note that this only verifies that at least one of the VU enums was found
3214 // 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 -06003215 m_errorMonitor->VerifyFound();
3216
Tony Barbour552f6c02016-12-21 14:34:07 -07003217 m_commandBuffer->EndCommandBuffer();
Mike Stroyanac5afeb2016-10-17 13:58:10 -06003218}
3219
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003220TEST_F(VkLayerTest, DSImageTransferGranularityTests) {
3221 VkResult err;
3222 bool pass;
3223
3224 TEST_DESCRIPTION("Tests for validaiton of Queue Family property minImageTransferGranularity.");
3225 ASSERT_NO_FATAL_FAILURE(InitState());
3226
3227 // If w/d/h granularity is 1, test is not meaningful
3228 // TODO: When virtual device limits are available, create a set of limits for this test that
3229 // will always have a granularity of > 1 for w, h, and d
3230 auto index = m_device->graphics_queue_node_index_;
3231 auto queue_family_properties = m_device->phy().queue_properties();
3232
3233 if ((queue_family_properties[index].minImageTransferGranularity.depth < 4) ||
3234 (queue_family_properties[index].minImageTransferGranularity.width < 4) ||
3235 (queue_family_properties[index].minImageTransferGranularity.height < 4)) {
3236 return;
3237 }
3238
3239 // Create two images of different types and try to copy between them
3240 VkImage srcImage;
3241 VkImage dstImage;
3242 VkDeviceMemory srcMem;
3243 VkDeviceMemory destMem;
3244 VkMemoryRequirements memReqs;
3245
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003246 VkImageCreateInfo image_create_info = {};
3247 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
3248 image_create_info.pNext = NULL;
3249 image_create_info.imageType = VK_IMAGE_TYPE_2D;
3250 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
3251 image_create_info.extent.width = 32;
3252 image_create_info.extent.height = 32;
3253 image_create_info.extent.depth = 1;
3254 image_create_info.mipLevels = 1;
3255 image_create_info.arrayLayers = 4;
3256 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
3257 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
3258 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
3259 image_create_info.flags = 0;
3260
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003261 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003262 ASSERT_VK_SUCCESS(err);
3263
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003264 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003265 ASSERT_VK_SUCCESS(err);
3266
3267 // Allocate memory
3268 VkMemoryAllocateInfo memAlloc = {};
3269 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
3270 memAlloc.pNext = NULL;
3271 memAlloc.allocationSize = 0;
3272 memAlloc.memoryTypeIndex = 0;
3273
3274 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
3275 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003276 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003277 ASSERT_TRUE(pass);
3278 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
3279 ASSERT_VK_SUCCESS(err);
3280
3281 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
3282 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003283 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003284 ASSERT_VK_SUCCESS(err);
3285 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
3286 ASSERT_VK_SUCCESS(err);
3287
3288 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
3289 ASSERT_VK_SUCCESS(err);
3290 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
3291 ASSERT_VK_SUCCESS(err);
3292
Tony Barbour552f6c02016-12-21 14:34:07 -07003293 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003294 VkImageCopy copyRegion;
3295 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3296 copyRegion.srcSubresource.mipLevel = 0;
3297 copyRegion.srcSubresource.baseArrayLayer = 0;
3298 copyRegion.srcSubresource.layerCount = 1;
3299 copyRegion.srcOffset.x = 0;
3300 copyRegion.srcOffset.y = 0;
3301 copyRegion.srcOffset.z = 0;
3302 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3303 copyRegion.dstSubresource.mipLevel = 0;
3304 copyRegion.dstSubresource.baseArrayLayer = 0;
3305 copyRegion.dstSubresource.layerCount = 1;
3306 copyRegion.dstOffset.x = 0;
3307 copyRegion.dstOffset.y = 0;
3308 copyRegion.dstOffset.z = 0;
3309 copyRegion.extent.width = 1;
3310 copyRegion.extent.height = 1;
3311 copyRegion.extent.depth = 1;
3312
3313 // Introduce failure by setting srcOffset to a bad granularity value
3314 copyRegion.srcOffset.y = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003315 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3316 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003317 m_errorMonitor->VerifyFound();
3318
3319 // Introduce failure by setting extent to a bad granularity value
3320 copyRegion.srcOffset.y = 0;
3321 copyRegion.extent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3323 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003324 m_errorMonitor->VerifyFound();
3325
3326 // Now do some buffer/image copies
3327 vk_testing::Buffer buffer;
3328 VkMemoryPropertyFlags reqs = 0;
3329 buffer.init_as_dst(*m_device, 128 * 128, reqs);
3330 VkBufferImageCopy region = {};
3331 region.bufferOffset = 0;
3332 region.bufferRowLength = 3;
3333 region.bufferImageHeight = 128;
3334 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3335 region.imageSubresource.layerCount = 1;
3336 region.imageExtent.height = 16;
3337 region.imageExtent.width = 16;
3338 region.imageExtent.depth = 1;
3339 region.imageOffset.x = 0;
3340 region.imageOffset.y = 0;
3341 region.imageOffset.z = 0;
3342
3343 // Introduce failure by setting bufferRowLength to a bad granularity value
3344 region.bufferRowLength = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003345 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3346 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3347 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003348 m_errorMonitor->VerifyFound();
3349 region.bufferRowLength = 128;
3350
3351 // Introduce failure by setting bufferOffset to a bad granularity value
3352 region.bufferOffset = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003353 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3354 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3355 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003356 m_errorMonitor->VerifyFound();
3357 region.bufferOffset = 0;
3358
3359 // Introduce failure by setting bufferImageHeight to a bad granularity value
3360 region.bufferImageHeight = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3362 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3363 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003364 m_errorMonitor->VerifyFound();
3365 region.bufferImageHeight = 128;
3366
3367 // Introduce failure by setting imageExtent to a bad granularity value
3368 region.imageExtent.width = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003369 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3370 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, buffer.handle(), 1,
3371 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003372 m_errorMonitor->VerifyFound();
3373 region.imageExtent.width = 16;
3374
3375 // Introduce failure by setting imageOffset to a bad granularity value
3376 region.imageOffset.z = 3;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003377 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "queue family image transfer granularity");
3378 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), srcImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
3379 &region);
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003380 m_errorMonitor->VerifyFound();
3381
Tony Barbour552f6c02016-12-21 14:34:07 -07003382 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskibb47ce72016-08-22 11:29:38 -06003383
3384 vkDestroyImage(m_device->device(), srcImage, NULL);
3385 vkDestroyImage(m_device->device(), dstImage, NULL);
3386 vkFreeMemory(m_device->device(), srcMem, NULL);
3387 vkFreeMemory(m_device->device(), destMem, NULL);
3388}
3389
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003390TEST_F(VkLayerTest, MismatchedQueueFamiliesOnSubmit) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003391 TEST_DESCRIPTION(
3392 "Submit command buffer created using one queue family and "
3393 "attempt to submit them on a queue created in a different "
3394 "queue family.");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003395
Cody Northropc31a84f2016-08-22 10:41:47 -06003396 ASSERT_NO_FATAL_FAILURE(InitState());
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07003397
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003398 // This test is meaningless unless we have multiple queue families
3399 auto queue_family_properties = m_device->phy().queue_properties();
3400 if (queue_family_properties.size() < 2) {
3401 return;
3402 }
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is being submitted on queue ");
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003404 // Get safe index of another queue family
3405 uint32_t other_queue_family = (m_device->graphics_queue_node_index_ == 0) ? 1 : 0;
3406 ASSERT_NO_FATAL_FAILURE(InitState());
3407 // Create a second queue using a different queue family
3408 VkQueue other_queue;
3409 vkGetDeviceQueue(m_device->device(), other_queue_family, 0, &other_queue);
3410
3411 // Record an empty cmd buffer
3412 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
3413 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
3414 vkBeginCommandBuffer(m_commandBuffer->handle(), &cmdBufBeginDesc);
3415 vkEndCommandBuffer(m_commandBuffer->handle());
3416
3417 // And submit on the wrong queue
3418 VkSubmitInfo submit_info = {};
3419 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
3420 submit_info.commandBufferCount = 1;
3421 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Tobin Ehlisfd213ea2016-08-10 17:10:46 -06003422 vkQueueSubmit(other_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003423
3424 m_errorMonitor->VerifyFound();
Mark Lobodzinski570efc62016-08-09 16:43:19 -06003425}
3426
Chris Forbes4c24a922016-11-16 08:59:10 +13003427TEST_F(VkLayerTest, RenderPassAttachmentIndexOutOfRange) {
3428 ASSERT_NO_FATAL_FAILURE(InitState());
3429
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003430 // There are no attachments, but refer to attachment 0.
3431 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbes4c24a922016-11-16 08:59:10 +13003432 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003433 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbes4c24a922016-11-16 08:59:10 +13003434 };
3435
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003436 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, subpasses, 0, nullptr};
Chris Forbes4c24a922016-11-16 08:59:10 +13003437 VkRenderPass rp;
3438
Chris Forbes2d9b2a82016-11-21 10:45:39 +13003439 // "... must be less than the total number of attachments ..."
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003440 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00325);
Chris Forbes4c24a922016-11-16 08:59:10 +13003441 vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3442 m_errorMonitor->VerifyFound();
3443}
3444
Chris Forbesa58c4522016-09-28 15:19:39 +13003445TEST_F(VkLayerTest, RenderPassPipelineSubpassMismatch) {
3446 TEST_DESCRIPTION("Use a pipeline for the wrong subpass in a render pass instance");
3447 ASSERT_NO_FATAL_FAILURE(InitState());
3448
3449 // A renderpass with two subpasses, both writing the same attachment.
3450 VkAttachmentDescription attach[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003451 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3452 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
3453 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesa58c4522016-09-28 15:19:39 +13003454 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003455 VkAttachmentReference ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Chris Forbesa58c4522016-09-28 15:19:39 +13003456 VkSubpassDescription subpasses[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003457 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
3458 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &ref, nullptr, nullptr, 0, nullptr},
Chris Forbesa58c4522016-09-28 15:19:39 +13003459 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003460 VkSubpassDependency dep = {0,
3461 1,
3462 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3463 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
3464 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3465 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
3466 VK_DEPENDENCY_BY_REGION_BIT};
3467 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, attach, 2, subpasses, 1, &dep};
Chris Forbesa58c4522016-09-28 15:19:39 +13003468 VkRenderPass rp;
3469 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3470 ASSERT_VK_SUCCESS(err);
3471
3472 VkImageObj image(m_device);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003473 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 +13003474 VkImageView imageView = image.targetView(VK_FORMAT_R8G8B8A8_UNORM);
3475
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003476 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &imageView, 32, 32, 1};
Chris Forbesa58c4522016-09-28 15:19:39 +13003477 VkFramebuffer fb;
3478 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
3479 ASSERT_VK_SUCCESS(err);
3480
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003481 char const *vsSource =
3482 "#version 450\n"
3483 "void main() { gl_Position = vec4(1); }\n";
3484 char const *fsSource =
3485 "#version 450\n"
3486 "layout(location=0) out vec4 color;\n"
3487 "void main() { color = vec4(1); }\n";
Chris Forbesa58c4522016-09-28 15:19:39 +13003488
3489 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
3490 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
3491 VkPipelineObj pipe(m_device);
3492 pipe.AddColorAttachment();
3493 pipe.AddShader(&vs);
3494 pipe.AddShader(&fs);
3495 VkViewport view_port = {};
3496 m_viewports.push_back(view_port);
3497 pipe.SetViewport(m_viewports);
3498 VkRect2D rect = {};
3499 m_scissors.push_back(rect);
3500 pipe.SetScissor(m_scissors);
3501
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003502 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 0, nullptr, 0, nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003503 VkPipelineLayout pl;
3504 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
3505 ASSERT_VK_SUCCESS(err);
3506 pipe.CreateVKPipeline(pl, rp);
3507
Tony Barbour552f6c02016-12-21 14:34:07 -07003508 m_commandBuffer->BeginCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003509
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003510 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
3511 nullptr,
3512 rp,
3513 fb,
3514 {{
3515 0, 0,
3516 },
3517 {32, 32}},
3518 0,
3519 nullptr};
Chris Forbesa58c4522016-09-28 15:19:39 +13003520
3521 // subtest 1: bind in the wrong subpass
3522 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3523 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003524 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 +13003525 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3526 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3527 m_errorMonitor->VerifyFound();
3528
3529 vkCmdEndRenderPass(m_commandBuffer->handle());
3530
3531 // subtest 2: bind in correct subpass, then transition to next subpass
3532 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
3533 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
3534 vkCmdNextSubpass(m_commandBuffer->handle(), VK_SUBPASS_CONTENTS_INLINE);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07003535 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 +13003536 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
3537 m_errorMonitor->VerifyFound();
3538
3539 vkCmdEndRenderPass(m_commandBuffer->handle());
3540
Tony Barbour552f6c02016-12-21 14:34:07 -07003541 m_commandBuffer->EndCommandBuffer();
Chris Forbesa58c4522016-09-28 15:19:39 +13003542
3543 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
3544 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
3545 vkDestroyRenderPass(m_device->device(), rp, nullptr);
3546}
3547
Tony Barbour4e919972016-08-09 13:27:40 -06003548TEST_F(VkLayerTest, RenderPassInvalidRenderArea) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003549 TEST_DESCRIPTION(
3550 "Generate INVALID_RENDER_AREA error by beginning renderpass"
3551 "with extent outside of framebuffer");
Tony Barbour4e919972016-08-09 13:27:40 -06003552 ASSERT_NO_FATAL_FAILURE(InitState());
3553 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3554
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003555 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3556 "Cannot execute a render pass with renderArea "
3557 "not within the bound of the framebuffer.");
Tony Barbour4e919972016-08-09 13:27:40 -06003558
3559 // Framebuffer for render target is 256x256, exceed that for INVALID_RENDER_AREA
3560 m_renderPassBeginInfo.renderArea.extent.width = 257;
3561 m_renderPassBeginInfo.renderArea.extent.height = 257;
Tony Barbour552f6c02016-12-21 14:34:07 -07003562 m_commandBuffer->BeginCommandBuffer();
3563 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour4e919972016-08-09 13:27:40 -06003564 m_errorMonitor->VerifyFound();
3565}
3566
3567TEST_F(VkLayerTest, DisabledIndependentBlend) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003568 TEST_DESCRIPTION(
3569 "Generate INDEPENDENT_BLEND by disabling independent "
3570 "blend and then specifying different blend states for two "
3571 "attachements");
Cody Northrop5703cc72016-08-19 09:57:10 -06003572 VkPhysicalDeviceFeatures features = {};
3573 features.independentBlend = VK_FALSE;
Cody Northropc31a84f2016-08-22 10:41:47 -06003574 ASSERT_NO_FATAL_FAILURE(InitState(&features));
Tony Barbour4e919972016-08-09 13:27:40 -06003575
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003576 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3577 "Invalid Pipeline CreateInfo: If independent blend feature not "
3578 "enabled, all elements of pAttachments must be identical");
Tony Barbour4e919972016-08-09 13:27:40 -06003579
Cody Northropc31a84f2016-08-22 10:41:47 -06003580 VkDescriptorSetObj descriptorSet(m_device);
3581 descriptorSet.AppendDummy();
3582 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Tony Barbour4e919972016-08-09 13:27:40 -06003583
Cody Northropc31a84f2016-08-22 10:41:47 -06003584 VkPipelineObj pipeline(m_device);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003585 // Create a renderPass with two color attachments
3586 VkAttachmentReference attachments[2] = {};
3587 attachments[0].layout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003588 attachments[1].attachment = 1;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003589 attachments[1].layout = VK_IMAGE_LAYOUT_GENERAL;
3590
3591 VkSubpassDescription subpass = {};
3592 subpass.pColorAttachments = attachments;
3593 subpass.colorAttachmentCount = 2;
3594
3595 VkRenderPassCreateInfo rpci = {};
3596 rpci.subpassCount = 1;
3597 rpci.pSubpasses = &subpass;
Tony Barbourffd60bd2017-03-09 12:04:55 -07003598 rpci.attachmentCount = 2;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003599
Tony Barbourffd60bd2017-03-09 12:04:55 -07003600 VkAttachmentDescription attach_desc[2] = {};
3601 attach_desc[0].format = VK_FORMAT_B8G8R8A8_UNORM;
3602 attach_desc[0].samples = VK_SAMPLE_COUNT_1_BIT;
3603 attach_desc[0].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3604 attach_desc[0].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
3605 attach_desc[1].format = VK_FORMAT_B8G8R8A8_UNORM;
3606 attach_desc[1].samples = VK_SAMPLE_COUNT_1_BIT;
3607 attach_desc[1].initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
3608 attach_desc[1].finalLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003609
Tony Barbourffd60bd2017-03-09 12:04:55 -07003610 rpci.pAttachments = attach_desc;
Tony Barbour0ace59a2017-02-06 13:38:36 -07003611 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3612
3613 VkRenderPass renderpass;
3614 vkCreateRenderPass(m_device->device(), &rpci, NULL, &renderpass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003615 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Cody Northropc31a84f2016-08-22 10:41:47 -06003616 pipeline.AddShader(&vs);
Cody Northrop5703cc72016-08-19 09:57:10 -06003617
Cody Northropc31a84f2016-08-22 10:41:47 -06003618 VkPipelineColorBlendAttachmentState att_state1 = {}, att_state2 = {};
3619 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3620 att_state1.blendEnable = VK_TRUE;
3621 att_state2.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3622 att_state2.blendEnable = VK_FALSE;
3623 pipeline.AddColorAttachment(0, &att_state1);
3624 pipeline.AddColorAttachment(1, &att_state2);
Tony Barbour0ace59a2017-02-06 13:38:36 -07003625 pipeline.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderpass);
Cody Northropc31a84f2016-08-22 10:41:47 -06003626 m_errorMonitor->VerifyFound();
Tony Barbour0ace59a2017-02-06 13:38:36 -07003627 vkDestroyRenderPass(m_device->device(), renderpass, NULL);
Tony Barbour4e919972016-08-09 13:27:40 -06003628}
3629
Mike Weiblen40b160e2017-02-06 19:21:52 -07003630// Is the Pipeline compatible with the expectations of the Renderpass/subpasses?
3631TEST_F(VkLayerTest, PipelineRenderpassCompatibility) {
3632 TEST_DESCRIPTION(
3633 "Create a graphics pipeline that is incompatible with the requirements "
3634 "of its contained Renderpass/subpasses.");
3635 ASSERT_NO_FATAL_FAILURE(InitState());
3636
3637 VkDescriptorSetObj ds_obj(m_device);
3638 ds_obj.AppendDummy();
3639 ds_obj.CreateVKDescriptorSet(m_commandBuffer);
3640
3641 VkShaderObj vs_obj(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
3642
3643 VkPipelineColorBlendAttachmentState att_state1 = {};
3644 att_state1.dstAlphaBlendFactor = VK_BLEND_FACTOR_CONSTANT_COLOR;
3645 att_state1.blendEnable = VK_TRUE;
3646
3647 VkRenderpassObj rp_obj(m_device);
3648
3649 {
3650 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02116);
3651 VkPipelineObj pipeline(m_device);
3652 pipeline.AddShader(&vs_obj);
3653 pipeline.AddColorAttachment(0, &att_state1);
3654
3655 VkGraphicsPipelineCreateInfo info = {};
3656 pipeline.InitGraphicsPipelineCreateInfo(&info);
3657 info.pColorBlendState = nullptr;
3658
3659 pipeline.CreateVKPipeline(ds_obj.GetPipelineLayout(), rp_obj.handle(), &info);
3660 m_errorMonitor->VerifyFound();
3661 }
3662}
3663
Chris Forbes26ec2122016-11-29 08:58:33 +13003664#if 0
Tony Barbour4e919972016-08-09 13:27:40 -06003665TEST_F(VkLayerTest, RenderPassDepthStencilAttachmentUnused) {
3666 TEST_DESCRIPTION("Specify no depth attachement in renderpass then specify "
3667 "depth attachments in subpass");
Cody Northropc31a84f2016-08-22 10:41:47 -06003668 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour4e919972016-08-09 13:27:40 -06003669
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3671 "vkCreateRenderPass has no depth/stencil attachment, yet subpass");
Tony Barbour4e919972016-08-09 13:27:40 -06003672
3673 // Create a renderPass with a single color attachment
3674 VkAttachmentReference attach = {};
3675 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
3676 VkSubpassDescription subpass = {};
3677 VkRenderPassCreateInfo rpci = {};
3678 rpci.subpassCount = 1;
3679 rpci.pSubpasses = &subpass;
3680 rpci.attachmentCount = 1;
3681 VkAttachmentDescription attach_desc = {};
3682 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3683 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3684 rpci.pAttachments = &attach_desc;
3685 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3686 VkRenderPass rp;
3687 subpass.pDepthStencilAttachment = &attach;
3688 subpass.pColorAttachments = NULL;
3689 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3690 m_errorMonitor->VerifyFound();
3691}
Chris Forbes26ec2122016-11-29 08:58:33 +13003692#endif
Tony Barbour4e919972016-08-09 13:27:40 -06003693
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003694TEST_F(VkLayerTest, UnusedPreserveAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003695 TEST_DESCRIPTION(
3696 "Create a framebuffer where a subpass has a preserve "
3697 "attachment reference of VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003698
3699 ASSERT_NO_FATAL_FAILURE(InitState());
3700 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3701
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "must not be VK_ATTACHMENT_UNUSED");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003703
3704 VkAttachmentReference color_attach = {};
3705 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3706 color_attach.attachment = 0;
3707 uint32_t preserve_attachment = VK_ATTACHMENT_UNUSED;
3708 VkSubpassDescription subpass = {};
3709 subpass.colorAttachmentCount = 1;
3710 subpass.pColorAttachments = &color_attach;
3711 subpass.preserveAttachmentCount = 1;
3712 subpass.pPreserveAttachments = &preserve_attachment;
3713
3714 VkRenderPassCreateInfo rpci = {};
3715 rpci.subpassCount = 1;
3716 rpci.pSubpasses = &subpass;
3717 rpci.attachmentCount = 1;
3718 VkAttachmentDescription attach_desc = {};
3719 attach_desc.format = VK_FORMAT_UNDEFINED;
3720 rpci.pAttachments = &attach_desc;
3721 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3722 VkRenderPass rp;
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003723 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003724
3725 m_errorMonitor->VerifyFound();
3726
Mark Lobodzinskia4feeeb2016-06-17 12:00:46 -06003727 if (result == VK_SUCCESS) {
3728 vkDestroyRenderPass(m_device->device(), rp, NULL);
3729 }
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003730}
3731
Chris Forbesc5389742016-06-29 11:49:23 +12003732TEST_F(VkLayerTest, CreateRenderPassResolveRequiresColorMsaa) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003733 TEST_DESCRIPTION(
3734 "Ensure that CreateRenderPass produces a validation error "
3735 "when the source of a subpass multisample resolve "
3736 "does not have multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003737
Chris Forbesc5389742016-06-29 11:49:23 +12003738 ASSERT_NO_FATAL_FAILURE(InitState());
3739
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003740 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3741 "Subpass 0 requests multisample resolve from attachment 0 which has "
3742 "VK_SAMPLE_COUNT_1_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003743
3744 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003745 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3746 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3747 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3748 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3749 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3750 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003751 };
3752
3753 VkAttachmentReference color = {
3754 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3755 };
3756
3757 VkAttachmentReference resolve = {
3758 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3759 };
3760
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003761 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003762
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003763 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003764
3765 VkRenderPass rp;
3766 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3767
3768 m_errorMonitor->VerifyFound();
3769
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003770 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003771}
3772
3773TEST_F(VkLayerTest, CreateRenderPassResolveRequiresSingleSampleDest) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003774 TEST_DESCRIPTION(
3775 "Ensure CreateRenderPass produces a validation error "
3776 "when a subpass multisample resolve operation is "
3777 "requested, and the destination of that resolve has "
3778 "multiple samples.");
Chris Forbes6655bb32016-07-01 18:27:30 +12003779
Chris Forbesc5389742016-06-29 11:49:23 +12003780 ASSERT_NO_FATAL_FAILURE(InitState());
3781
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3783 "Subpass 0 requests multisample resolve into attachment 1, which "
3784 "must have VK_SAMPLE_COUNT_1_BIT but has VK_SAMPLE_COUNT_4_BIT");
Chris Forbesc5389742016-06-29 11:49:23 +12003785
3786 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003787 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3788 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3789 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3790 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3791 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3792 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbesc5389742016-06-29 11:49:23 +12003793 };
3794
3795 VkAttachmentReference color = {
3796 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3797 };
3798
3799 VkAttachmentReference resolve = {
3800 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3801 };
3802
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003803 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &color, &resolve, nullptr, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003804
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003805 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesc5389742016-06-29 11:49:23 +12003806
3807 VkRenderPass rp;
3808 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3809
3810 m_errorMonitor->VerifyFound();
3811
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003812 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbesc5389742016-06-29 11:49:23 +12003813}
3814
Chris Forbes3f128ef2016-06-29 14:58:53 +12003815TEST_F(VkLayerTest, CreateRenderPassSubpassSampleCountConsistency) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003816 TEST_DESCRIPTION(
3817 "Ensure CreateRenderPass produces a validation error "
3818 "when the color and depth attachments used by a subpass "
3819 "have inconsistent sample counts");
Chris Forbes6655bb32016-07-01 18:27:30 +12003820
Chris Forbes3f128ef2016-06-29 14:58:53 +12003821 ASSERT_NO_FATAL_FAILURE(InitState());
3822
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3824 "Subpass 0 attempts to render to attachments with inconsistent sample counts");
Chris Forbes3f128ef2016-06-29 14:58:53 +12003825
3826 VkAttachmentDescription attachments[] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003827 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3828 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3829 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
3830 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_4_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
3831 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3832 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
Chris Forbes3f128ef2016-06-29 14:58:53 +12003833 };
3834
3835 VkAttachmentReference color[] = {
3836 {
3837 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3838 },
3839 {
3840 1, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
3841 },
3842 };
3843
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003844 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 2, color, nullptr, nullptr, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003845
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003846 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbes3f128ef2016-06-29 14:58:53 +12003847
3848 VkRenderPass rp;
3849 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
3850
3851 m_errorMonitor->VerifyFound();
3852
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003853 if (err == VK_SUCCESS) vkDestroyRenderPass(m_device->device(), rp, nullptr);
Chris Forbes3f128ef2016-06-29 14:58:53 +12003854}
3855
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003856TEST_F(VkLayerTest, FramebufferCreateErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003857 TEST_DESCRIPTION(
3858 "Hit errors when attempting to create a framebuffer :\n"
3859 " 1. Mismatch between framebuffer & renderPass attachmentCount\n"
3860 " 2. Use a color image as depthStencil attachment\n"
3861 " 3. Mismatch framebuffer & renderPass attachment formats\n"
3862 " 4. Mismatch framebuffer & renderPass attachment #samples\n"
3863 " 5. Framebuffer attachment w/ non-1 mip-levels\n"
3864 " 6. Framebuffer attachment where dimensions don't match\n"
3865 " 7. Framebuffer attachment w/o identity swizzle\n"
3866 " 8. framebuffer dimensions exceed physical device limits\n");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003867
3868 ASSERT_NO_FATAL_FAILURE(InitState());
3869 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
3870
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003871 m_errorMonitor->SetDesiredFailureMsg(
3872 VK_DEBUG_REPORT_ERROR_BIT_EXT,
3873 "vkCreateFramebuffer(): VkFramebufferCreateInfo attachmentCount of 2 does not match attachmentCount of 1 of ");
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003874
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003875 // Create a renderPass with a single color attachment
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003876 VkAttachmentReference attach = {};
3877 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
3878 VkSubpassDescription subpass = {};
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003879 subpass.pColorAttachments = &attach;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003880 VkRenderPassCreateInfo rpci = {};
3881 rpci.subpassCount = 1;
3882 rpci.pSubpasses = &subpass;
3883 rpci.attachmentCount = 1;
3884 VkAttachmentDescription attach_desc = {};
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003885 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003886 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003887 rpci.pAttachments = &attach_desc;
3888 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
3889 VkRenderPass rp;
3890 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3891 ASSERT_VK_SUCCESS(err);
3892
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003893 VkImageView ivs[2];
3894 ivs[0] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
3895 ivs[1] = m_renderTargets[0]->targetView(VK_FORMAT_B8G8R8A8_UNORM);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003896 VkFramebufferCreateInfo fb_info = {};
3897 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
3898 fb_info.pNext = NULL;
3899 fb_info.renderPass = rp;
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003900 // Set mis-matching attachmentCount
3901 fb_info.attachmentCount = 2;
3902 fb_info.pAttachments = ivs;
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003903 fb_info.width = 100;
3904 fb_info.height = 100;
3905 fb_info.layers = 1;
3906
3907 VkFramebuffer fb;
3908 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3909
3910 m_errorMonitor->VerifyFound();
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06003911 if (err == VK_SUCCESS) {
3912 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3913 }
3914 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003915
3916 // Create a renderPass with a depth-stencil attachment created with
3917 // IMAGE_USAGE_COLOR_ATTACHMENT
3918 // Add our color attachment to pDepthStencilAttachment
3919 subpass.pDepthStencilAttachment = &attach;
3920 subpass.pColorAttachments = NULL;
3921 VkRenderPass rp_ds;
3922 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp_ds);
3923 ASSERT_VK_SUCCESS(err);
3924 // Set correct attachment count, but attachment has COLOR usage bit set
3925 fb_info.attachmentCount = 1;
3926 fb_info.renderPass = rp_ds;
3927
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " conflicts with the image's IMAGE_USAGE flags ");
Tobin Ehlis2545e6f2016-06-22 10:42:19 -06003929 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3930
3931 m_errorMonitor->VerifyFound();
3932 if (err == VK_SUCCESS) {
3933 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3934 }
3935 vkDestroyRenderPass(m_device->device(), rp_ds, NULL);
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003936
3937 // Create new renderpass with alternate attachment format from fb
3938 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
3939 subpass.pDepthStencilAttachment = NULL;
3940 subpass.pColorAttachments = &attach;
3941 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3942 ASSERT_VK_SUCCESS(err);
3943
3944 // Cause error due to mis-matched formats between rp & fb
3945 // rp attachment 0 now has RGBA8 but corresponding fb attach is BGRA8
3946 fb_info.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003947 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
3948 " has format of VK_FORMAT_B8G8R8A8_UNORM that does not match ");
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003949 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3950
3951 m_errorMonitor->VerifyFound();
3952 if (err == VK_SUCCESS) {
3953 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3954 }
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003955 vkDestroyRenderPass(m_device->device(), rp, NULL);
3956
3957 // Create new renderpass with alternate sample count from fb
3958 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
3959 attach_desc.samples = VK_SAMPLE_COUNT_4_BIT;
3960 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3961 ASSERT_VK_SUCCESS(err);
3962
3963 // Cause error due to mis-matched sample count between rp & fb
3964 fb_info.renderPass = rp;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07003965 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayesba9aa222017-02-22 08:41:30 -07003966 " has VK_SAMPLE_COUNT_1_BIT samples that do not match the VK_SAMPLE_COUNT_4_BIT ");
Tobin Ehlis77d717c2016-06-22 14:19:19 -06003967 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
3968
3969 m_errorMonitor->VerifyFound();
3970 if (err == VK_SUCCESS) {
3971 vkDestroyFramebuffer(m_device->device(), fb, NULL);
3972 }
Tobin Ehlisd3bb23a2016-06-22 13:34:46 -06003973
3974 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis6cfda642016-06-22 16:12:58 -06003975
3976 // Create a custom imageView with non-1 mip levels
3977 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06003978 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 -06003979 ASSERT_TRUE(image.initialized());
3980
3981 VkImageView view;
3982 VkImageViewCreateInfo ivci = {};
3983 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
3984 ivci.image = image.handle();
3985 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
3986 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
3987 ivci.subresourceRange.layerCount = 1;
3988 ivci.subresourceRange.baseMipLevel = 0;
3989 // Set level count 2 (only 1 is allowed for FB attachment)
3990 ivci.subresourceRange.levelCount = 2;
3991 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
3992 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
3993 ASSERT_VK_SUCCESS(err);
3994 // Re-create renderpass to have matching sample count
3995 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
3996 err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
3997 ASSERT_VK_SUCCESS(err);
3998
3999 fb_info.renderPass = rp;
4000 fb_info.pAttachments = &view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004001 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has mip levelCount of 2 but only ");
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004002 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4003
4004 m_errorMonitor->VerifyFound();
4005 if (err == VK_SUCCESS) {
4006 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4007 }
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004008 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004009 // Update view to original color buffer and grow FB dimensions too big
4010 fb_info.pAttachments = ivs;
4011 fb_info.height = 1024;
4012 fb_info.width = 1024;
4013 fb_info.layers = 2;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004014 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " Attachment dimensions must be at least as large. ");
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004015 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4016
4017 m_errorMonitor->VerifyFound();
4018 if (err == VK_SUCCESS) {
4019 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4020 }
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004021 // Create view attachment with non-identity swizzle
4022 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
4023 ivci.image = image.handle();
4024 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
4025 ivci.format = VK_FORMAT_B8G8R8A8_UNORM;
4026 ivci.subresourceRange.layerCount = 1;
4027 ivci.subresourceRange.baseMipLevel = 0;
4028 ivci.subresourceRange.levelCount = 1;
4029 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
4030 ivci.components.r = VK_COMPONENT_SWIZZLE_G;
4031 ivci.components.g = VK_COMPONENT_SWIZZLE_R;
4032 ivci.components.b = VK_COMPONENT_SWIZZLE_A;
4033 ivci.components.a = VK_COMPONENT_SWIZZLE_B;
4034 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
4035 ASSERT_VK_SUCCESS(err);
4036
4037 fb_info.pAttachments = &view;
4038 fb_info.height = 100;
4039 fb_info.width = 100;
4040 fb_info.layers = 1;
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004041 m_errorMonitor->SetDesiredFailureMsg(
4042 VK_DEBUG_REPORT_ERROR_BIT_EXT,
4043 " has non-identy swizzle. All framebuffer attachments must have been created with the identity swizzle. ");
Tobin Ehlisb1f303b2016-06-23 08:19:55 -06004044 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4045
4046 m_errorMonitor->VerifyFound();
4047 if (err == VK_SUCCESS) {
4048 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4049 }
4050 vkDestroyImageView(m_device->device(), view, NULL);
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004051 // reset attachment to color attachment
4052 fb_info.pAttachments = ivs;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004053
4054 // Request fb that exceeds max width
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004055 fb_info.width = m_device->props.limits.maxFramebufferWidth + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004056 fb_info.height = 100;
4057 fb_info.layers = 1;
4058 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00413);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004059 m_errorMonitor->SetDesiredFailureMsg(
4060 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004061 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4062 "Here are the respective dimensions for attachment");
4063
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004064 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4065
4066 m_errorMonitor->VerifyFound();
4067 if (err == VK_SUCCESS) {
4068 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4069 }
4070
4071 // Request fb that exceeds max height
4072 fb_info.width = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004073 fb_info.height = m_device->props.limits.maxFramebufferHeight + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004074 fb_info.layers = 1;
4075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00414);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004076 m_errorMonitor->SetDesiredFailureMsg(
4077 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004078 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4079 "Here are the respective dimensions for attachment");
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004080 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4081
4082 m_errorMonitor->VerifyFound();
4083 if (err == VK_SUCCESS) {
4084 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4085 }
4086
4087 // Request fb that exceeds max layers
4088 fb_info.width = 100;
4089 fb_info.height = 100;
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004090 fb_info.layers = m_device->props.limits.maxFramebufferLayers + 1;
Mike Schuchardt8fb38062016-12-08 15:36:24 -07004091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00415);
Jeremy Hayesba9aa222017-02-22 08:41:30 -07004092 m_errorMonitor->SetDesiredFailureMsg(
4093 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07004094 "has dimensions smaller than the corresponding framebuffer dimensions. Attachment dimensions must be at least as large. "
4095 "Here are the respective dimensions for attachment");
Tobin Ehlis08d4b5e2016-06-23 08:52:39 -06004096 err = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
4097
4098 m_errorMonitor->VerifyFound();
4099 if (err == VK_SUCCESS) {
4100 vkDestroyFramebuffer(m_device->device(), fb, NULL);
4101 }
Tobin Ehlis27f2ae82016-06-23 07:36:57 -06004102
Tobin Ehlis6cfda642016-06-22 16:12:58 -06004103 vkDestroyRenderPass(m_device->device(), rp, NULL);
Mark Lobodzinski6d17b9f2016-06-16 13:21:38 -06004104}
4105
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004106TEST_F(VkLayerTest, DynamicDepthBiasNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004107 TEST_DESCRIPTION(
4108 "Run a simple draw calls to validate failure when Depth Bias dynamic "
4109 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004110
Cody Northropc31a84f2016-08-22 10:41:47 -06004111 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004112 // Dynamic depth bias
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004113 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic depth bias state not set for this command buffer");
4114 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBias);
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004115 m_errorMonitor->VerifyFound();
4116}
4117
4118TEST_F(VkLayerTest, DynamicLineWidthNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004119 TEST_DESCRIPTION(
4120 "Run a simple draw calls to validate failure when Line Width dynamic "
4121 "state is required but not correctly bound.");
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004122
Cody Northropc31a84f2016-08-22 10:41:47 -06004123 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004124 // Dynamic line width
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004125 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Dynamic line width state not set for this command buffer");
4126 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailLineWidth);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004127 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004128}
4129
4130TEST_F(VkLayerTest, DynamicViewportNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004131 TEST_DESCRIPTION(
4132 "Run a simple draw calls to validate failure when Viewport dynamic "
4133 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004134
Cody Northropc31a84f2016-08-22 10:41:47 -06004135 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004136 // Dynamic viewport state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4138 "Dynamic viewport(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004139 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailViewport);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004140 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004141}
4142
4143TEST_F(VkLayerTest, DynamicScissorNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004144 TEST_DESCRIPTION(
4145 "Run a simple draw calls to validate failure when Scissor dynamic "
4146 "state is required but not correctly bound.");
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004147
Cody Northropc31a84f2016-08-22 10:41:47 -06004148 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004149 // Dynamic scissor state
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07004150 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4151 "Dynamic scissor(s) 0 are used by pipeline state object, but were not provided");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004152 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailScissor);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004153 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004154}
4155
Cortd713fe82016-07-27 09:51:27 -07004156TEST_F(VkLayerTest, DynamicBlendConstantsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004157 TEST_DESCRIPTION(
4158 "Run a simple draw calls to validate failure when Blend Constants "
4159 "dynamic state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004160
4161 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004162 // Dynamic blend constant state
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004163 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4164 "Dynamic blend constants state not set for this command buffer");
4165 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailBlend);
Tobin Ehlis21c88352016-05-26 06:15:45 -06004166 m_errorMonitor->VerifyFound();
4167}
4168
4169TEST_F(VkLayerTest, DynamicDepthBoundsNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004170 TEST_DESCRIPTION(
4171 "Run a simple draw calls to validate failure when Depth Bounds dynamic "
4172 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004173
4174 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis21c88352016-05-26 06:15:45 -06004175 if (!m_device->phy().features().depthBounds) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07004176 printf(" Device does not support depthBounds test; skipped.\n");
Tobin Ehlis21c88352016-05-26 06:15:45 -06004177 return;
4178 }
4179 // Dynamic depth bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4181 "Dynamic depth bounds state not set for this command buffer");
4182 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailDepthBounds);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004183 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004184}
4185
4186TEST_F(VkLayerTest, DynamicStencilReadNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004187 TEST_DESCRIPTION(
4188 "Run a simple draw calls to validate failure when Stencil Read dynamic "
4189 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004190
4191 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004192 // Dynamic stencil read mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4194 "Dynamic stencil read mask state not set for this command buffer");
4195 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReadMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004196 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004197}
4198
4199TEST_F(VkLayerTest, DynamicStencilWriteNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004200 TEST_DESCRIPTION(
4201 "Run a simple draw calls to validate failure when Stencil Write dynamic"
4202 " state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004203
4204 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004205 // Dynamic stencil write mask
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004206 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4207 "Dynamic stencil write mask state not set for this command buffer");
4208 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilWriteMask);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004209 m_errorMonitor->VerifyFound();
Tobin Ehlisb1a87992016-05-25 16:42:47 -06004210}
4211
4212TEST_F(VkLayerTest, DynamicStencilRefNotBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004213 TEST_DESCRIPTION(
4214 "Run a simple draw calls to validate failure when Stencil Ref dynamic "
4215 "state is required but not correctly bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004216
4217 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisa5200ef2016-05-03 10:34:08 -06004218 // Dynamic stencil reference
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4220 "Dynamic stencil reference state not set for this command buffer");
4221 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailStencilReference);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004222 m_errorMonitor->VerifyFound();
Tobin Ehlis963a4042015-09-29 08:18:34 -06004223}
4224
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004225TEST_F(VkLayerTest, IndexBufferNotBound) {
4226 TEST_DESCRIPTION("Run an indexed draw call without an index buffer bound.");
Cody Northropc31a84f2016-08-22 10:41:47 -06004227
4228 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004229 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4230 "Index buffer object not bound to this command buffer when Indexed ");
4231 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailIndexBuffer);
Tobin Ehlis379ba3b2016-07-19 11:22:29 -06004232 m_errorMonitor->VerifyFound();
4233}
4234
Karl Schultz6addd812016-02-02 17:17:23 -07004235TEST_F(VkLayerTest, CommandBufferTwoSubmits) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004236 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
4237 "was begun w/ VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has "
4238 "been submitted");
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004239
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004240 ASSERT_NO_FATAL_FAILURE(InitState());
4241 ASSERT_NO_FATAL_FAILURE(InitViewport());
4242 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4243
Karl Schultz6addd812016-02-02 17:17:23 -07004244 // We luck out b/c by default the framework creates CB w/ the
4245 // VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set
Tony Barbour552f6c02016-12-21 14:34:07 -07004246 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004247 m_commandBuffer->ClearAllBuffers(m_clear_color, m_depth_clear_color, m_stencil_clear_color, NULL);
Tony Barbour552f6c02016-12-21 14:34:07 -07004248 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004249
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004250 // Bypass framework since it does the waits automatically
4251 VkResult err = VK_SUCCESS;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004252 VkSubmitInfo submit_info;
Chia-I Wuf9be13c2015-10-26 20:37:06 +08004253 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4254 submit_info.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004255 submit_info.waitSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004256 submit_info.pWaitSemaphores = NULL;
Jon Ashburn7f9716c2015-12-30 16:42:50 -07004257 submit_info.pWaitDstStageMask = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08004258 submit_info.commandBufferCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004259 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Chia-I Wud50a7d72015-10-26 20:48:51 +08004260 submit_info.signalSemaphoreCount = 0;
Courtney Goeltzenleuchter806c7002015-10-27 11:22:14 -06004261 submit_info.pSignalSemaphores = NULL;
4262
Chris Forbes40028e22016-06-13 09:59:34 +12004263 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Karl Schultz6addd812016-02-02 17:17:23 -07004264 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004265 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004266
Karl Schultz6addd812016-02-02 17:17:23 -07004267 // Cause validation error by re-submitting cmd buffer that should only be
4268 // submitted once
Chris Forbes40028e22016-06-13 09:59:34 +12004269 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski89cad1a2016-11-11 15:51:31 -07004270 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004271
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004272 m_errorMonitor->VerifyFound();
Tobin Ehlis59278bf2015-08-18 07:10:58 -06004273}
4274
Karl Schultz6addd812016-02-02 17:17:23 -07004275TEST_F(VkLayerTest, AllocDescriptorFromEmptyPool) {
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004276 TEST_DESCRIPTION("Attempt to allocate more sets and descriptors than descriptor pool has available.");
Karl Schultz6addd812016-02-02 17:17:23 -07004277 VkResult err;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004278
4279 ASSERT_NO_FATAL_FAILURE(InitState());
4280 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004281
Karl Schultz6addd812016-02-02 17:17:23 -07004282 // Create Pool w/ 1 Sampler descriptor, but try to alloc Uniform Buffer
4283 // descriptor from it
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004284 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004285 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004286 ds_type_count.descriptorCount = 2;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004287
4288 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004289 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4290 ds_pool_ci.pNext = NULL;
4291 ds_pool_ci.flags = 0;
4292 ds_pool_ci.maxSets = 1;
4293 ds_pool_ci.poolSizeCount = 1;
4294 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004295
4296 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004297 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004298 ASSERT_VK_SUCCESS(err);
4299
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004300 VkDescriptorSetLayoutBinding dsl_binding_samp = {};
4301 dsl_binding_samp.binding = 0;
4302 dsl_binding_samp.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4303 dsl_binding_samp.descriptorCount = 1;
4304 dsl_binding_samp.stageFlags = VK_SHADER_STAGE_ALL;
4305 dsl_binding_samp.pImmutableSamplers = NULL;
4306
4307 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4308 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4309 ds_layout_ci.pNext = NULL;
4310 ds_layout_ci.bindingCount = 1;
4311 ds_layout_ci.pBindings = &dsl_binding_samp;
4312
4313 VkDescriptorSetLayout ds_layout_samp;
4314 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_samp);
4315 ASSERT_VK_SUCCESS(err);
4316
4317 // Try to allocate 2 sets when pool only has 1 set
4318 VkDescriptorSet descriptor_sets[2];
4319 VkDescriptorSetLayout set_layouts[2] = {ds_layout_samp, ds_layout_samp};
4320 VkDescriptorSetAllocateInfo alloc_info = {};
4321 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4322 alloc_info.descriptorSetCount = 2;
4323 alloc_info.descriptorPool = ds_pool;
4324 alloc_info.pSetLayouts = set_layouts;
4325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00911);
4326 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
4327 m_errorMonitor->VerifyFound();
4328
4329 alloc_info.descriptorSetCount = 1;
4330 // Create layout w/ descriptor type not available in pool
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004331 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004332 dsl_binding.binding = 0;
4333 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4334 dsl_binding.descriptorCount = 1;
4335 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4336 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004337
Karl Schultz6addd812016-02-02 17:17:23 -07004338 ds_layout_ci.bindingCount = 1;
4339 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004340
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004341 VkDescriptorSetLayout ds_layout_ub;
4342 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_ub);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004343 ASSERT_VK_SUCCESS(err);
4344
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004345 VkDescriptorSet descriptor_set;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004346 alloc_info.descriptorSetCount = 1;
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004347 alloc_info.pSetLayouts = &ds_layout_ub;
4348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00912);
4349 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004350
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004351 m_errorMonitor->VerifyFound();
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004352
Karl Schultz2825ab92016-12-02 08:23:14 -07004353 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_samp, NULL);
Tobin Ehlis14cd5852016-11-23 12:52:48 -07004354 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_ub, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +08004355 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisf93f1e32015-10-20 16:16:04 -06004356}
4357
Karl Schultz6addd812016-02-02 17:17:23 -07004358TEST_F(VkLayerTest, FreeDescriptorFromOneShotPool) {
4359 VkResult err;
Tobin Ehlise735c692015-10-08 13:13:50 -06004360
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004361 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00922);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06004362
Tobin Ehlise735c692015-10-08 13:13:50 -06004363 ASSERT_NO_FATAL_FAILURE(InitState());
4364 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise735c692015-10-08 13:13:50 -06004365
Chia-I Wu1b99bb22015-10-27 19:25:11 +08004366 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004367 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4368 ds_type_count.descriptorCount = 1;
Tobin Ehlise735c692015-10-08 13:13:50 -06004369
4370 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004371 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4372 ds_pool_ci.pNext = NULL;
4373 ds_pool_ci.maxSets = 1;
4374 ds_pool_ci.poolSizeCount = 1;
4375 ds_pool_ci.flags = 0;
4376 // Not specifying VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT means
4377 // app can only call vkResetDescriptorPool on this pool.;
4378 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise735c692015-10-08 13:13:50 -06004379
4380 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004381 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise735c692015-10-08 13:13:50 -06004382 ASSERT_VK_SUCCESS(err);
4383
4384 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004385 dsl_binding.binding = 0;
4386 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4387 dsl_binding.descriptorCount = 1;
4388 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
4389 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlise735c692015-10-08 13:13:50 -06004390
4391 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07004392 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4393 ds_layout_ci.pNext = NULL;
4394 ds_layout_ci.bindingCount = 1;
4395 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise735c692015-10-08 13:13:50 -06004396
4397 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004398 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise735c692015-10-08 13:13:50 -06004399 ASSERT_VK_SUCCESS(err);
4400
4401 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08004402 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08004403 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07004404 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06004405 alloc_info.descriptorPool = ds_pool;
4406 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004407 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise735c692015-10-08 13:13:50 -06004408 ASSERT_VK_SUCCESS(err);
4409
4410 err = vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12004411 m_errorMonitor->VerifyFound();
Tobin Ehlise735c692015-10-08 13:13:50 -06004412
Chia-I Wuf7458c52015-10-26 21:10:41 +08004413 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4414 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise735c692015-10-08 13:13:50 -06004415}
4416
Karl Schultz6addd812016-02-02 17:17:23 -07004417TEST_F(VkLayerTest, InvalidDescriptorPool) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004418 // Attempt to clear Descriptor Pool with bad object.
4419 // ObjectTracker should catch this.
Cody Northropc31a84f2016-08-22 10:41:47 -06004420
4421 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004422 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00930);
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004423 uint64_t fake_pool_handle = 0xbaad6001;
4424 VkDescriptorPool bad_pool = reinterpret_cast<VkDescriptorPool &>(fake_pool_handle);
4425 vkResetDescriptorPool(device(), bad_pool, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -06004426 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004427}
4428
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004429TEST_F(VkLayerTest, InvalidDescriptorSet) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004430 // Attempt to bind an invalid Descriptor Set to a valid Command Buffer
4431 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004432 // Create a valid cmd buffer
Karl Schultzbdb75952016-04-19 11:36:49 -06004433 // call vkCmdBindDescriptorSets w/ false Descriptor Set
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004434
4435 uint64_t fake_set_handle = 0xbaad6001;
4436 VkDescriptorSet bad_set = reinterpret_cast<VkDescriptorSet &>(fake_set_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06004437 VkResult err;
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004438 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00982);
Karl Schultzbdb75952016-04-19 11:36:49 -06004439
4440 ASSERT_NO_FATAL_FAILURE(InitState());
4441
4442 VkDescriptorSetLayoutBinding layout_bindings[1] = {};
4443 layout_bindings[0].binding = 0;
4444 layout_bindings[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4445 layout_bindings[0].descriptorCount = 1;
4446 layout_bindings[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
4447 layout_bindings[0].pImmutableSamplers = NULL;
4448
4449 VkDescriptorSetLayout descriptor_set_layout;
4450 VkDescriptorSetLayoutCreateInfo dslci = {};
4451 dslci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4452 dslci.pNext = NULL;
4453 dslci.bindingCount = 1;
4454 dslci.pBindings = layout_bindings;
4455 err = vkCreateDescriptorSetLayout(device(), &dslci, NULL, &descriptor_set_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004456 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004457
4458 VkPipelineLayout pipeline_layout;
4459 VkPipelineLayoutCreateInfo plci = {};
4460 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4461 plci.pNext = NULL;
4462 plci.setLayoutCount = 1;
4463 plci.pSetLayouts = &descriptor_set_layout;
4464 err = vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
Karl Schultz5cb21112016-04-21 17:17:40 -06004465 ASSERT_VK_SUCCESS(err);
Karl Schultzbdb75952016-04-19 11:36:49 -06004466
Tony Barbour552f6c02016-12-21 14:34:07 -07004467 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004468 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &bad_set, 0,
4469 NULL);
Karl Schultzbdb75952016-04-19 11:36:49 -06004470 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07004471 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -06004472 vkDestroyPipelineLayout(device(), pipeline_layout, NULL);
4473 vkDestroyDescriptorSetLayout(device(), descriptor_set_layout, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004474}
4475
Karl Schultz6addd812016-02-02 17:17:23 -07004476TEST_F(VkLayerTest, InvalidDescriptorSetLayout) {
Karl Schultzbdb75952016-04-19 11:36:49 -06004477 // Attempt to create a Pipeline Layout with an invalid Descriptor Set Layout.
4478 // ObjectTracker should catch this.
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06004479 uint64_t fake_layout_handle = 0xbaad6001;
4480 VkDescriptorSetLayout bad_layout = reinterpret_cast<VkDescriptorSetLayout &>(fake_layout_handle);
Karl Schultzf78bcdd2016-11-30 12:36:01 -07004481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00875);
Cody Northropc31a84f2016-08-22 10:41:47 -06004482 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultzbdb75952016-04-19 11:36:49 -06004483 VkPipelineLayout pipeline_layout;
4484 VkPipelineLayoutCreateInfo plci = {};
4485 plci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4486 plci.pNext = NULL;
4487 plci.setLayoutCount = 1;
4488 plci.pSetLayouts = &bad_layout;
4489 vkCreatePipelineLayout(device(), &plci, NULL, &pipeline_layout);
4490
4491 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06004492}
4493
Mark Muellerd4914412016-06-13 17:52:06 -06004494TEST_F(VkLayerTest, WriteDescriptorSetIntegrityCheck) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004495 TEST_DESCRIPTION(
4496 "This test verifies some requirements of chapter 13.2.3 of the Vulkan Spec "
4497 "1) A uniform buffer update must have a valid buffer index."
4498 "2) When using an array of descriptors in a single WriteDescriptor,"
4499 " the descriptor types and stageflags must all be the same."
4500 "3) Immutable Sampler state must match across descriptors");
Mark Muellerd4914412016-06-13 17:52:06 -06004501
Mike Weiblena6666382017-01-05 15:16:11 -07004502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00941);
Mark Muellerd4914412016-06-13 17:52:06 -06004503
4504 ASSERT_NO_FATAL_FAILURE(InitState());
4505 VkDescriptorPoolSize ds_type_count[4] = {};
4506 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4507 ds_type_count[0].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004508 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004509 ds_type_count[1].descriptorCount = 1;
Tony Barboure132c5f2016-12-12 11:50:20 -07004510 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Muellerd4914412016-06-13 17:52:06 -06004511 ds_type_count[2].descriptorCount = 1;
4512 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
4513 ds_type_count[3].descriptorCount = 1;
4514
4515 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4516 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4517 ds_pool_ci.maxSets = 1;
4518 ds_pool_ci.poolSizeCount = sizeof(ds_type_count) / sizeof(VkDescriptorPoolSize);
4519 ds_pool_ci.pPoolSizes = ds_type_count;
4520
4521 VkDescriptorPool ds_pool;
4522 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4523 ASSERT_VK_SUCCESS(err);
4524
Mark Muellerb9896722016-06-16 09:54:29 -06004525 VkDescriptorSetLayoutBinding layout_binding[3] = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004526 layout_binding[0].binding = 0;
4527 layout_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4528 layout_binding[0].descriptorCount = 1;
4529 layout_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
4530 layout_binding[0].pImmutableSamplers = NULL;
4531
4532 layout_binding[1].binding = 1;
4533 layout_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4534 layout_binding[1].descriptorCount = 1;
4535 layout_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4536 layout_binding[1].pImmutableSamplers = NULL;
4537
4538 VkSamplerCreateInfo sampler_ci = {};
4539 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
4540 sampler_ci.pNext = NULL;
4541 sampler_ci.magFilter = VK_FILTER_NEAREST;
4542 sampler_ci.minFilter = VK_FILTER_NEAREST;
4543 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
4544 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4545 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4546 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
4547 sampler_ci.mipLodBias = 1.0;
4548 sampler_ci.anisotropyEnable = VK_FALSE;
4549 sampler_ci.maxAnisotropy = 1;
4550 sampler_ci.compareEnable = VK_FALSE;
4551 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
4552 sampler_ci.minLod = 1.0;
4553 sampler_ci.maxLod = 1.0;
4554 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
4555 sampler_ci.unnormalizedCoordinates = VK_FALSE;
4556 VkSampler sampler;
4557
4558 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
4559 ASSERT_VK_SUCCESS(err);
4560
4561 layout_binding[2].binding = 2;
4562 layout_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
4563 layout_binding[2].descriptorCount = 1;
4564 layout_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4565 layout_binding[2].pImmutableSamplers = static_cast<VkSampler *>(&sampler);
4566
Mark Muellerd4914412016-06-13 17:52:06 -06004567 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4568 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4569 ds_layout_ci.bindingCount = sizeof(layout_binding) / sizeof(VkDescriptorSetLayoutBinding);
4570 ds_layout_ci.pBindings = layout_binding;
4571 VkDescriptorSetLayout ds_layout;
4572 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4573 ASSERT_VK_SUCCESS(err);
4574
4575 VkDescriptorSetAllocateInfo alloc_info = {};
4576 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4577 alloc_info.descriptorSetCount = 1;
4578 alloc_info.descriptorPool = ds_pool;
4579 alloc_info.pSetLayouts = &ds_layout;
4580 VkDescriptorSet descriptorSet;
4581 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
4582 ASSERT_VK_SUCCESS(err);
4583
4584 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4585 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4586 pipeline_layout_ci.pNext = NULL;
4587 pipeline_layout_ci.setLayoutCount = 1;
4588 pipeline_layout_ci.pSetLayouts = &ds_layout;
4589
4590 VkPipelineLayout pipeline_layout;
4591 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4592 ASSERT_VK_SUCCESS(err);
4593
Mark Mueller5c838ce2016-06-16 09:54:29 -06004594 VkWriteDescriptorSet descriptor_write = {};
Mark Muellerd4914412016-06-13 17:52:06 -06004595 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4596 descriptor_write.dstSet = descriptorSet;
4597 descriptor_write.dstBinding = 0;
4598 descriptor_write.descriptorCount = 1;
4599 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
4600
Mark Mueller5c838ce2016-06-16 09:54:29 -06004601 // 1) The uniform buffer is intentionally invalid here
Mark Muellerd4914412016-06-13 17:52:06 -06004602 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4603 m_errorMonitor->VerifyFound();
4604
4605 // Create a buffer to update the descriptor with
4606 uint32_t qfi = 0;
4607 VkBufferCreateInfo buffCI = {};
4608 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4609 buffCI.size = 1024;
4610 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
4611 buffCI.queueFamilyIndexCount = 1;
4612 buffCI.pQueueFamilyIndices = &qfi;
4613
4614 VkBuffer dyub;
4615 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
4616 ASSERT_VK_SUCCESS(err);
Mark Muellerd4914412016-06-13 17:52:06 -06004617
Tony Barboure132c5f2016-12-12 11:50:20 -07004618 VkDeviceMemory mem;
4619 VkMemoryRequirements mem_reqs;
4620 vkGetBufferMemoryRequirements(m_device->device(), dyub, &mem_reqs);
4621
4622 VkMemoryAllocateInfo mem_alloc_info = {};
4623 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4624 mem_alloc_info.allocationSize = mem_reqs.size;
4625 m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
4626 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
4627 ASSERT_VK_SUCCESS(err);
4628
4629 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
4630 ASSERT_VK_SUCCESS(err);
4631
4632 VkDescriptorBufferInfo buffInfo[2] = {};
4633 buffInfo[0].buffer = dyub;
4634 buffInfo[0].offset = 0;
4635 buffInfo[0].range = 1024;
4636 buffInfo[1].buffer = dyub;
4637 buffInfo[1].offset = 0;
4638 buffInfo[1].range = 1024;
4639 descriptor_write.pBufferInfo = buffInfo;
Mark Muellerd4914412016-06-13 17:52:06 -06004640 descriptor_write.descriptorCount = 2;
4641
Mark Mueller5c838ce2016-06-16 09:54:29 -06004642 // 2) The stateFlags don't match between the first and second descriptor
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004643 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004644 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4645 m_errorMonitor->VerifyFound();
4646
Mark Mueller5c838ce2016-06-16 09:54:29 -06004647 // 3) The second descriptor has a null_ptr pImmutableSamplers and
4648 // the third descriptor contains an immutable sampler
Mark Muellerd4914412016-06-13 17:52:06 -06004649 descriptor_write.dstBinding = 1;
4650 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Mark Mueller5c838ce2016-06-16 09:54:29 -06004651
Mark Mueller5c838ce2016-06-16 09:54:29 -06004652 // Make pImageInfo index non-null to avoid complaints of it missing
4653 VkDescriptorImageInfo imageInfo = {};
4654 imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
4655 descriptor_write.pImageInfo = &imageInfo;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07004656 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Muellerd4914412016-06-13 17:52:06 -06004657 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4658 m_errorMonitor->VerifyFound();
4659
Mark Muellerd4914412016-06-13 17:52:06 -06004660 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tony Barboure132c5f2016-12-12 11:50:20 -07004661 vkFreeMemory(m_device->device(), mem, NULL);
Mark Muellerd4914412016-06-13 17:52:06 -06004662 vkDestroySampler(m_device->device(), sampler, NULL);
4663 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4664 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4665 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4666}
4667
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004668TEST_F(VkLayerTest, InvalidCmdBufferBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004669 TEST_DESCRIPTION(
4670 "Attempt to draw with a command buffer that is invalid "
4671 "due to a buffer dependency being destroyed.");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004672 ASSERT_NO_FATAL_FAILURE(InitState());
4673
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004674 VkBuffer buffer;
4675 VkDeviceMemory mem;
4676 VkMemoryRequirements mem_reqs;
4677
4678 VkBufferCreateInfo buf_info = {};
4679 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes3d5882f2016-09-16 17:37:17 +12004680 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004681 buf_info.size = 256;
4682 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
4683 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
4684 ASSERT_VK_SUCCESS(err);
4685
4686 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
4687
4688 VkMemoryAllocateInfo alloc_info = {};
4689 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4690 alloc_info.allocationSize = 256;
4691 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004692 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 -06004693 if (!pass) {
4694 vkDestroyBuffer(m_device->device(), buffer, NULL);
4695 return;
4696 }
4697 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
4698 ASSERT_VK_SUCCESS(err);
4699
4700 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
4701 ASSERT_VK_SUCCESS(err);
4702
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004703 m_commandBuffer->BeginCommandBuffer();
Chris Forbes3d5882f2016-09-16 17:37:17 +12004704 vkCmdFillBuffer(m_commandBuffer->GetBufferHandle(), buffer, 0, VK_WHOLE_SIZE, 0);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004705 m_commandBuffer->EndCommandBuffer();
4706
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004708 // Destroy buffer dependency prior to submit to cause ERROR
4709 vkDestroyBuffer(m_device->device(), buffer, NULL);
4710
4711 VkSubmitInfo submit_info = {};
4712 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4713 submit_info.commandBufferCount = 1;
4714 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4715 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4716
4717 m_errorMonitor->VerifyFound();
Rene Lindsayab6c5cd2016-12-20 14:05:37 -07004718 vkQueueWaitIdle(m_device->m_queue);
Tobin Ehlis0283c4d2016-06-28 17:57:07 -06004719 vkFreeMemory(m_device->handle(), mem, NULL);
4720}
4721
Tobin Ehlisea413442016-09-28 10:23:59 -06004722TEST_F(VkLayerTest, InvalidCmdBufferBufferViewDestroyed) {
4723 TEST_DESCRIPTION("Delete bufferView bound to cmd buffer, then attempt to submit cmd buffer.");
4724
4725 ASSERT_NO_FATAL_FAILURE(InitState());
4726 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4727
4728 VkDescriptorPoolSize ds_type_count;
4729 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4730 ds_type_count.descriptorCount = 1;
4731
4732 VkDescriptorPoolCreateInfo ds_pool_ci = {};
4733 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
4734 ds_pool_ci.maxSets = 1;
4735 ds_pool_ci.poolSizeCount = 1;
4736 ds_pool_ci.pPoolSizes = &ds_type_count;
4737
4738 VkDescriptorPool ds_pool;
4739 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
4740 ASSERT_VK_SUCCESS(err);
4741
4742 VkDescriptorSetLayoutBinding layout_binding;
4743 layout_binding.binding = 0;
4744 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4745 layout_binding.descriptorCount = 1;
4746 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
4747 layout_binding.pImmutableSamplers = NULL;
4748
4749 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
4750 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
4751 ds_layout_ci.bindingCount = 1;
4752 ds_layout_ci.pBindings = &layout_binding;
4753 VkDescriptorSetLayout ds_layout;
4754 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
4755 ASSERT_VK_SUCCESS(err);
4756
4757 VkDescriptorSetAllocateInfo alloc_info = {};
4758 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
4759 alloc_info.descriptorSetCount = 1;
4760 alloc_info.descriptorPool = ds_pool;
4761 alloc_info.pSetLayouts = &ds_layout;
4762 VkDescriptorSet descriptor_set;
4763 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
4764 ASSERT_VK_SUCCESS(err);
4765
4766 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
4767 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
4768 pipeline_layout_ci.pNext = NULL;
4769 pipeline_layout_ci.setLayoutCount = 1;
4770 pipeline_layout_ci.pSetLayouts = &ds_layout;
4771
4772 VkPipelineLayout pipeline_layout;
4773 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
4774 ASSERT_VK_SUCCESS(err);
4775
4776 VkBuffer buffer;
4777 uint32_t queue_family_index = 0;
4778 VkBufferCreateInfo buffer_create_info = {};
4779 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
4780 buffer_create_info.size = 1024;
4781 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
4782 buffer_create_info.queueFamilyIndexCount = 1;
4783 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
4784
4785 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
4786 ASSERT_VK_SUCCESS(err);
4787
4788 VkMemoryRequirements memory_reqs;
4789 VkDeviceMemory buffer_memory;
4790
4791 VkMemoryAllocateInfo memory_info = {};
4792 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4793 memory_info.allocationSize = 0;
4794 memory_info.memoryTypeIndex = 0;
4795
4796 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
4797 memory_info.allocationSize = memory_reqs.size;
4798 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
4799 ASSERT_TRUE(pass);
4800
4801 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
4802 ASSERT_VK_SUCCESS(err);
4803 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
4804 ASSERT_VK_SUCCESS(err);
4805
4806 VkBufferView view;
4807 VkBufferViewCreateInfo bvci = {};
4808 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
4809 bvci.buffer = buffer;
4810 bvci.format = VK_FORMAT_R8_UNORM;
4811 bvci.range = VK_WHOLE_SIZE;
4812
4813 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
4814 ASSERT_VK_SUCCESS(err);
4815
4816 VkWriteDescriptorSet descriptor_write = {};
4817 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
4818 descriptor_write.dstSet = descriptor_set;
4819 descriptor_write.dstBinding = 0;
4820 descriptor_write.descriptorCount = 1;
4821 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
4822 descriptor_write.pTexelBufferView = &view;
4823
4824 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
4825
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004826 char const *vsSource =
4827 "#version 450\n"
4828 "\n"
4829 "out gl_PerVertex { \n"
4830 " vec4 gl_Position;\n"
4831 "};\n"
4832 "void main(){\n"
4833 " gl_Position = vec4(1);\n"
4834 "}\n";
4835 char const *fsSource =
4836 "#version 450\n"
4837 "\n"
4838 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
4839 "layout(location=0) out vec4 x;\n"
4840 "void main(){\n"
4841 " x = imageLoad(s, 0);\n"
4842 "}\n";
Tobin Ehlisea413442016-09-28 10:23:59 -06004843 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
4844 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
4845 VkPipelineObj pipe(m_device);
4846 pipe.AddShader(&vs);
4847 pipe.AddShader(&fs);
4848 pipe.AddColorAttachment();
4849 pipe.CreateVKPipeline(pipeline_layout, renderPass());
4850
Tobin Ehlisea413442016-09-28 10:23:59 -06004851 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer view ");
4852
Tony Barbour552f6c02016-12-21 14:34:07 -07004853 m_commandBuffer->BeginCommandBuffer();
4854 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
4855
Tobin Ehlisea413442016-09-28 10:23:59 -06004856 VkViewport viewport = {0, 0, 16, 16, 0, 1};
4857 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
4858 VkRect2D scissor = {{0, 0}, {16, 16}};
4859 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
4860 // Bind pipeline to cmd buffer
4861 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
4862 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
4863 &descriptor_set, 0, nullptr);
4864 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07004865 m_commandBuffer->EndRenderPass();
4866 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisea413442016-09-28 10:23:59 -06004867
4868 // Delete BufferView in order to invalidate cmd buffer
4869 vkDestroyBufferView(m_device->device(), view, NULL);
4870 // Now attempt submit of cmd buffer
4871 VkSubmitInfo submit_info = {};
4872 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4873 submit_info.commandBufferCount = 1;
4874 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4875 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4876 m_errorMonitor->VerifyFound();
4877
4878 // Clean-up
4879 vkDestroyBuffer(m_device->device(), buffer, NULL);
4880 vkFreeMemory(m_device->device(), buffer_memory, NULL);
4881 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
4882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
4883 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
4884}
4885
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004886TEST_F(VkLayerTest, InvalidCmdBufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004887 TEST_DESCRIPTION(
4888 "Attempt to draw with a command buffer that is invalid "
4889 "due to an image dependency being destroyed.");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004890 ASSERT_NO_FATAL_FAILURE(InitState());
4891
4892 VkImage image;
4893 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
4894 VkImageCreateInfo image_create_info = {};
4895 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4896 image_create_info.pNext = NULL;
4897 image_create_info.imageType = VK_IMAGE_TYPE_2D;
4898 image_create_info.format = tex_format;
4899 image_create_info.extent.width = 32;
4900 image_create_info.extent.height = 32;
4901 image_create_info.extent.depth = 1;
4902 image_create_info.mipLevels = 1;
4903 image_create_info.arrayLayers = 1;
4904 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
4905 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004906 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004907 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004908 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004909 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004910 // Have to bind memory to image before recording cmd in cmd buffer using it
4911 VkMemoryRequirements mem_reqs;
4912 VkDeviceMemory image_mem;
4913 bool pass;
4914 VkMemoryAllocateInfo mem_alloc = {};
4915 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4916 mem_alloc.pNext = NULL;
4917 mem_alloc.memoryTypeIndex = 0;
4918 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
4919 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004920 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004921 ASSERT_TRUE(pass);
4922 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
4923 ASSERT_VK_SUCCESS(err);
4924 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
4925 ASSERT_VK_SUCCESS(err);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004926
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004927 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis764d7072016-07-01 12:54:29 -06004928 VkClearColorValue ccv;
4929 ccv.float32[0] = 1.0f;
4930 ccv.float32[1] = 1.0f;
4931 ccv.float32[2] = 1.0f;
4932 ccv.float32[3] = 1.0f;
4933 VkImageSubresourceRange isr = {};
4934 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004935 isr.baseArrayLayer = 0;
4936 isr.baseMipLevel = 0;
Tobin Ehlis764d7072016-07-01 12:54:29 -06004937 isr.layerCount = 1;
4938 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004939 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004940 m_commandBuffer->EndCommandBuffer();
4941
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004942 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004943 // Destroy image dependency prior to submit to cause ERROR
4944 vkDestroyImage(m_device->device(), image, NULL);
4945
4946 VkSubmitInfo submit_info = {};
4947 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
4948 submit_info.commandBufferCount = 1;
4949 submit_info.pCommandBuffers = &m_commandBuffer->handle();
4950 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
4951
4952 m_errorMonitor->VerifyFound();
Tobin Ehlis3d09fd52016-07-06 08:12:56 -06004953 vkFreeMemory(m_device->device(), image_mem, nullptr);
Tobin Ehlis11c8cea2016-06-28 17:44:21 -06004954}
4955
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004956TEST_F(VkLayerTest, InvalidCmdBufferFramebufferImageDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07004957 TEST_DESCRIPTION(
4958 "Attempt to draw with a command buffer that is invalid "
4959 "due to a framebuffer image dependency being destroyed.");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004960 VkFormatProperties format_properties;
4961 VkResult err = VK_SUCCESS;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004962 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
4963 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004964 return;
4965 }
4966
4967 ASSERT_NO_FATAL_FAILURE(InitState());
4968 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
4969
4970 VkImageCreateInfo image_ci = {};
4971 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
4972 image_ci.pNext = NULL;
4973 image_ci.imageType = VK_IMAGE_TYPE_2D;
4974 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
4975 image_ci.extent.width = 32;
4976 image_ci.extent.height = 32;
4977 image_ci.extent.depth = 1;
4978 image_ci.mipLevels = 1;
4979 image_ci.arrayLayers = 1;
4980 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
4981 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004982 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004983 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
4984 image_ci.flags = 0;
4985 VkImage image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004986 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004987
4988 VkMemoryRequirements memory_reqs;
4989 VkDeviceMemory image_memory;
4990 bool pass;
4991 VkMemoryAllocateInfo memory_info = {};
4992 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
4993 memory_info.pNext = NULL;
4994 memory_info.allocationSize = 0;
4995 memory_info.memoryTypeIndex = 0;
4996 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
4997 memory_info.allocationSize = memory_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06004998 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06004999 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005000 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005001 ASSERT_VK_SUCCESS(err);
5002 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5003 ASSERT_VK_SUCCESS(err);
5004
5005 VkImageViewCreateInfo ivci = {
5006 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5007 nullptr,
5008 0,
5009 image,
5010 VK_IMAGE_VIEW_TYPE_2D,
5011 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005012 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005013 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5014 };
5015 VkImageView view;
5016 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5017 ASSERT_VK_SUCCESS(err);
5018
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005019 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 32, 32, 1};
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005020 VkFramebuffer fb;
5021 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5022 ASSERT_VK_SUCCESS(err);
5023
5024 // Just use default renderpass with our framebuffer
5025 m_renderPassBeginInfo.framebuffer = fb;
Jeremy Hayesba817e12017-03-03 15:51:11 -07005026 m_renderPassBeginInfo.renderArea.extent.width = 32;
5027 m_renderPassBeginInfo.renderArea.extent.height = 32;
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005028 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005029 m_commandBuffer->BeginCommandBuffer();
5030 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5031 m_commandBuffer->EndRenderPass();
5032 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005033 // Destroy image attached to framebuffer to invalidate cmd buffer
5034 vkDestroyImage(m_device->device(), image, NULL);
5035 // Now attempt to submit cmd buffer and verify error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005036 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Tobin Ehlis59f68ab2016-09-06 21:59:07 -06005037 QueueCommandBuffer(false);
5038 m_errorMonitor->VerifyFound();
5039
5040 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5041 vkDestroyImageView(m_device->device(), view, nullptr);
5042 vkFreeMemory(m_device->device(), image_memory, nullptr);
5043}
5044
Tobin Ehlisb329f992016-10-12 13:20:29 -06005045TEST_F(VkLayerTest, FramebufferInUseDestroyedSignaled) {
5046 TEST_DESCRIPTION("Delete in-use framebuffer.");
5047 VkFormatProperties format_properties;
5048 VkResult err = VK_SUCCESS;
5049 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
5050
5051 ASSERT_NO_FATAL_FAILURE(InitState());
5052 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5053
5054 VkImageObj image(m_device);
5055 image.init(256, 256, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
5056 ASSERT_TRUE(image.initialized());
5057 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
5058
5059 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5060 VkFramebuffer fb;
5061 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5062 ASSERT_VK_SUCCESS(err);
5063
5064 // Just use default renderpass with our framebuffer
5065 m_renderPassBeginInfo.framebuffer = fb;
5066 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005067 m_commandBuffer->BeginCommandBuffer();
5068 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5069 m_commandBuffer->EndRenderPass();
5070 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisb329f992016-10-12 13:20:29 -06005071 // Submit cmd buffer to put it in-flight
5072 VkSubmitInfo submit_info = {};
5073 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5074 submit_info.commandBufferCount = 1;
5075 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5076 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5077 // Destroy framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005078 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00422);
Tobin Ehlisb329f992016-10-12 13:20:29 -06005079 vkDestroyFramebuffer(m_device->device(), fb, NULL);
5080 m_errorMonitor->VerifyFound();
5081 // Wait for queue to complete so we can safely destroy everything
5082 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005083 m_errorMonitor->SetUnexpectedError("If framebuffer is not VK_NULL_HANDLE, framebuffer must be a valid VkFramebuffer handle");
5084 m_errorMonitor->SetUnexpectedError("Unable to remove Framebuffer obj");
Tobin Ehlisb329f992016-10-12 13:20:29 -06005085 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5086}
5087
Tobin Ehlis88becd72016-09-21 14:33:41 -06005088TEST_F(VkLayerTest, FramebufferImageInUseDestroyedSignaled) {
5089 TEST_DESCRIPTION("Delete in-use image that's child of framebuffer.");
5090 VkFormatProperties format_properties;
5091 VkResult err = VK_SUCCESS;
5092 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_B8G8R8A8_UNORM, &format_properties);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005093
5094 ASSERT_NO_FATAL_FAILURE(InitState());
5095 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5096
5097 VkImageCreateInfo image_ci = {};
5098 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5099 image_ci.pNext = NULL;
5100 image_ci.imageType = VK_IMAGE_TYPE_2D;
5101 image_ci.format = VK_FORMAT_B8G8R8A8_UNORM;
5102 image_ci.extent.width = 256;
5103 image_ci.extent.height = 256;
5104 image_ci.extent.depth = 1;
5105 image_ci.mipLevels = 1;
5106 image_ci.arrayLayers = 1;
5107 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
5108 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlisc8ca0312016-09-22 07:30:05 -06005109 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis88becd72016-09-21 14:33:41 -06005110 image_ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
5111 image_ci.flags = 0;
5112 VkImage image;
5113 ASSERT_VK_SUCCESS(vkCreateImage(m_device->handle(), &image_ci, NULL, &image));
5114
5115 VkMemoryRequirements memory_reqs;
5116 VkDeviceMemory image_memory;
5117 bool pass;
5118 VkMemoryAllocateInfo memory_info = {};
5119 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5120 memory_info.pNext = NULL;
5121 memory_info.allocationSize = 0;
5122 memory_info.memoryTypeIndex = 0;
5123 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5124 memory_info.allocationSize = memory_reqs.size;
5125 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
5126 ASSERT_TRUE(pass);
5127 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
5128 ASSERT_VK_SUCCESS(err);
5129 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5130 ASSERT_VK_SUCCESS(err);
5131
5132 VkImageViewCreateInfo ivci = {
5133 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
5134 nullptr,
5135 0,
5136 image,
5137 VK_IMAGE_VIEW_TYPE_2D,
5138 VK_FORMAT_B8G8R8A8_UNORM,
5139 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
5140 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
5141 };
5142 VkImageView view;
5143 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
5144 ASSERT_VK_SUCCESS(err);
5145
5146 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, m_renderPass, 1, &view, 256, 256, 1};
5147 VkFramebuffer fb;
5148 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
5149 ASSERT_VK_SUCCESS(err);
5150
5151 // Just use default renderpass with our framebuffer
5152 m_renderPassBeginInfo.framebuffer = fb;
5153 // Create Null cmd buffer for submit
Tony Barbour552f6c02016-12-21 14:34:07 -07005154 m_commandBuffer->BeginCommandBuffer();
5155 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
5156 m_commandBuffer->EndRenderPass();
5157 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis88becd72016-09-21 14:33:41 -06005158 // Submit cmd buffer to put it (and attached imageView) in-flight
5159 VkSubmitInfo submit_info = {};
5160 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5161 submit_info.commandBufferCount = 1;
5162 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5163 // Submit cmd buffer to put framebuffer and children in-flight
5164 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5165 // Destroy image attached to framebuffer while in-flight
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07005166 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00743);
Tobin Ehlis88becd72016-09-21 14:33:41 -06005167 vkDestroyImage(m_device->device(), image, NULL);
5168 m_errorMonitor->VerifyFound();
5169 // Wait for queue to complete so we can safely destroy image and other objects
5170 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005171 m_errorMonitor->SetUnexpectedError("If image is not VK_NULL_HANDLE, image must be a valid VkImage handle");
5172 m_errorMonitor->SetUnexpectedError("Unable to remove Image obj");
Tobin Ehlis88becd72016-09-21 14:33:41 -06005173 vkDestroyImage(m_device->device(), image, NULL);
5174 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
5175 vkDestroyImageView(m_device->device(), view, nullptr);
5176 vkFreeMemory(m_device->device(), image_memory, nullptr);
5177}
5178
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005179TEST_F(VkLayerTest, RenderPassInUseDestroyedSignaled) {
5180 TEST_DESCRIPTION("Delete in-use renderPass.");
5181
5182 ASSERT_NO_FATAL_FAILURE(InitState());
5183 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5184
5185 // Create simple renderpass
5186 VkAttachmentReference attach = {};
5187 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
5188 VkSubpassDescription subpass = {};
5189 subpass.pColorAttachments = &attach;
5190 VkRenderPassCreateInfo rpci = {};
5191 rpci.subpassCount = 1;
5192 rpci.pSubpasses = &subpass;
5193 rpci.attachmentCount = 1;
5194 VkAttachmentDescription attach_desc = {};
5195 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
5196 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
5197 rpci.pAttachments = &attach_desc;
5198 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
5199 VkRenderPass rp;
5200 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
5201 ASSERT_VK_SUCCESS(err);
5202
5203 // Create a pipeline that uses the given renderpass
5204 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5205 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5206
5207 VkPipelineLayout pipeline_layout;
5208 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
5209 ASSERT_VK_SUCCESS(err);
5210
5211 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5212 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5213 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005214 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005215 vp_state_ci.pViewports = &vp;
5216 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005217 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005218 vp_state_ci.pScissors = &scissors;
5219
5220 VkPipelineShaderStageCreateInfo shaderStages[2];
5221 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5222
5223 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005224 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 -06005225 // but add it to be able to run on more devices
5226 shaderStages[0] = vs.GetStageCreateInfo();
5227 shaderStages[1] = fs.GetStageCreateInfo();
5228
5229 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5230 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5231
5232 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5233 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5234 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5235
5236 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5237 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
5238 rs_ci.rasterizerDiscardEnable = true;
5239 rs_ci.lineWidth = 1.0f;
5240
5241 VkPipelineColorBlendAttachmentState att = {};
5242 att.blendEnable = VK_FALSE;
5243 att.colorWriteMask = 0xf;
5244
5245 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5246 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5247 cb_ci.attachmentCount = 1;
5248 cb_ci.pAttachments = &att;
5249
5250 VkGraphicsPipelineCreateInfo gp_ci = {};
5251 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5252 gp_ci.stageCount = 2;
5253 gp_ci.pStages = shaderStages;
5254 gp_ci.pVertexInputState = &vi_ci;
5255 gp_ci.pInputAssemblyState = &ia_ci;
5256 gp_ci.pViewportState = &vp_state_ci;
5257 gp_ci.pRasterizationState = &rs_ci;
5258 gp_ci.pColorBlendState = &cb_ci;
5259 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5260 gp_ci.layout = pipeline_layout;
5261 gp_ci.renderPass = rp;
5262
5263 VkPipelineCacheCreateInfo pc_ci = {};
5264 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5265
5266 VkPipeline pipeline;
5267 VkPipelineCache pipe_cache;
5268 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipe_cache);
5269 ASSERT_VK_SUCCESS(err);
5270
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005271 m_errorMonitor->SetUnexpectedError(
5272 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
5273 "used to create subpass");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005274 err = vkCreateGraphicsPipelines(m_device->device(), pipe_cache, 1, &gp_ci, NULL, &pipeline);
5275 ASSERT_VK_SUCCESS(err);
5276 // Bind pipeline to cmd buffer, will also bind renderpass
5277 m_commandBuffer->BeginCommandBuffer();
5278 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
5279 m_commandBuffer->EndCommandBuffer();
5280
5281 VkSubmitInfo submit_info = {};
5282 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5283 submit_info.commandBufferCount = 1;
5284 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5285 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5286
5287 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00393);
5288 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5289 m_errorMonitor->VerifyFound();
5290
5291 // Wait for queue to complete so we can safely destroy everything
5292 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07005293 m_errorMonitor->SetUnexpectedError("If renderPass is not VK_NULL_HANDLE, renderPass must be a valid VkRenderPass handle");
5294 m_errorMonitor->SetUnexpectedError("Unable to remove Render Pass obj");
Tobin Ehlisaa739cd2016-10-27 07:53:36 -06005295 vkDestroyRenderPass(m_device->device(), rp, nullptr);
5296 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5297 vkDestroyPipelineCache(m_device->device(), pipe_cache, nullptr);
5298 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
5299}
5300
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005301TEST_F(VkLayerTest, ImageMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005302 TEST_DESCRIPTION("Attempt to draw with an image which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005303 ASSERT_NO_FATAL_FAILURE(InitState());
5304
5305 VkImage image;
5306 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5307 VkImageCreateInfo image_create_info = {};
5308 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5309 image_create_info.pNext = NULL;
5310 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5311 image_create_info.format = tex_format;
5312 image_create_info.extent.width = 32;
5313 image_create_info.extent.height = 32;
5314 image_create_info.extent.depth = 1;
5315 image_create_info.mipLevels = 1;
5316 image_create_info.arrayLayers = 1;
5317 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5318 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005319 image_create_info.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005320 image_create_info.flags = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005321 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005322 ASSERT_VK_SUCCESS(err);
5323 // Have to bind memory to image before recording cmd in cmd buffer using it
5324 VkMemoryRequirements mem_reqs;
5325 VkDeviceMemory image_mem;
5326 bool pass;
5327 VkMemoryAllocateInfo mem_alloc = {};
5328 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5329 mem_alloc.pNext = NULL;
5330 mem_alloc.memoryTypeIndex = 0;
5331 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
5332 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005333 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005334 ASSERT_TRUE(pass);
5335 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
5336 ASSERT_VK_SUCCESS(err);
5337
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005338 // Introduce error, do not call vkBindImageMemory(m_device->device(), image, image_mem, 0);
5339 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005340 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005341
5342 m_commandBuffer->BeginCommandBuffer();
5343 VkClearColorValue ccv;
5344 ccv.float32[0] = 1.0f;
5345 ccv.float32[1] = 1.0f;
5346 ccv.float32[2] = 1.0f;
5347 ccv.float32[3] = 1.0f;
5348 VkImageSubresourceRange isr = {};
5349 isr.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5350 isr.baseArrayLayer = 0;
5351 isr.baseMipLevel = 0;
5352 isr.layerCount = 1;
5353 isr.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005354 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), image, VK_IMAGE_LAYOUT_GENERAL, &ccv, 1, &isr);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005355 m_commandBuffer->EndCommandBuffer();
5356
5357 m_errorMonitor->VerifyFound();
5358 vkDestroyImage(m_device->device(), image, NULL);
5359 vkFreeMemory(m_device->device(), image_mem, nullptr);
5360}
5361
5362TEST_F(VkLayerTest, BufferMemoryNotBound) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005363 TEST_DESCRIPTION("Attempt to copy from a buffer which has not had memory bound to it.");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005364 ASSERT_NO_FATAL_FAILURE(InitState());
5365
5366 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005367 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 -06005368 VK_IMAGE_TILING_OPTIMAL, 0);
5369 ASSERT_TRUE(image.initialized());
5370
5371 VkBuffer buffer;
5372 VkDeviceMemory mem;
5373 VkMemoryRequirements mem_reqs;
5374
5375 VkBufferCreateInfo buf_info = {};
5376 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes8d260dd2016-09-16 17:42:42 +12005377 buf_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005378 buf_info.size = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005379 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
5380 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
5381 ASSERT_VK_SUCCESS(err);
5382
5383 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
5384
5385 VkMemoryAllocateInfo alloc_info = {};
5386 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
Mark Lobodzinski80871462017-02-16 10:37:27 -07005387 alloc_info.allocationSize = 1024;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005388 bool pass = false;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005389 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 -06005390 if (!pass) {
5391 vkDestroyBuffer(m_device->device(), buffer, NULL);
5392 return;
5393 }
5394 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
5395 ASSERT_VK_SUCCESS(err);
5396
Tobin Ehlisfed999f2016-09-21 15:09:45 -06005397 // Introduce failure by not calling vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5398 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06005399 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005400 VkBufferImageCopy region = {};
Mark Lobodzinski80871462017-02-16 10:37:27 -07005401 region.bufferRowLength = 16;
5402 region.bufferImageHeight = 16;
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005403 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
5404
5405 region.imageSubresource.layerCount = 1;
5406 region.imageExtent.height = 4;
5407 region.imageExtent.width = 4;
5408 region.imageExtent.depth = 1;
5409 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005410 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer, image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1,
5411 &region);
Mark Lobodzinskia4df3632016-07-14 09:57:41 -06005412 m_commandBuffer->EndCommandBuffer();
5413
5414 m_errorMonitor->VerifyFound();
5415
5416 vkDestroyBuffer(m_device->device(), buffer, NULL);
5417 vkFreeMemory(m_device->handle(), mem, NULL);
5418}
5419
Tobin Ehlis85940f52016-07-07 16:57:21 -06005420TEST_F(VkLayerTest, InvalidCmdBufferEventDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005421 TEST_DESCRIPTION(
5422 "Attempt to draw with a command buffer that is invalid "
5423 "due to an event dependency being destroyed.");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005424 ASSERT_NO_FATAL_FAILURE(InitState());
5425
5426 VkEvent event;
5427 VkEventCreateInfo evci = {};
5428 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
5429 VkResult result = vkCreateEvent(m_device->device(), &evci, NULL, &event);
5430 ASSERT_VK_SUCCESS(result);
5431
5432 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005433 vkCmdSetEvent(m_commandBuffer->GetBufferHandle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Tobin Ehlis85940f52016-07-07 16:57:21 -06005434 m_commandBuffer->EndCommandBuffer();
5435
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005436 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound event ");
Tobin Ehlis85940f52016-07-07 16:57:21 -06005437 // Destroy event dependency prior to submit to cause ERROR
5438 vkDestroyEvent(m_device->device(), event, NULL);
5439
5440 VkSubmitInfo submit_info = {};
5441 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5442 submit_info.commandBufferCount = 1;
5443 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5444 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5445
5446 m_errorMonitor->VerifyFound();
5447}
5448
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005449TEST_F(VkLayerTest, InvalidCmdBufferQueryPoolDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005450 TEST_DESCRIPTION(
5451 "Attempt to draw with a command buffer that is invalid "
5452 "due to a query pool dependency being destroyed.");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005453 ASSERT_NO_FATAL_FAILURE(InitState());
5454
5455 VkQueryPool query_pool;
5456 VkQueryPoolCreateInfo qpci{};
5457 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
5458 qpci.queryType = VK_QUERY_TYPE_TIMESTAMP;
5459 qpci.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005460 VkResult result = vkCreateQueryPool(m_device->device(), &qpci, nullptr, &query_pool);
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005461 ASSERT_VK_SUCCESS(result);
5462
5463 m_commandBuffer->BeginCommandBuffer();
5464 vkCmdResetQueryPool(m_commandBuffer->GetBufferHandle(), query_pool, 0, 1);
5465 m_commandBuffer->EndCommandBuffer();
5466
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005467 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound query pool ");
Tobin Ehlisdbea7552016-07-08 14:33:31 -06005468 // Destroy query pool dependency prior to submit to cause ERROR
5469 vkDestroyQueryPool(m_device->device(), query_pool, NULL);
5470
5471 VkSubmitInfo submit_info = {};
5472 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5473 submit_info.commandBufferCount = 1;
5474 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5475 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5476
5477 m_errorMonitor->VerifyFound();
5478}
5479
Tobin Ehlis24130d92016-07-08 15:50:53 -06005480TEST_F(VkLayerTest, InvalidCmdBufferPipelineDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005481 TEST_DESCRIPTION(
5482 "Attempt to draw with a command buffer that is invalid "
5483 "due to a pipeline dependency being destroyed.");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005484 ASSERT_NO_FATAL_FAILURE(InitState());
5485 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5486
5487 VkResult err;
5488
5489 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5490 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5491
5492 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005493 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005494 ASSERT_VK_SUCCESS(err);
5495
5496 VkPipelineViewportStateCreateInfo vp_state_ci = {};
5497 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
5498 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005499 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -06005500 vp_state_ci.pViewports = &vp;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005501 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005502 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis24130d92016-07-08 15:50:53 -06005503 vp_state_ci.pScissors = &scissors;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005504
5505 VkPipelineShaderStageCreateInfo shaderStages[2];
5506 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
5507
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005508 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005509 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 -06005510 // but add it to be able to run on more devices
Tobin Ehlis24130d92016-07-08 15:50:53 -06005511 shaderStages[0] = vs.GetStageCreateInfo();
5512 shaderStages[1] = fs.GetStageCreateInfo();
5513
5514 VkPipelineVertexInputStateCreateInfo vi_ci = {};
5515 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
5516
5517 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
5518 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
5519 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
5520
5521 VkPipelineRasterizationStateCreateInfo rs_ci = {};
5522 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbese06ba252016-09-16 17:48:53 +12005523 rs_ci.rasterizerDiscardEnable = true;
5524 rs_ci.lineWidth = 1.0f;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005525
5526 VkPipelineColorBlendAttachmentState att = {};
5527 att.blendEnable = VK_FALSE;
5528 att.colorWriteMask = 0xf;
5529
5530 VkPipelineColorBlendStateCreateInfo cb_ci = {};
5531 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
5532 cb_ci.attachmentCount = 1;
5533 cb_ci.pAttachments = &att;
5534
5535 VkGraphicsPipelineCreateInfo gp_ci = {};
5536 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
5537 gp_ci.stageCount = 2;
5538 gp_ci.pStages = shaderStages;
5539 gp_ci.pVertexInputState = &vi_ci;
5540 gp_ci.pInputAssemblyState = &ia_ci;
5541 gp_ci.pViewportState = &vp_state_ci;
5542 gp_ci.pRasterizationState = &rs_ci;
5543 gp_ci.pColorBlendState = &cb_ci;
Tobin Ehlis24130d92016-07-08 15:50:53 -06005544 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
5545 gp_ci.layout = pipeline_layout;
5546 gp_ci.renderPass = renderPass();
5547
5548 VkPipelineCacheCreateInfo pc_ci = {};
5549 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
5550
5551 VkPipeline pipeline;
5552 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005553 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005554 ASSERT_VK_SUCCESS(err);
5555
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005556 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005557 ASSERT_VK_SUCCESS(err);
5558
5559 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005560 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Tobin Ehlis24130d92016-07-08 15:50:53 -06005561 m_commandBuffer->EndCommandBuffer();
5562 // Now destroy pipeline in order to cause error when submitting
5563 vkDestroyPipeline(m_device->device(), pipeline, nullptr);
5564
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound pipeline ");
Tobin Ehlis24130d92016-07-08 15:50:53 -06005566
5567 VkSubmitInfo submit_info = {};
5568 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5569 submit_info.commandBufferCount = 1;
5570 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5571 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5572
5573 m_errorMonitor->VerifyFound();
5574 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
5575 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5576}
5577
Tobin Ehlis31289162016-08-17 14:57:58 -06005578TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetBufferDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005579 TEST_DESCRIPTION(
5580 "Attempt to draw with a command buffer that is invalid "
5581 "due to a bound descriptor set with a buffer dependency "
5582 "being destroyed.");
Tobin Ehlis31289162016-08-17 14:57:58 -06005583 ASSERT_NO_FATAL_FAILURE(InitState());
5584 ASSERT_NO_FATAL_FAILURE(InitViewport());
5585 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5586
5587 VkDescriptorPoolSize ds_type_count = {};
5588 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5589 ds_type_count.descriptorCount = 1;
5590
5591 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5592 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5593 ds_pool_ci.pNext = NULL;
5594 ds_pool_ci.maxSets = 1;
5595 ds_pool_ci.poolSizeCount = 1;
5596 ds_pool_ci.pPoolSizes = &ds_type_count;
5597
5598 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005599 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis31289162016-08-17 14:57:58 -06005600 ASSERT_VK_SUCCESS(err);
5601
5602 VkDescriptorSetLayoutBinding dsl_binding = {};
5603 dsl_binding.binding = 0;
5604 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5605 dsl_binding.descriptorCount = 1;
5606 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5607 dsl_binding.pImmutableSamplers = NULL;
5608
5609 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5610 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5611 ds_layout_ci.pNext = NULL;
5612 ds_layout_ci.bindingCount = 1;
5613 ds_layout_ci.pBindings = &dsl_binding;
5614 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005615 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005616 ASSERT_VK_SUCCESS(err);
5617
5618 VkDescriptorSet descriptorSet;
5619 VkDescriptorSetAllocateInfo alloc_info = {};
5620 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5621 alloc_info.descriptorSetCount = 1;
5622 alloc_info.descriptorPool = ds_pool;
5623 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005624 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis31289162016-08-17 14:57:58 -06005625 ASSERT_VK_SUCCESS(err);
5626
5627 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5628 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5629 pipeline_layout_ci.pNext = NULL;
5630 pipeline_layout_ci.setLayoutCount = 1;
5631 pipeline_layout_ci.pSetLayouts = &ds_layout;
5632
5633 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005634 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis31289162016-08-17 14:57:58 -06005635 ASSERT_VK_SUCCESS(err);
5636
5637 // Create a buffer to update the descriptor with
5638 uint32_t qfi = 0;
5639 VkBufferCreateInfo buffCI = {};
5640 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
5641 buffCI.size = 1024;
5642 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
5643 buffCI.queueFamilyIndexCount = 1;
5644 buffCI.pQueueFamilyIndices = &qfi;
5645
5646 VkBuffer buffer;
5647 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &buffer);
5648 ASSERT_VK_SUCCESS(err);
5649 // Allocate memory and bind to buffer so we can make it to the appropriate
5650 // error
5651 VkMemoryAllocateInfo mem_alloc = {};
5652 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5653 mem_alloc.pNext = NULL;
5654 mem_alloc.allocationSize = 1024;
5655 mem_alloc.memoryTypeIndex = 0;
5656
5657 VkMemoryRequirements memReqs;
5658 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005659 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis31289162016-08-17 14:57:58 -06005660 if (!pass) {
5661 vkDestroyBuffer(m_device->device(), buffer, NULL);
5662 return;
5663 }
5664
5665 VkDeviceMemory mem;
5666 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
5667 ASSERT_VK_SUCCESS(err);
5668 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
5669 ASSERT_VK_SUCCESS(err);
5670 // Correctly update descriptor to avoid "NOT_UPDATED" error
5671 VkDescriptorBufferInfo buffInfo = {};
5672 buffInfo.buffer = buffer;
5673 buffInfo.offset = 0;
5674 buffInfo.range = 1024;
5675
5676 VkWriteDescriptorSet descriptor_write;
5677 memset(&descriptor_write, 0, sizeof(descriptor_write));
5678 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5679 descriptor_write.dstSet = descriptorSet;
5680 descriptor_write.dstBinding = 0;
5681 descriptor_write.descriptorCount = 1;
5682 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
5683 descriptor_write.pBufferInfo = &buffInfo;
5684
5685 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5686
5687 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005688 char const *vsSource =
5689 "#version 450\n"
5690 "\n"
5691 "out gl_PerVertex { \n"
5692 " vec4 gl_Position;\n"
5693 "};\n"
5694 "void main(){\n"
5695 " gl_Position = vec4(1);\n"
5696 "}\n";
5697 char const *fsSource =
5698 "#version 450\n"
5699 "\n"
5700 "layout(location=0) out vec4 x;\n"
5701 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
5702 "void main(){\n"
5703 " x = vec4(bar.y);\n"
5704 "}\n";
Tobin Ehlis31289162016-08-17 14:57:58 -06005705 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5706 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5707 VkPipelineObj pipe(m_device);
5708 pipe.AddShader(&vs);
5709 pipe.AddShader(&fs);
5710 pipe.AddColorAttachment();
5711 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5712
Tony Barbour552f6c02016-12-21 14:34:07 -07005713 m_commandBuffer->BeginCommandBuffer();
5714 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005715 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5716 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5717 &descriptorSet, 0, NULL);
Rene Lindsay0583ac92017-01-16 14:29:10 -07005718
5719 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &m_viewports[0]);
5720 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &m_scissors[0]);
5721
Tobin Ehlis31289162016-08-17 14:57:58 -06005722 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005723 m_commandBuffer->EndRenderPass();
5724 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005725 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound buffer ");
Tobin Ehlis31289162016-08-17 14:57:58 -06005726 // Destroy buffer should invalidate the cmd buffer, causing error on submit
5727 vkDestroyBuffer(m_device->device(), buffer, NULL);
5728 // Attempt to submit cmd buffer
5729 VkSubmitInfo submit_info = {};
5730 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5731 submit_info.commandBufferCount = 1;
5732 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5733 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5734 m_errorMonitor->VerifyFound();
5735 // Cleanup
5736 vkFreeMemory(m_device->device(), mem, NULL);
5737
5738 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
5739 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
5740 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
5741}
5742
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005743TEST_F(VkLayerTest, InvalidCmdBufferDescriptorSetImageSamplerDestroyed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005744 TEST_DESCRIPTION(
5745 "Attempt to draw with a command buffer that is invalid "
5746 "due to a bound descriptor sets with a combined image "
5747 "sampler having their image, sampler, and descriptor set "
5748 "each respectively destroyed and then attempting to "
5749 "submit associated cmd buffers. Attempt to destroy a "
5750 "DescriptorSet that is in use.");
Rene Lindsayed88b732017-01-27 15:55:29 -07005751 ASSERT_NO_FATAL_FAILURE(InitState(nullptr, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT));
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005752 ASSERT_NO_FATAL_FAILURE(InitViewport());
5753 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
5754
5755 VkDescriptorPoolSize ds_type_count = {};
5756 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5757 ds_type_count.descriptorCount = 1;
5758
5759 VkDescriptorPoolCreateInfo ds_pool_ci = {};
5760 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
5761 ds_pool_ci.pNext = NULL;
Rene Lindsayed88b732017-01-27 15:55:29 -07005762 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005763 ds_pool_ci.maxSets = 1;
5764 ds_pool_ci.poolSizeCount = 1;
5765 ds_pool_ci.pPoolSizes = &ds_type_count;
5766
5767 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005768 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005769 ASSERT_VK_SUCCESS(err);
5770
5771 VkDescriptorSetLayoutBinding dsl_binding = {};
5772 dsl_binding.binding = 0;
5773 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5774 dsl_binding.descriptorCount = 1;
5775 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
5776 dsl_binding.pImmutableSamplers = NULL;
5777
5778 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
5779 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
5780 ds_layout_ci.pNext = NULL;
5781 ds_layout_ci.bindingCount = 1;
5782 ds_layout_ci.pBindings = &dsl_binding;
5783 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005784 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005785 ASSERT_VK_SUCCESS(err);
5786
5787 VkDescriptorSet descriptorSet;
5788 VkDescriptorSetAllocateInfo alloc_info = {};
5789 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
5790 alloc_info.descriptorSetCount = 1;
5791 alloc_info.descriptorPool = ds_pool;
5792 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005793 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005794 ASSERT_VK_SUCCESS(err);
5795
5796 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
5797 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
5798 pipeline_layout_ci.pNext = NULL;
5799 pipeline_layout_ci.setLayoutCount = 1;
5800 pipeline_layout_ci.pSetLayouts = &ds_layout;
5801
5802 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005803 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005804 ASSERT_VK_SUCCESS(err);
5805
5806 // Create images to update the descriptor with
5807 VkImage image;
5808 VkImage image2;
5809 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
5810 const int32_t tex_width = 32;
5811 const int32_t tex_height = 32;
5812 VkImageCreateInfo image_create_info = {};
5813 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
5814 image_create_info.pNext = NULL;
5815 image_create_info.imageType = VK_IMAGE_TYPE_2D;
5816 image_create_info.format = tex_format;
5817 image_create_info.extent.width = tex_width;
5818 image_create_info.extent.height = tex_height;
5819 image_create_info.extent.depth = 1;
5820 image_create_info.mipLevels = 1;
5821 image_create_info.arrayLayers = 1;
5822 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
5823 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
5824 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
5825 image_create_info.flags = 0;
5826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
5827 ASSERT_VK_SUCCESS(err);
5828 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image2);
5829 ASSERT_VK_SUCCESS(err);
5830
5831 VkMemoryRequirements memory_reqs;
5832 VkDeviceMemory image_memory;
5833 bool pass;
5834 VkMemoryAllocateInfo memory_info = {};
5835 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
5836 memory_info.pNext = NULL;
5837 memory_info.allocationSize = 0;
5838 memory_info.memoryTypeIndex = 0;
5839 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
5840 // Allocate enough memory for both images
5841 memory_info.allocationSize = memory_reqs.size * 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005842 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005843 ASSERT_TRUE(pass);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005844 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005845 ASSERT_VK_SUCCESS(err);
5846 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
5847 ASSERT_VK_SUCCESS(err);
5848 // Bind second image to memory right after first image
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005849 err = vkBindImageMemory(m_device->device(), image2, image_memory, memory_reqs.size);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005850 ASSERT_VK_SUCCESS(err);
5851
5852 VkImageViewCreateInfo image_view_create_info = {};
5853 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
5854 image_view_create_info.image = image;
5855 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
5856 image_view_create_info.format = tex_format;
5857 image_view_create_info.subresourceRange.layerCount = 1;
5858 image_view_create_info.subresourceRange.baseMipLevel = 0;
5859 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005860 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005861
5862 VkImageView view;
5863 VkImageView view2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005864 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005865 ASSERT_VK_SUCCESS(err);
5866 image_view_create_info.image = image2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005867 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view2);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005868 ASSERT_VK_SUCCESS(err);
5869 // Create Samplers
5870 VkSamplerCreateInfo sampler_ci = {};
5871 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
5872 sampler_ci.pNext = NULL;
5873 sampler_ci.magFilter = VK_FILTER_NEAREST;
5874 sampler_ci.minFilter = VK_FILTER_NEAREST;
5875 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
5876 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5877 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5878 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
5879 sampler_ci.mipLodBias = 1.0;
5880 sampler_ci.anisotropyEnable = VK_FALSE;
5881 sampler_ci.maxAnisotropy = 1;
5882 sampler_ci.compareEnable = VK_FALSE;
5883 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
5884 sampler_ci.minLod = 1.0;
5885 sampler_ci.maxLod = 1.0;
5886 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
5887 sampler_ci.unnormalizedCoordinates = VK_FALSE;
5888 VkSampler sampler;
5889 VkSampler sampler2;
5890 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
5891 ASSERT_VK_SUCCESS(err);
5892 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler2);
5893 ASSERT_VK_SUCCESS(err);
5894 // Update descriptor with image and sampler
5895 VkDescriptorImageInfo img_info = {};
5896 img_info.sampler = sampler;
5897 img_info.imageView = view;
5898 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
5899
5900 VkWriteDescriptorSet descriptor_write;
5901 memset(&descriptor_write, 0, sizeof(descriptor_write));
5902 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
5903 descriptor_write.dstSet = descriptorSet;
5904 descriptor_write.dstBinding = 0;
5905 descriptor_write.descriptorCount = 1;
5906 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
5907 descriptor_write.pImageInfo = &img_info;
5908
5909 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
5910
5911 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07005912 char const *vsSource =
5913 "#version 450\n"
5914 "\n"
5915 "out gl_PerVertex { \n"
5916 " vec4 gl_Position;\n"
5917 "};\n"
5918 "void main(){\n"
5919 " gl_Position = vec4(1);\n"
5920 "}\n";
5921 char const *fsSource =
5922 "#version 450\n"
5923 "\n"
5924 "layout(set=0, binding=0) uniform sampler2D s;\n"
5925 "layout(location=0) out vec4 x;\n"
5926 "void main(){\n"
5927 " x = texture(s, vec2(1));\n"
5928 "}\n";
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005929 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
5930 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
5931 VkPipelineObj pipe(m_device);
5932 pipe.AddShader(&vs);
5933 pipe.AddShader(&fs);
5934 pipe.AddColorAttachment();
5935 pipe.CreateVKPipeline(pipeline_layout, renderPass());
5936
5937 // First error case is destroying sampler prior to cmd buffer submission
Jeremy Hayesb91c79d2017-02-27 15:09:03 -07005938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound sampler");
Tony Barbour552f6c02016-12-21 14:34:07 -07005939 m_commandBuffer->BeginCommandBuffer();
5940 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005941 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5942 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5943 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005944 VkViewport viewport = {0, 0, 16, 16, 0, 1};
5945 VkRect2D scissor = {{0, 0}, {16, 16}};
5946 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5947 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005948 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005949 m_commandBuffer->EndRenderPass();
5950 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005951 // Destroy sampler invalidates the cmd buffer, causing error on submit
5952 vkDestroySampler(m_device->device(), sampler, NULL);
5953 // Attempt to submit cmd buffer
5954 VkSubmitInfo submit_info = {};
5955 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5956 submit_info.commandBufferCount = 1;
5957 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5958 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5959 m_errorMonitor->VerifyFound();
Rene Lindsaya31285f2017-01-11 16:35:53 -07005960
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005961 // Now re-update descriptor with valid sampler and delete image
5962 img_info.sampler = sampler2;
5963 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005964
5965 VkCommandBufferBeginInfo info = {};
5966 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
5967 info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
5968
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005969 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound image ");
Rene Lindsayed88b732017-01-27 15:55:29 -07005970 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005971 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005972 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5973 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5974 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005975 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5976 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005977 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07005978 m_commandBuffer->EndRenderPass();
5979 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005980 // Destroy image invalidates the cmd buffer, causing error on submit
5981 vkDestroyImage(m_device->device(), image, NULL);
5982 // Attempt to submit cmd buffer
5983 submit_info = {};
5984 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
5985 submit_info.commandBufferCount = 1;
5986 submit_info.pCommandBuffers = &m_commandBuffer->handle();
5987 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
5988 m_errorMonitor->VerifyFound();
5989 // Now update descriptor to be valid, but then free descriptor
5990 img_info.imageView = view2;
5991 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Rene Lindsayed88b732017-01-27 15:55:29 -07005992 m_commandBuffer->BeginCommandBuffer(&info);
Tony Barbour552f6c02016-12-21 14:34:07 -07005993 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06005994 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
5995 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
5996 &descriptorSet, 0, NULL);
Rene Lindsaya31285f2017-01-11 16:35:53 -07005997 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
5998 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06005999 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006000 m_commandBuffer->EndRenderPass();
6001 m_commandBuffer->EndCommandBuffer();
Tony Barbourc373c012017-01-26 10:53:28 -07006002 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -07006003
6004 // Immediately try to destroy the descriptor set in the active command buffer - failure expected
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006005 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call vkFreeDescriptorSets() on descriptor set 0x");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006006 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
Mark Mueller917f6bc2016-08-30 10:57:19 -06006007 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006008
6009 // Try again once the queue is idle - should succeed w/o error
Dave Houltond5507dd2017-01-24 15:29:02 -07006010 // 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 -07006011 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006012 m_errorMonitor->SetUnexpectedError(
6013 "pDescriptorSets must be a pointer to an array of descriptorSetCount VkDescriptorSet handles, each element of which must "
6014 "either be a valid handle or VK_NULL_HANDLE");
6015 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Set obj");
Dave Houltonfbf52152017-01-06 12:55:29 -07006016 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptorSet);
6017
6018 // Attempt to submit cmd buffer containing the freed descriptor set
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006019 submit_info = {};
6020 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6021 submit_info.commandBufferCount = 1;
6022 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07006023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " that is invalid because bound descriptor set ");
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006024 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6025 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07006026
Tobin Ehlis1d7f5c92016-08-17 17:00:07 -06006027 // Cleanup
6028 vkFreeMemory(m_device->device(), image_memory, NULL);
6029 vkDestroySampler(m_device->device(), sampler2, NULL);
6030 vkDestroyImage(m_device->device(), image2, NULL);
6031 vkDestroyImageView(m_device->device(), view, NULL);
6032 vkDestroyImageView(m_device->device(), view2, NULL);
6033 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6034 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6035 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6036}
6037
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006038TEST_F(VkLayerTest, DescriptorPoolInUseDestroyedSignaled) {
6039 TEST_DESCRIPTION("Delete a DescriptorPool with a DescriptorSet that is in use.");
6040 ASSERT_NO_FATAL_FAILURE(InitState());
6041 ASSERT_NO_FATAL_FAILURE(InitViewport());
6042 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6043
6044 VkDescriptorPoolSize ds_type_count = {};
6045 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6046 ds_type_count.descriptorCount = 1;
6047
6048 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6049 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6050 ds_pool_ci.pNext = NULL;
6051 ds_pool_ci.maxSets = 1;
6052 ds_pool_ci.poolSizeCount = 1;
6053 ds_pool_ci.pPoolSizes = &ds_type_count;
6054
6055 VkDescriptorPool ds_pool;
6056 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6057 ASSERT_VK_SUCCESS(err);
6058
6059 VkDescriptorSetLayoutBinding dsl_binding = {};
6060 dsl_binding.binding = 0;
6061 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6062 dsl_binding.descriptorCount = 1;
6063 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6064 dsl_binding.pImmutableSamplers = NULL;
6065
6066 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6067 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6068 ds_layout_ci.pNext = NULL;
6069 ds_layout_ci.bindingCount = 1;
6070 ds_layout_ci.pBindings = &dsl_binding;
6071 VkDescriptorSetLayout ds_layout;
6072 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6073 ASSERT_VK_SUCCESS(err);
6074
6075 VkDescriptorSet descriptor_set;
6076 VkDescriptorSetAllocateInfo alloc_info = {};
6077 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6078 alloc_info.descriptorSetCount = 1;
6079 alloc_info.descriptorPool = ds_pool;
6080 alloc_info.pSetLayouts = &ds_layout;
6081 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
6082 ASSERT_VK_SUCCESS(err);
6083
6084 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6085 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6086 pipeline_layout_ci.pNext = NULL;
6087 pipeline_layout_ci.setLayoutCount = 1;
6088 pipeline_layout_ci.pSetLayouts = &ds_layout;
6089
6090 VkPipelineLayout pipeline_layout;
6091 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6092 ASSERT_VK_SUCCESS(err);
6093
6094 // Create image to update the descriptor with
6095 VkImageObj image(m_device);
6096 image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
6097 ASSERT_TRUE(image.initialized());
6098
6099 VkImageView view = image.targetView(VK_FORMAT_B8G8R8A8_UNORM);
6100 // Create Sampler
6101 VkSamplerCreateInfo sampler_ci = {};
6102 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6103 sampler_ci.pNext = NULL;
6104 sampler_ci.magFilter = VK_FILTER_NEAREST;
6105 sampler_ci.minFilter = VK_FILTER_NEAREST;
6106 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6107 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6108 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6109 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6110 sampler_ci.mipLodBias = 1.0;
6111 sampler_ci.anisotropyEnable = VK_FALSE;
6112 sampler_ci.maxAnisotropy = 1;
6113 sampler_ci.compareEnable = VK_FALSE;
6114 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6115 sampler_ci.minLod = 1.0;
6116 sampler_ci.maxLod = 1.0;
6117 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6118 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6119 VkSampler sampler;
6120 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6121 ASSERT_VK_SUCCESS(err);
6122 // Update descriptor with image and sampler
6123 VkDescriptorImageInfo img_info = {};
6124 img_info.sampler = sampler;
6125 img_info.imageView = view;
6126 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6127
6128 VkWriteDescriptorSet descriptor_write;
6129 memset(&descriptor_write, 0, sizeof(descriptor_write));
6130 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6131 descriptor_write.dstSet = descriptor_set;
6132 descriptor_write.dstBinding = 0;
6133 descriptor_write.descriptorCount = 1;
6134 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6135 descriptor_write.pImageInfo = &img_info;
6136
6137 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6138
6139 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006140 char const *vsSource =
6141 "#version 450\n"
6142 "\n"
6143 "out gl_PerVertex { \n"
6144 " vec4 gl_Position;\n"
6145 "};\n"
6146 "void main(){\n"
6147 " gl_Position = vec4(1);\n"
6148 "}\n";
6149 char const *fsSource =
6150 "#version 450\n"
6151 "\n"
6152 "layout(set=0, binding=0) uniform sampler2D s;\n"
6153 "layout(location=0) out vec4 x;\n"
6154 "void main(){\n"
6155 " x = texture(s, vec2(1));\n"
6156 "}\n";
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006157 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6158 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6159 VkPipelineObj pipe(m_device);
6160 pipe.AddShader(&vs);
6161 pipe.AddShader(&fs);
6162 pipe.AddColorAttachment();
6163 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6164
Tony Barbour552f6c02016-12-21 14:34:07 -07006165 m_commandBuffer->BeginCommandBuffer();
6166 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006167 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6168 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6169 &descriptor_set, 0, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006170
6171 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6172 VkRect2D scissor = {{0, 0}, {16, 16}};
6173 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6174 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6175
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006176 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -07006177 m_commandBuffer->EndRenderPass();
6178 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006179 // Submit cmd buffer to put pool in-flight
6180 VkSubmitInfo submit_info = {};
6181 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
6182 submit_info.commandBufferCount = 1;
6183 submit_info.pCommandBuffers = &m_commandBuffer->handle();
6184 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
6185 // Destroy pool while in-flight, causing error
6186 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot delete descriptor pool ");
6187 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6188 m_errorMonitor->VerifyFound();
6189 vkQueueWaitIdle(m_device->m_queue);
6190 // Cleanup
6191 vkDestroySampler(m_device->device(), sampler, NULL);
6192 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6193 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07006194 m_errorMonitor->SetUnexpectedError(
6195 "If descriptorPool is not VK_NULL_HANDLE, descriptorPool must be a valid VkDescriptorPool handle");
6196 m_errorMonitor->SetUnexpectedError("Unable to remove Descriptor Pool obj");
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006197 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsaye353a072017-01-16 11:07:28 -07006198 // TODO : It seems Validation layers think ds_pool was already destroyed, even though it wasn't?
Tobin Ehlis6dd1b2e2016-10-12 15:12:05 -06006199}
6200
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006201TEST_F(VkLayerTest, DescriptorImageUpdateNoMemoryBound) {
6202 TEST_DESCRIPTION("Attempt an image descriptor set update where image's bound memory has been freed.");
6203 ASSERT_NO_FATAL_FAILURE(InitState());
6204 ASSERT_NO_FATAL_FAILURE(InitViewport());
6205 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6206
6207 VkDescriptorPoolSize ds_type_count = {};
6208 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6209 ds_type_count.descriptorCount = 1;
6210
6211 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6212 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6213 ds_pool_ci.pNext = NULL;
6214 ds_pool_ci.maxSets = 1;
6215 ds_pool_ci.poolSizeCount = 1;
6216 ds_pool_ci.pPoolSizes = &ds_type_count;
6217
6218 VkDescriptorPool ds_pool;
6219 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
6220 ASSERT_VK_SUCCESS(err);
6221
6222 VkDescriptorSetLayoutBinding dsl_binding = {};
6223 dsl_binding.binding = 0;
6224 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6225 dsl_binding.descriptorCount = 1;
6226 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6227 dsl_binding.pImmutableSamplers = NULL;
6228
6229 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6230 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6231 ds_layout_ci.pNext = NULL;
6232 ds_layout_ci.bindingCount = 1;
6233 ds_layout_ci.pBindings = &dsl_binding;
6234 VkDescriptorSetLayout ds_layout;
6235 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
6236 ASSERT_VK_SUCCESS(err);
6237
6238 VkDescriptorSet descriptorSet;
6239 VkDescriptorSetAllocateInfo alloc_info = {};
6240 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6241 alloc_info.descriptorSetCount = 1;
6242 alloc_info.descriptorPool = ds_pool;
6243 alloc_info.pSetLayouts = &ds_layout;
6244 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
6245 ASSERT_VK_SUCCESS(err);
6246
6247 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6248 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6249 pipeline_layout_ci.pNext = NULL;
6250 pipeline_layout_ci.setLayoutCount = 1;
6251 pipeline_layout_ci.pSetLayouts = &ds_layout;
6252
6253 VkPipelineLayout pipeline_layout;
6254 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
6255 ASSERT_VK_SUCCESS(err);
6256
6257 // Create images to update the descriptor with
6258 VkImage image;
6259 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
6260 const int32_t tex_width = 32;
6261 const int32_t tex_height = 32;
6262 VkImageCreateInfo image_create_info = {};
6263 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
6264 image_create_info.pNext = NULL;
6265 image_create_info.imageType = VK_IMAGE_TYPE_2D;
6266 image_create_info.format = tex_format;
6267 image_create_info.extent.width = tex_width;
6268 image_create_info.extent.height = tex_height;
6269 image_create_info.extent.depth = 1;
6270 image_create_info.mipLevels = 1;
6271 image_create_info.arrayLayers = 1;
6272 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
6273 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
6274 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
6275 image_create_info.flags = 0;
6276 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
6277 ASSERT_VK_SUCCESS(err);
6278 // Initially bind memory to avoid error at bind view time. We'll break binding before update.
6279 VkMemoryRequirements memory_reqs;
6280 VkDeviceMemory image_memory;
6281 bool pass;
6282 VkMemoryAllocateInfo memory_info = {};
6283 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6284 memory_info.pNext = NULL;
6285 memory_info.allocationSize = 0;
6286 memory_info.memoryTypeIndex = 0;
6287 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
6288 // Allocate enough memory for image
6289 memory_info.allocationSize = memory_reqs.size;
6290 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
6291 ASSERT_TRUE(pass);
6292 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
6293 ASSERT_VK_SUCCESS(err);
6294 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
6295 ASSERT_VK_SUCCESS(err);
6296
6297 VkImageViewCreateInfo image_view_create_info = {};
6298 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
6299 image_view_create_info.image = image;
6300 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
6301 image_view_create_info.format = tex_format;
6302 image_view_create_info.subresourceRange.layerCount = 1;
6303 image_view_create_info.subresourceRange.baseMipLevel = 0;
6304 image_view_create_info.subresourceRange.levelCount = 1;
6305 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
6306
6307 VkImageView view;
6308 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
6309 ASSERT_VK_SUCCESS(err);
6310 // Create Samplers
6311 VkSamplerCreateInfo sampler_ci = {};
6312 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
6313 sampler_ci.pNext = NULL;
6314 sampler_ci.magFilter = VK_FILTER_NEAREST;
6315 sampler_ci.minFilter = VK_FILTER_NEAREST;
6316 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
6317 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6318 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6319 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
6320 sampler_ci.mipLodBias = 1.0;
6321 sampler_ci.anisotropyEnable = VK_FALSE;
6322 sampler_ci.maxAnisotropy = 1;
6323 sampler_ci.compareEnable = VK_FALSE;
6324 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
6325 sampler_ci.minLod = 1.0;
6326 sampler_ci.maxLod = 1.0;
6327 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
6328 sampler_ci.unnormalizedCoordinates = VK_FALSE;
6329 VkSampler sampler;
6330 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
6331 ASSERT_VK_SUCCESS(err);
6332 // Update descriptor with image and sampler
6333 VkDescriptorImageInfo img_info = {};
6334 img_info.sampler = sampler;
6335 img_info.imageView = view;
6336 img_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
6337
6338 VkWriteDescriptorSet descriptor_write;
6339 memset(&descriptor_write, 0, sizeof(descriptor_write));
6340 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6341 descriptor_write.dstSet = descriptorSet;
6342 descriptor_write.dstBinding = 0;
6343 descriptor_write.descriptorCount = 1;
6344 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
6345 descriptor_write.pImageInfo = &img_info;
6346 // Break memory binding and attempt update
6347 vkFreeMemory(m_device->device(), image_memory, nullptr);
6348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006349 " previously bound memory was freed. Memory must not be freed prior to this operation.");
Tobin Ehlis50a095d2016-09-21 17:32:49 -06006350 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6351 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
6352 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6353 m_errorMonitor->VerifyFound();
6354 // Cleanup
6355 vkDestroyImage(m_device->device(), image, NULL);
6356 vkDestroySampler(m_device->device(), sampler, NULL);
6357 vkDestroyImageView(m_device->device(), view, NULL);
6358 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6359 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6360 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6361}
6362
Karl Schultz6addd812016-02-02 17:17:23 -07006363TEST_F(VkLayerTest, InvalidPipeline) {
Karl Schultzbdb75952016-04-19 11:36:49 -06006364 // Attempt to bind an invalid Pipeline to a valid Command Buffer
6365 // ObjectTracker should catch this.
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006366 // Create a valid cmd buffer
6367 // call vkCmdBindPipeline w/ false Pipeline
Mark Lobodzinski02bf89d2016-05-10 14:45:13 -06006368 uint64_t fake_pipeline_handle = 0xbaad6001;
6369 VkPipeline bad_pipeline = reinterpret_cast<VkPipeline &>(fake_pipeline_handle);
Karl Schultzbdb75952016-04-19 11:36:49 -06006370 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006371 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6372
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006373 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00601);
Tony Barbour552f6c02016-12-21 14:34:07 -07006374 m_commandBuffer->BeginCommandBuffer();
6375 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006376 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, bad_pipeline);
Karl Schultzbdb75952016-04-19 11:36:49 -06006377 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006378
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006379 // Now issue a draw call with no pipeline bound
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006380 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 -06006381 Draw(1, 0, 0, 0);
6382 m_errorMonitor->VerifyFound();
Chris Forbes4dbf70f2016-09-16 17:58:00 +12006383
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006384 // Finally same check once more but with Dispatch/Compute
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006385 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 -07006386 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle()); // must be outside renderpass
Tobin Ehlisb8b6b272016-05-02 13:26:06 -06006387 vkCmdDispatch(m_commandBuffer->GetBufferHandle(), 0, 0, 0);
6388 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06006389}
6390
Karl Schultz6addd812016-02-02 17:17:23 -07006391TEST_F(VkLayerTest, DescriptorSetNotUpdated) {
Tobin Ehlis5a5f5ef2016-08-17 13:56:55 -06006392 TEST_DESCRIPTION("Bind a descriptor set that hasn't been updated.");
Karl Schultz6addd812016-02-02 17:17:23 -07006393 VkResult err;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006395 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, " bound but it was never updated. ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06006396
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006397 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyan713b2d72015-08-04 10:49:29 -06006398 ASSERT_NO_FATAL_FAILURE(InitViewport());
6399 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +08006400 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006401 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6402 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06006403
6404 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006405 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6406 ds_pool_ci.pNext = NULL;
6407 ds_pool_ci.maxSets = 1;
6408 ds_pool_ci.poolSizeCount = 1;
6409 ds_pool_ci.pPoolSizes = &ds_type_count;
Mike Stroyan713b2d72015-08-04 10:49:29 -06006410
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006411 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006412 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006413 ASSERT_VK_SUCCESS(err);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006414
Tony Barboureb254902015-07-15 12:50:33 -06006415 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006416 dsl_binding.binding = 0;
6417 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
6418 dsl_binding.descriptorCount = 1;
6419 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6420 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006421
Tony Barboureb254902015-07-15 12:50:33 -06006422 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006423 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6424 ds_layout_ci.pNext = NULL;
6425 ds_layout_ci.bindingCount = 1;
6426 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006427 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006428 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006429 ASSERT_VK_SUCCESS(err);
6430
6431 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08006432 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006433 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006434 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06006435 alloc_info.descriptorPool = ds_pool;
6436 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006437 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006438 ASSERT_VK_SUCCESS(err);
6439
Tony Barboureb254902015-07-15 12:50:33 -06006440 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006441 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6442 pipeline_layout_ci.pNext = NULL;
6443 pipeline_layout_ci.setLayoutCount = 1;
6444 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006445
6446 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006447 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006448 ASSERT_VK_SUCCESS(err);
6449
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006450 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -06006451 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -07006452 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006453 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006454
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006455 VkPipelineObj pipe(m_device);
6456 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -06006457 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -06006458 pipe.AddColorAttachment();
Tony Barbourc95e4ac2015-08-04 17:05:26 -06006459 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -06006460
Tony Barbour552f6c02016-12-21 14:34:07 -07006461 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006462 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
6463 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6464 &descriptorSet, 0, NULL);
Tobin Ehlis7d1a7112015-05-27 14:32:28 -06006465
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006466 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06006467
Chia-I Wuf7458c52015-10-26 21:10:41 +08006468 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6469 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6470 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06006471}
6472
Karl Schultz6addd812016-02-02 17:17:23 -07006473TEST_F(VkLayerTest, InvalidBufferViewObject) {
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006474 // Create a single TEXEL_BUFFER descriptor and send it an invalid bufferView
Karl Schultz6addd812016-02-02 17:17:23 -07006475 VkResult err;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006476
Karl Schultzf78bcdd2016-11-30 12:36:01 -07006477 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00940);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006478
6479 ASSERT_NO_FATAL_FAILURE(InitState());
6480 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006481 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6482 ds_type_count.descriptorCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006483
6484 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006485 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6486 ds_pool_ci.pNext = NULL;
6487 ds_pool_ci.maxSets = 1;
6488 ds_pool_ci.poolSizeCount = 1;
6489 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006490
6491 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006492 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006493 ASSERT_VK_SUCCESS(err);
6494
6495 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006496 dsl_binding.binding = 0;
6497 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6498 dsl_binding.descriptorCount = 1;
6499 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6500 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006501
6502 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006503 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6504 ds_layout_ci.pNext = NULL;
6505 ds_layout_ci.bindingCount = 1;
6506 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006507 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006508 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006509 ASSERT_VK_SUCCESS(err);
6510
6511 VkDescriptorSet descriptorSet;
6512 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006513 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006514 alloc_info.descriptorSetCount = 1;
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006515 alloc_info.descriptorPool = ds_pool;
6516 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006517 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006518 ASSERT_VK_SUCCESS(err);
6519
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006520 VkBufferView view = (VkBufferView)((size_t)0xbaadbeef); // invalid bufferView object
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006521 VkWriteDescriptorSet descriptor_write;
6522 memset(&descriptor_write, 0, sizeof(descriptor_write));
6523 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6524 descriptor_write.dstSet = descriptorSet;
6525 descriptor_write.dstBinding = 0;
6526 descriptor_write.descriptorCount = 1;
6527 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
6528 descriptor_write.pTexelBufferView = &view;
6529
6530 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6531
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006532 m_errorMonitor->VerifyFound();
Tobin Ehlisba31cab2015-11-02 15:24:32 -07006533
6534 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6535 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6536}
6537
Mark Youngd339ba32016-05-30 13:28:35 -06006538TEST_F(VkLayerTest, CreateBufferViewNoMemoryBoundToBuffer) {
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006539 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 -06006540
6541 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006542 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006543 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -06006544
6545 ASSERT_NO_FATAL_FAILURE(InitState());
6546
6547 // Create a buffer with no bound memory and then attempt to create
6548 // a buffer view.
6549 VkBufferCreateInfo buff_ci = {};
6550 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Chris Forbes4538d242016-09-13 18:13:58 +12006551 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -06006552 buff_ci.size = 256;
6553 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
6554 VkBuffer buffer;
6555 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
6556 ASSERT_VK_SUCCESS(err);
6557
6558 VkBufferViewCreateInfo buff_view_ci = {};
6559 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
6560 buff_view_ci.buffer = buffer;
6561 buff_view_ci.format = VK_FORMAT_R8_UNORM;
6562 buff_view_ci.range = VK_WHOLE_SIZE;
6563 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006564 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Mark Youngd339ba32016-05-30 13:28:35 -06006565
6566 m_errorMonitor->VerifyFound();
6567 vkDestroyBuffer(m_device->device(), buffer, NULL);
6568 // If last error is success, it still created the view, so delete it.
6569 if (err == VK_SUCCESS) {
6570 vkDestroyBufferView(m_device->device(), buff_view, NULL);
6571 }
6572}
6573
Karl Schultz6addd812016-02-02 17:17:23 -07006574TEST_F(VkLayerTest, InvalidDynamicOffsetCases) {
6575 // Create a descriptorSet w/ dynamic descriptor and then hit 3 offset error
6576 // cases:
Tobin Ehlisf6585052015-12-17 11:48:42 -07006577 // 1. No dynamicOffset supplied
6578 // 2. Too many dynamicOffsets supplied
6579 // 3. Dynamic offset oversteps buffer being updated
Karl Schultz6addd812016-02-02 17:17:23 -07006580 VkResult err;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6582 " requires 1 dynamicOffsets, but only "
6583 "0 dynamicOffsets are left in "
6584 "pDynamicOffsets ");
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006585
6586 ASSERT_NO_FATAL_FAILURE(InitState());
6587 ASSERT_NO_FATAL_FAILURE(InitViewport());
6588 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6589
6590 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006591 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6592 ds_type_count.descriptorCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006593
6594 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006595 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6596 ds_pool_ci.pNext = NULL;
6597 ds_pool_ci.maxSets = 1;
6598 ds_pool_ci.poolSizeCount = 1;
6599 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006600
6601 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006602 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006603 ASSERT_VK_SUCCESS(err);
6604
6605 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006606 dsl_binding.binding = 0;
6607 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6608 dsl_binding.descriptorCount = 1;
6609 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6610 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006611
6612 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006613 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6614 ds_layout_ci.pNext = NULL;
6615 ds_layout_ci.bindingCount = 1;
6616 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006617 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006618 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006619 ASSERT_VK_SUCCESS(err);
6620
6621 VkDescriptorSet descriptorSet;
6622 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08006623 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07006624 alloc_info.descriptorSetCount = 1;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006625 alloc_info.descriptorPool = ds_pool;
6626 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006627 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006628 ASSERT_VK_SUCCESS(err);
6629
6630 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006631 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6632 pipeline_layout_ci.pNext = NULL;
6633 pipeline_layout_ci.setLayoutCount = 1;
6634 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006635
6636 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006637 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006638 ASSERT_VK_SUCCESS(err);
6639
6640 // Create a buffer to update the descriptor with
6641 uint32_t qfi = 0;
6642 VkBufferCreateInfo buffCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006643 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6644 buffCI.size = 1024;
6645 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6646 buffCI.queueFamilyIndexCount = 1;
6647 buffCI.pQueueFamilyIndices = &qfi;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006648
6649 VkBuffer dyub;
6650 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6651 ASSERT_VK_SUCCESS(err);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006652 // Allocate memory and bind to buffer so we can make it to the appropriate
6653 // error
6654 VkMemoryAllocateInfo mem_alloc = {};
6655 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
6656 mem_alloc.pNext = NULL;
6657 mem_alloc.allocationSize = 1024;
Chris Forbesb6116cc2016-05-08 11:39:59 +12006658 mem_alloc.memoryTypeIndex = 0;
6659
6660 VkMemoryRequirements memReqs;
6661 vkGetBufferMemoryRequirements(m_device->device(), dyub, &memReqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006662 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
Chris Forbesb6116cc2016-05-08 11:39:59 +12006663 if (!pass) {
6664 vkDestroyBuffer(m_device->device(), dyub, NULL);
6665 return;
6666 }
6667
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006668 VkDeviceMemory mem;
6669 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
6670 ASSERT_VK_SUCCESS(err);
6671 err = vkBindBufferMemory(m_device->device(), dyub, mem, 0);
6672 ASSERT_VK_SUCCESS(err);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006673 // Correctly update descriptor to avoid "NOT_UPDATED" error
6674 VkDescriptorBufferInfo buffInfo = {};
Karl Schultz6addd812016-02-02 17:17:23 -07006675 buffInfo.buffer = dyub;
6676 buffInfo.offset = 0;
6677 buffInfo.range = 1024;
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006678
6679 VkWriteDescriptorSet descriptor_write;
6680 memset(&descriptor_write, 0, sizeof(descriptor_write));
6681 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6682 descriptor_write.dstSet = descriptorSet;
6683 descriptor_write.dstBinding = 0;
6684 descriptor_write.descriptorCount = 1;
6685 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6686 descriptor_write.pBufferInfo = &buffInfo;
6687
6688 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6689
Tony Barbour552f6c02016-12-21 14:34:07 -07006690 m_commandBuffer->BeginCommandBuffer();
6691 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006692 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6693 &descriptorSet, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006694 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006695 uint32_t pDynOff[2] = {512, 756};
6696 // Now cause error b/c too many dynOffsets in array for # of dyn descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6698 "Attempting to bind 1 descriptorSets with 1 dynamic descriptors, but ");
6699 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6700 &descriptorSet, 2, pDynOff);
Chris Forbes7b342802016-04-07 13:20:10 +12006701 m_errorMonitor->VerifyFound();
Tobin Ehlisf6585052015-12-17 11:48:42 -07006702 // Finally cause error due to dynamicOffset being too big
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006703 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6704 " dynamic offset 512 combined with "
6705 "offset 0 and range 1024 that "
6706 "oversteps the buffer size of 1024");
Tobin Ehlisf6585052015-12-17 11:48:42 -07006707 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006708 char const *vsSource =
6709 "#version 450\n"
6710 "\n"
6711 "out gl_PerVertex { \n"
6712 " vec4 gl_Position;\n"
6713 "};\n"
6714 "void main(){\n"
6715 " gl_Position = vec4(1);\n"
6716 "}\n";
6717 char const *fsSource =
6718 "#version 450\n"
6719 "\n"
6720 "layout(location=0) out vec4 x;\n"
6721 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
6722 "void main(){\n"
6723 " x = vec4(bar.y);\n"
6724 "}\n";
Tobin Ehlisf6585052015-12-17 11:48:42 -07006725 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
6726 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
6727 VkPipelineObj pipe(m_device);
6728 pipe.AddShader(&vs);
6729 pipe.AddShader(&fs);
6730 pipe.AddColorAttachment();
6731 pipe.CreateVKPipeline(pipeline_layout, renderPass());
6732
Rene Lindsayacbf5e62016-12-15 18:47:11 -07006733 VkViewport viewport = {0, 0, 16, 16, 0, 1};
6734 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
6735 VkRect2D scissor = {{0, 0}, {16, 16}};
6736 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
6737
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006738 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07006739 // This update should succeed, but offset size of 512 will overstep buffer
6740 // /w range 1024 & size 1024
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006741 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
6742 &descriptorSet, 1, pDynOff);
Tobin Ehlisf6585052015-12-17 11:48:42 -07006743 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006744 m_errorMonitor->VerifyFound();
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006745
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006746 vkDestroyBuffer(m_device->device(), dyub, NULL);
Tobin Ehlis512098e2016-05-05 09:06:12 -06006747 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis0a43bde2016-05-03 08:31:08 -06006748
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006749 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06006750 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis49f903e2015-11-04 13:30:34 -07006751 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6752}
6753
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006754TEST_F(VkLayerTest, DescriptorBufferUpdateNoMemoryBound) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07006755 TEST_DESCRIPTION(
6756 "Attempt to update a descriptor with a non-sparse buffer "
6757 "that doesn't have memory bound");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006758 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006759 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -06006760 " used with no memory bound. Memory should be bound by calling vkBindBufferMemory().");
Tobin Ehlisfed999f2016-09-21 15:09:45 -06006761 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
6762 "vkUpdateDescriptorsSets() failed write update validation for Descriptor Set 0x");
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006763
6764 ASSERT_NO_FATAL_FAILURE(InitState());
6765 ASSERT_NO_FATAL_FAILURE(InitViewport());
6766 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6767
6768 VkDescriptorPoolSize ds_type_count = {};
6769 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6770 ds_type_count.descriptorCount = 1;
6771
6772 VkDescriptorPoolCreateInfo ds_pool_ci = {};
6773 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
6774 ds_pool_ci.pNext = NULL;
6775 ds_pool_ci.maxSets = 1;
6776 ds_pool_ci.poolSizeCount = 1;
6777 ds_pool_ci.pPoolSizes = &ds_type_count;
6778
6779 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006780 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006781 ASSERT_VK_SUCCESS(err);
6782
6783 VkDescriptorSetLayoutBinding dsl_binding = {};
6784 dsl_binding.binding = 0;
6785 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6786 dsl_binding.descriptorCount = 1;
6787 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
6788 dsl_binding.pImmutableSamplers = NULL;
6789
6790 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
6791 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
6792 ds_layout_ci.pNext = NULL;
6793 ds_layout_ci.bindingCount = 1;
6794 ds_layout_ci.pBindings = &dsl_binding;
6795 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006796 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006797 ASSERT_VK_SUCCESS(err);
6798
6799 VkDescriptorSet descriptorSet;
6800 VkDescriptorSetAllocateInfo alloc_info = {};
6801 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
6802 alloc_info.descriptorSetCount = 1;
6803 alloc_info.descriptorPool = ds_pool;
6804 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006805 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis8ef479c2016-07-20 16:14:49 -06006806 ASSERT_VK_SUCCESS(err);
6807
6808 // Create a buffer to update the descriptor with
6809 uint32_t qfi = 0;
6810 VkBufferCreateInfo buffCI = {};
6811 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
6812 buffCI.size = 1024;
6813 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
6814 buffCI.queueFamilyIndexCount = 1;
6815 buffCI.pQueueFamilyIndices = &qfi;
6816
6817 VkBuffer dyub;
6818 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub);
6819 ASSERT_VK_SUCCESS(err);
6820
6821 // Attempt to update descriptor without binding memory to it
6822 VkDescriptorBufferInfo buffInfo = {};
6823 buffInfo.buffer = dyub;
6824 buffInfo.offset = 0;
6825 buffInfo.range = 1024;
6826
6827 VkWriteDescriptorSet descriptor_write;
6828 memset(&descriptor_write, 0, sizeof(descriptor_write));
6829 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
6830 descriptor_write.dstSet = descriptorSet;
6831 descriptor_write.dstBinding = 0;
6832 descriptor_write.descriptorCount = 1;
6833 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
6834 descriptor_write.pBufferInfo = &buffInfo;
6835
6836 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
6837 m_errorMonitor->VerifyFound();
6838
6839 vkDestroyBuffer(m_device->device(), dyub, NULL);
6840 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
6841 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
6842}
6843
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006844TEST_F(VkLayerTest, InvalidPushConstants) {
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006845 VkResult err;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006846 ASSERT_NO_FATAL_FAILURE(InitState());
6847 ASSERT_NO_FATAL_FAILURE(InitViewport());
6848 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
6849
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006850 VkPipelineLayout pipeline_layout;
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006851 VkPushConstantRange pc_range = {};
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006852 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
6853 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
6854 pipeline_layout_ci.pushConstantRangeCount = 1;
6855 pipeline_layout_ci.pPushConstantRanges = &pc_range;
6856
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006857 //
6858 // Check for invalid push constant ranges in pipeline layouts.
6859 //
6860 struct PipelineLayoutTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006861 VkPushConstantRange const range;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006862 char const *msg;
6863 };
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006864
Karl Schultzc81037d2016-05-12 08:11:23 -06006865 const uint32_t too_big = m_device->props.limits.maxPushConstantsSize + 0x4;
6866 const std::array<PipelineLayoutTestCase, 10> range_tests = {{
6867 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 0},
6868 "vkCreatePipelineLayout() call has push constants index 0 with "
6869 "size 0."},
6870 {{VK_SHADER_STAGE_VERTEX_BIT, 0, 1},
6871 "vkCreatePipelineLayout() call has push constants index 0 with "
6872 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006873 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 1},
Karl Schultzc81037d2016-05-12 08:11:23 -06006874 "vkCreatePipelineLayout() call has push constants index 0 with "
6875 "size 1."},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006876 {{VK_SHADER_STAGE_VERTEX_BIT, 4, 0},
Karl Schultzc81037d2016-05-12 08:11:23 -06006877 "vkCreatePipelineLayout() call has push constants index 0 with "
6878 "size 0."},
6879 {{VK_SHADER_STAGE_VERTEX_BIT, 1, 4},
6880 "vkCreatePipelineLayout() call has push constants index 0 with "
6881 "offset 1. Offset must"},
6882 {{VK_SHADER_STAGE_VERTEX_BIT, 0, too_big},
6883 "vkCreatePipelineLayout() call has push constants index 0 "
6884 "with offset "},
6885 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, too_big},
6886 "vkCreatePipelineLayout() call has push constants "
6887 "index 0 with offset "},
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006888 {{VK_SHADER_STAGE_VERTEX_BIT, too_big, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06006889 "vkCreatePipelineLayout() call has push constants index 0 "
6890 "with offset "},
6891 {{VK_SHADER_STAGE_VERTEX_BIT, 0xFFFFFFF0, 0x00000020},
6892 "vkCreatePipelineLayout() call has push "
6893 "constants index 0 with offset "},
6894 {{VK_SHADER_STAGE_VERTEX_BIT, 0x00000020, 0xFFFFFFF0},
6895 "vkCreatePipelineLayout() call has push "
6896 "constants index 0 with offset "},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006897 }};
6898
6899 // Check for invalid offset and size
Karl Schultzc81037d2016-05-12 08:11:23 -06006900 for (const auto &iter : range_tests) {
6901 pc_range = iter.range;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg);
6903 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006904 m_errorMonitor->VerifyFound();
6905 if (VK_SUCCESS == err) {
6906 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6907 }
6908 }
6909
6910 // Check for invalid stage flag
6911 pc_range.offset = 0;
6912 pc_range.size = 16;
6913 pc_range.stageFlags = 0;
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06006914 m_errorMonitor->SetDesiredFailureMsg(
6915 VK_DEBUG_REPORT_ERROR_BIT_EXT,
6916 "vkCreatePipelineLayout: value of pCreateInfo->pPushConstantRanges[0].stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006917 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12006918 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006919 if (VK_SUCCESS == err) {
6920 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6921 }
6922
Karl Schultzc59b72d2017-02-24 15:45:05 -07006923 // Check for duplicate stage flags in a list of push constant ranges.
6924 // A shader can only have one push constant block and that block is mapped
6925 // to the push constant range that has that shader's stage flag set.
6926 // The shader's stage flag can only appear once in all the ranges, so the
6927 // implementation can find the one and only range to map it to.
Karl Schultzc81037d2016-05-12 08:11:23 -06006928 const uint32_t ranges_per_test = 5;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006929 struct DuplicateStageFlagsTestCase {
Karl Schultzc81037d2016-05-12 08:11:23 -06006930 VkPushConstantRange const ranges[ranges_per_test];
Jeremy Hayesde6d96c2017-02-01 15:22:32 -07006931 std::vector<char const *> const msg;
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006932 };
Karl Schultzc59b72d2017-02-24 15:45:05 -07006933 // Overlapping ranges are OK, but a stage flag can appear only once.
6934 const std::array<DuplicateStageFlagsTestCase, 3> duplicate_stageFlags_tests = {
6935 {
6936 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6937 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6938 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6939 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006940 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4}},
Karl Schultzc59b72d2017-02-24 15:45:05 -07006941 {
6942 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 1.",
6943 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 2.",
6944 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6945 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 4.",
6946 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 2.",
6947 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 3.",
6948 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6949 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6950 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 4.",
6951 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 3 and 4.",
6952 }},
6953 {{{VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6954 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4},
6955 {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6956 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6957 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6958 {
6959 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 0 and 3.",
6960 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 1 and 4.",
6961 }},
6962 {{{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4},
6963 {VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0, 4},
6964 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6965 {VK_SHADER_STAGE_VERTEX_BIT, 0, 4},
6966 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 4}},
6967 {
6968 "vkCreatePipelineLayout() Duplicate stage flags found in ranges 2 and 3.",
6969 }},
6970 },
6971 };
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006972
Karl Schultzc59b72d2017-02-24 15:45:05 -07006973 for (const auto &iter : duplicate_stageFlags_tests) {
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006974 pipeline_layout_ci.pPushConstantRanges = iter.ranges;
Karl Schultzc81037d2016-05-12 08:11:23 -06006975 pipeline_layout_ci.pushConstantRangeCount = ranges_per_test;
Karl Schultzc59b72d2017-02-24 15:45:05 -07006976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, iter.msg.begin(), iter.msg.end());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006977 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006978 m_errorMonitor->VerifyFound();
6979 if (VK_SUCCESS == err) {
6980 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
6981 }
6982 }
6983
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006984 //
6985 // CmdPushConstants tests
6986 //
6987
Karl Schultzc59b72d2017-02-24 15:45:05 -07006988 // Setup a pipeline layout with ranges: [0,16) [64,80)
Karl Schultzc81037d2016-05-12 08:11:23 -06006989 const VkPushConstantRange pc_range2[] = {
Karl Schultzc59b72d2017-02-24 15:45:05 -07006990 {VK_SHADER_STAGE_VERTEX_BIT, 64, 16}, {VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006991 };
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006992 pipeline_layout_ci.pushConstantRangeCount = sizeof(pc_range2) / sizeof(VkPushConstantRange);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06006993 pipeline_layout_ci.pPushConstantRanges = pc_range2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06006994 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07006995 ASSERT_VK_SUCCESS(err);
Karl Schultzc59b72d2017-02-24 15:45:05 -07006996
6997 const uint8_t dummy_values[100] = {};
6998
6999 m_commandBuffer->BeginCommandBuffer();
7000 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007001
7002 // Check for invalid stage flag
Karl Schultzc59b72d2017-02-24 15:45:05 -07007003 // Note that VU 00996 isn't reached due to parameter validation
Karl Schultzb7c6d0f2016-09-13 14:23:19 -06007004 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdPushConstants: value of stageFlags must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007005 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, 0, 0, 16, dummy_values);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007006 m_errorMonitor->VerifyFound();
Karl Schultzfc8eaf12016-05-06 13:56:42 -06007007
Karl Schultzc59b72d2017-02-24 15:45:05 -07007008 m_errorMonitor->ExpectSuccess();
7009 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16, dummy_values);
7010 m_errorMonitor->VerifyNotFound();
7011 m_errorMonitor->ExpectSuccess();
7012 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, VK_SHADER_STAGE_VERTEX_BIT, 64, 16, dummy_values);
7013 m_errorMonitor->VerifyNotFound();
7014 const std::array<VkPushConstantRange, 6> cmd_range_tests = {{
7015 {VK_SHADER_STAGE_FRAGMENT_BIT, 64, 16},
7016 {VK_SHADER_STAGE_VERTEX_BIT, 0, 16},
7017 {VK_SHADER_STAGE_GEOMETRY_BIT, 0, 16},
7018 {VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, 16},
7019 {VK_SHADER_STAGE_VERTEX_BIT, 24, 16},
7020 {VK_SHADER_STAGE_VERTEX_BIT, 8, 4},
Karl Schultzc81037d2016-05-12 08:11:23 -06007021 }};
Karl Schultzc59b72d2017-02-24 15:45:05 -07007022 for (const auto &iter : cmd_range_tests) {
7023 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00988);
7024 vkCmdPushConstants(m_commandBuffer->GetBufferHandle(), pipeline_layout, iter.stageFlags, iter.offset, iter.size,
7025 dummy_values);
Karl Schultzc81037d2016-05-12 08:11:23 -06007026 m_errorMonitor->VerifyFound();
7027 }
Karl Schultzc81037d2016-05-12 08:11:23 -06007028
Tony Barbour552f6c02016-12-21 14:34:07 -07007029 m_commandBuffer->EndRenderPass();
7030 m_commandBuffer->EndCommandBuffer();
Karl Schultzc59b72d2017-02-24 15:45:05 -07007031 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
Tobin Ehlis3a23b6a2016-02-17 10:35:18 -07007032}
7033
Karl Schultz6addd812016-02-02 17:17:23 -07007034TEST_F(VkLayerTest, DescriptorSetCompatibility) {
Tobin Ehlis559c6382015-11-05 09:52:49 -07007035 // Test various desriptorSet errors with bad binding combinations
Karl Schultz6addd812016-02-02 17:17:23 -07007036 VkResult err;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007037
7038 ASSERT_NO_FATAL_FAILURE(InitState());
7039 ASSERT_NO_FATAL_FAILURE(InitViewport());
7040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
7041
7042 static const uint32_t NUM_DESCRIPTOR_TYPES = 5;
7043 VkDescriptorPoolSize ds_type_count[NUM_DESCRIPTOR_TYPES] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007044 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7045 ds_type_count[0].descriptorCount = 10;
7046 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
7047 ds_type_count[1].descriptorCount = 2;
7048 ds_type_count[2].type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7049 ds_type_count[2].descriptorCount = 2;
7050 ds_type_count[3].type = VK_DESCRIPTOR_TYPE_SAMPLER;
7051 ds_type_count[3].descriptorCount = 5;
7052 // TODO : LunarG ILO driver currently asserts in desc.c w/ INPUT_ATTACHMENT
7053 // type
7054 // ds_type_count[4].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
7055 ds_type_count[4].type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
7056 ds_type_count[4].descriptorCount = 2;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007057
7058 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007059 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7060 ds_pool_ci.pNext = NULL;
7061 ds_pool_ci.maxSets = 5;
7062 ds_pool_ci.poolSizeCount = NUM_DESCRIPTOR_TYPES;
7063 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007064
7065 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007066 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007067 ASSERT_VK_SUCCESS(err);
7068
7069 static const uint32_t MAX_DS_TYPES_IN_LAYOUT = 2;
7070 VkDescriptorSetLayoutBinding dsl_binding[MAX_DS_TYPES_IN_LAYOUT] = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007071 dsl_binding[0].binding = 0;
7072 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7073 dsl_binding[0].descriptorCount = 5;
7074 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
7075 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007076
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007077 // Create layout identical to set0 layout but w/ different stageFlags
7078 VkDescriptorSetLayoutBinding dsl_fs_stage_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007079 dsl_fs_stage_only.binding = 0;
7080 dsl_fs_stage_only.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7081 dsl_fs_stage_only.descriptorCount = 5;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007082 dsl_fs_stage_only.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // Different stageFlags to cause error at
7083 // bind time
Karl Schultz6addd812016-02-02 17:17:23 -07007084 dsl_fs_stage_only.pImmutableSamplers = NULL;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007085 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007086 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7087 ds_layout_ci.pNext = NULL;
7088 ds_layout_ci.bindingCount = 1;
7089 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007090 static const uint32_t NUM_LAYOUTS = 4;
7091 VkDescriptorSetLayout ds_layout[NUM_LAYOUTS] = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007092 VkDescriptorSetLayout ds_layout_fs_only = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007093 // Create 4 unique layouts for full pipelineLayout, and 1 special fs-only
7094 // layout for error case
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007095 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[0]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007096 ASSERT_VK_SUCCESS(err);
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007097 ds_layout_ci.pBindings = &dsl_fs_stage_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007098 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007099 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007100 dsl_binding[0].binding = 0;
7101 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007102 dsl_binding[0].descriptorCount = 2;
Mike Stroyan9c70cdb2016-01-06 14:14:17 -07007103 dsl_binding[1].binding = 1;
7104 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
7105 dsl_binding[1].descriptorCount = 2;
7106 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
7107 dsl_binding[1].pImmutableSamplers = NULL;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007108 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007109 ds_layout_ci.bindingCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007110 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[1]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007111 ASSERT_VK_SUCCESS(err);
7112 dsl_binding[0].binding = 0;
7113 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007114 dsl_binding[0].descriptorCount = 5;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007115 ds_layout_ci.bindingCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007116 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[2]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007117 ASSERT_VK_SUCCESS(err);
7118 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007119 dsl_binding[0].descriptorCount = 2;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007120 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout[3]);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007121 ASSERT_VK_SUCCESS(err);
7122
7123 static const uint32_t NUM_SETS = 4;
7124 VkDescriptorSet descriptorSet[NUM_SETS] = {};
7125 VkDescriptorSetAllocateInfo alloc_info = {};
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007126 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007127 alloc_info.descriptorSetCount = NUM_LAYOUTS;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007128 alloc_info.descriptorPool = ds_pool;
7129 alloc_info.pSetLayouts = ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007130 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptorSet);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007131 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007132 VkDescriptorSet ds0_fs_only = {};
Jon Ashburnf19916e2016-01-11 13:12:43 -07007133 alloc_info.descriptorSetCount = 1;
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007134 alloc_info.pSetLayouts = &ds_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007135 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &ds0_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007136 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007137
7138 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007139 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7140 pipeline_layout_ci.pNext = NULL;
7141 pipeline_layout_ci.setLayoutCount = NUM_LAYOUTS;
7142 pipeline_layout_ci.pSetLayouts = ds_layout;
Tobin Ehlis559c6382015-11-05 09:52:49 -07007143
7144 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007145 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007146 ASSERT_VK_SUCCESS(err);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007147 // Create pipelineLayout with only one setLayout
7148 pipeline_layout_ci.setLayoutCount = 1;
7149 VkPipelineLayout single_pipe_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007150 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &single_pipe_layout);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007151 ASSERT_VK_SUCCESS(err);
7152 // Create pipelineLayout with 2 descriptor setLayout at index 0
7153 pipeline_layout_ci.pSetLayouts = &ds_layout[3];
7154 VkPipelineLayout pipe_layout_one_desc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007155 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_one_desc);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007156 ASSERT_VK_SUCCESS(err);
7157 // Create pipelineLayout with 5 SAMPLER descriptor setLayout at index 0
7158 pipeline_layout_ci.pSetLayouts = &ds_layout[2];
7159 VkPipelineLayout pipe_layout_five_samp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007160 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_five_samp);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007161 ASSERT_VK_SUCCESS(err);
7162 // Create pipelineLayout with UB type, but stageFlags for FS only
7163 pipeline_layout_ci.pSetLayouts = &ds_layout_fs_only;
7164 VkPipelineLayout pipe_layout_fs_only;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007165 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_fs_only);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007166 ASSERT_VK_SUCCESS(err);
7167 // Create pipelineLayout w/ incompatible set0 layout, but set1 is fine
7168 VkDescriptorSetLayout pl_bad_s0[2] = {};
7169 pl_bad_s0[0] = ds_layout_fs_only;
7170 pl_bad_s0[1] = ds_layout[1];
7171 pipeline_layout_ci.setLayoutCount = 2;
7172 pipeline_layout_ci.pSetLayouts = pl_bad_s0;
7173 VkPipelineLayout pipe_layout_bad_set0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007174 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipe_layout_bad_set0);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007175 ASSERT_VK_SUCCESS(err);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007176
Tobin Ehlis88452832015-12-03 09:40:56 -07007177 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007178 char const *vsSource =
7179 "#version 450\n"
7180 "\n"
7181 "out gl_PerVertex {\n"
7182 " vec4 gl_Position;\n"
7183 "};\n"
7184 "void main(){\n"
7185 " gl_Position = vec4(1);\n"
7186 "}\n";
7187 char const *fsSource =
7188 "#version 450\n"
7189 "\n"
7190 "layout(location=0) out vec4 x;\n"
7191 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
7192 "void main(){\n"
7193 " x = vec4(bar.y);\n"
7194 "}\n";
Tobin Ehlis88452832015-12-03 09:40:56 -07007195 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
7196 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007197 VkPipelineObj pipe(m_device);
7198 pipe.AddShader(&vs);
7199 pipe.AddShader(&fs);
Tobin Ehlis88452832015-12-03 09:40:56 -07007200 pipe.AddColorAttachment();
7201 pipe.CreateVKPipeline(pipe_layout_fs_only, renderPass());
Tobin Ehlis559c6382015-11-05 09:52:49 -07007202
Tony Barbour552f6c02016-12-21 14:34:07 -07007203 m_commandBuffer->BeginCommandBuffer();
7204 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis88452832015-12-03 09:40:56 -07007205
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007206 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Karl Schultz6addd812016-02-02 17:17:23 -07007207 // NOTE : I believe LunarG ilo driver has bug (LX#189) that requires binding
7208 // of PSO
7209 // here before binding DSs. Otherwise we assert in cmd_copy_dset_data() of
7210 // cmd_pipeline.c
7211 // due to the fact that cmd_alloc_dset_data() has not been called in
7212 // cmd_bind_graphics_pipeline()
7213 // TODO : Want to cause various binding incompatibility issues here to test
7214 // DrawState
Tobin Ehlis559c6382015-11-05 09:52:49 -07007215 // First cause various verify_layout_compatibility() fails
7216 // Second disturb early and late sets and verify INFO msgs
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007217 // verify_set_layout_compatibility fail cases:
7218 // 1. invalid VkPipelineLayout (layout) passed into vkCmdBindDescriptorSets
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007219 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00981);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007220 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS,
7221 (VkPipelineLayout)((size_t)0xbaadb1be), 0, 1, &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007222 m_errorMonitor->VerifyFound();
7223
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007224 // 2. layoutIndex exceeds # of layouts in layout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007225 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " attempting to bind set to index 1");
7226 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, single_pipe_layout, 0, 2,
7227 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007228 m_errorMonitor->VerifyFound();
7229
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007230 vkDestroyPipelineLayout(m_device->device(), single_pipe_layout, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007231 // 3. Pipeline setLayout[0] has 2 descriptors, but set being bound has 5
7232 // descriptors
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007233 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " has 2 descriptors, but DescriptorSetLayout ");
7234 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_one_desc, 0, 1,
7235 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007236 m_errorMonitor->VerifyFound();
7237
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007238 vkDestroyPipelineLayout(m_device->device(), pipe_layout_one_desc, NULL);
7239 // 4. same # of descriptors but mismatch in type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007240 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is type 'VK_DESCRIPTOR_TYPE_SAMPLER' but binding ");
7241 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_five_samp, 0, 1,
7242 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007243 m_errorMonitor->VerifyFound();
7244
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007245 vkDestroyPipelineLayout(m_device->device(), pipe_layout_five_samp, NULL);
7246 // 5. same # of descriptors but mismatch in stageFlags
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7248 " has stageFlags 16 but binding 0 for DescriptorSetLayout ");
7249 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7250 &descriptorSet[0], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007251 m_errorMonitor->VerifyFound();
7252
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007253 // Cause INFO messages due to disturbing previously bound Sets
7254 // First bind sets 0 & 1
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007255 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7256 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007257 // 1. Disturb bound set0 by re-binding set1 w/ updated pipelineLayout
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007258 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, " previously bound as set #0 was disturbed ");
7259 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7260 &descriptorSet[1], 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007261 m_errorMonitor->VerifyFound();
7262
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007263 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7264 &descriptorSet[0], 0, NULL);
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007265 // 2. Disturb set after last bound set
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007266 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
7267 " newly bound as set #0 so set #1 and "
7268 "any subsequent sets were disturbed ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007269 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_fs_only, 0, 1,
7270 &ds0_fs_only, 0, NULL);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007271 m_errorMonitor->VerifyFound();
7272
Tobin Ehlis10fad692016-07-07 12:00:36 -06007273 // Now that we're done actively using the pipelineLayout that gfx pipeline
7274 // was created with, we should be able to delete it. Do that now to verify
7275 // that validation obeys pipelineLayout lifetime
7276 vkDestroyPipelineLayout(m_device->device(), pipe_layout_fs_only, NULL);
7277
Tobin Ehlis88452832015-12-03 09:40:56 -07007278 // Cause draw-time errors due to PSO incompatibilities
Karl Schultz6addd812016-02-02 17:17:23 -07007279 // 1. Error due to not binding required set (we actually use same code as
7280 // above to disturb set0)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007281 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7282 &descriptorSet[0], 0, NULL);
7283 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe_layout_bad_set0, 1, 1,
7284 &descriptorSet[1], 0, NULL);
7285 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 -07007286
7287 VkViewport viewport = {0, 0, 16, 16, 0, 1};
7288 VkRect2D scissor = {{0, 0}, {16, 16}};
7289 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
7290 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
7291
Tobin Ehlis88452832015-12-03 09:40:56 -07007292 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007293 m_errorMonitor->VerifyFound();
7294
Tobin Ehlis991d45a2016-01-06 08:48:41 -07007295 vkDestroyPipelineLayout(m_device->device(), pipe_layout_bad_set0, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07007296 // 2. Error due to bound set not being compatible with PSO's
7297 // VkPipelineLayout (diff stageFlags in this case)
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007298 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 2,
7299 &descriptorSet[0], 0, NULL);
7300 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " bound as set #0 is not compatible with ");
Tobin Ehlis88452832015-12-03 09:40:56 -07007301 Draw(1, 0, 0, 0);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007302 m_errorMonitor->VerifyFound();
7303
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007304 // Remaining clean-up
Karl Schultz6addd812016-02-02 17:17:23 -07007305 for (uint32_t i = 0; i < NUM_LAYOUTS; ++i) {
Tobin Ehlis8fab6562015-12-01 09:57:09 -07007306 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout[i], NULL);
7307 }
7308 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout_fs_only, NULL);
Tobin Ehlis559c6382015-11-05 09:52:49 -07007309 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7310 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
7311}
Tobin Ehlis559c6382015-11-05 09:52:49 -07007312
Karl Schultz6addd812016-02-02 17:17:23 -07007313TEST_F(VkLayerTest, NoBeginCommandBuffer) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007314 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7315 "You must call vkBeginCommandBuffer() before this call to ");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007316
7317 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007318 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007319 // Call EndCommandBuffer() w/o calling BeginCommandBuffer()
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007320 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007321
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007322 m_errorMonitor->VerifyFound();
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007323}
7324
Karl Schultz6addd812016-02-02 17:17:23 -07007325TEST_F(VkLayerTest, SecondaryCommandBufferNullRenderpass) {
7326 VkResult err;
7327 VkCommandBuffer draw_cmd;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007328
Karl Schultzf78bcdd2016-11-30 12:36:01 -07007329 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007330
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007331 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007332
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007333 VkCommandBufferAllocateInfo cmd = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007334 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007335 cmd.pNext = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007336 cmd.commandPool = m_commandPool;
7337 cmd.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007338 cmd.commandBufferCount = 1;
Cody Northropb4569702015-08-04 17:35:57 -06007339
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007340 err = vkAllocateCommandBuffers(m_device->device(), &cmd, &draw_cmd);
Mike Stroyand1c84a52015-08-18 14:40:24 -06007341 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007342
7343 // Force the failure by not setting the Renderpass and Framebuffer fields
Jon Ashburnf19916e2016-01-11 13:12:43 -07007344 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Rene Lindsay65072a92017-01-23 11:38:10 -07007345 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7346
7347 VkCommandBufferBeginInfo cmd_buf_info = {};
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007348 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Cody Northropb4569702015-08-04 17:35:57 -06007349 cmd_buf_info.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007350 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 -07007351 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007352
7353 // The error should be caught by validation of the BeginCommandBuffer call
7354 vkBeginCommandBuffer(draw_cmd, &cmd_buf_info);
7355
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007356 m_errorMonitor->VerifyFound();
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007357 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &draw_cmd);
Mark Lobodzinskid9139a62015-08-04 16:24:20 -06007358}
7359
Karl Schultz6addd812016-02-02 17:17:23 -07007360TEST_F(VkLayerTest, CommandBufferResetErrors) {
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007361 // Cause error due to Begin while recording CB
7362 // Then cause 2 errors for attempting to reset CB w/o having
7363 // VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT set for the pool from
7364 // which CBs were allocated. Note that this bit is off by default.
Mike Weiblencce7ec72016-10-17 19:33:05 -06007365 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Cannot call Begin on command buffer");
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007366
7367 ASSERT_NO_FATAL_FAILURE(InitState());
7368
7369 // Calls AllocateCommandBuffers
7370 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
7371
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007372 // Force the failure by setting the Renderpass and Framebuffer fields with (fake) data
Jon Ashburnf19916e2016-01-11 13:12:43 -07007373 VkCommandBufferInheritanceInfo cmd_buf_hinfo = {};
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007374 cmd_buf_hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
7375 VkCommandBufferBeginInfo cmd_buf_info = {};
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007376 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
7377 cmd_buf_info.pNext = NULL;
7378 cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007379 cmd_buf_info.pInheritanceInfo = &cmd_buf_hinfo;
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007380
7381 // Begin CB to transition to recording state
7382 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
7383 // Can't re-begin. This should trigger error
7384 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007385 m_errorMonitor->VerifyFound();
7386
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007387 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00093);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007388 VkCommandBufferResetFlags flags = 0; // Don't care about flags for this test
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007389 // Reset attempt will trigger error due to incorrect CommandPool state
7390 vkResetCommandBuffer(commandBuffer.GetBufferHandle(), flags);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007391 m_errorMonitor->VerifyFound();
7392
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07007393 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00105);
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007394 // Transition CB to RECORDED state
7395 vkEndCommandBuffer(commandBuffer.GetBufferHandle());
7396 // Now attempting to Begin will implicitly reset, which triggers error
7397 vkBeginCommandBuffer(commandBuffer.GetBufferHandle(), &cmd_buf_info);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007398 m_errorMonitor->VerifyFound();
Tobin Ehlisac0ef842015-12-14 13:46:38 -07007399}
7400
Karl Schultz6addd812016-02-02 17:17:23 -07007401TEST_F(VkLayerTest, InvalidPipelineCreateState) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007402 // Attempt to Create Gfx Pipeline w/o a VS
Karl Schultz6addd812016-02-02 17:17:23 -07007403 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007404
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07007405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
7406 "Invalid Pipeline CreateInfo State: Vertex Shader required");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007407
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007408 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -06007409 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007410
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007411 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007412 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7413 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -06007414
7415 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007416 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7417 ds_pool_ci.pNext = NULL;
7418 ds_pool_ci.maxSets = 1;
7419 ds_pool_ci.poolSizeCount = 1;
7420 ds_pool_ci.pPoolSizes = &ds_type_count;
Mark Lobodzinski209b5292015-09-17 09:44:05 -06007421
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007422 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007423 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007424 ASSERT_VK_SUCCESS(err);
7425
Tony Barboureb254902015-07-15 12:50:33 -06007426 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007427 dsl_binding.binding = 0;
7428 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7429 dsl_binding.descriptorCount = 1;
7430 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7431 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007432
Tony Barboureb254902015-07-15 12:50:33 -06007433 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007434 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7435 ds_layout_ci.pNext = NULL;
7436 ds_layout_ci.bindingCount = 1;
7437 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -06007438
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007439 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007440 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007441 ASSERT_VK_SUCCESS(err);
7442
7443 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007444 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007445 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007446 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007447 alloc_info.descriptorPool = ds_pool;
7448 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007449 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007450 ASSERT_VK_SUCCESS(err);
7451
Tony Barboureb254902015-07-15 12:50:33 -06007452 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007453 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7454 pipeline_layout_ci.setLayoutCount = 1;
7455 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007456
7457 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007458 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007459 ASSERT_VK_SUCCESS(err);
7460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07007461 VkViewport vp = {}; // Just need dummy vp to point to
7462 VkRect2D sc = {}; // dummy scissor to point to
Tobin Ehlise68360f2015-10-01 11:15:13 -06007463
7464 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007465 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
7466 vp_state_ci.scissorCount = 1;
7467 vp_state_ci.pScissors = &sc;
7468 vp_state_ci.viewportCount = 1;
7469 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007470
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007471 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7472 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7473 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7474 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7475 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7476 rs_state_ci.depthClampEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007477 rs_state_ci.rasterizerDiscardEnable = VK_TRUE;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007478 rs_state_ci.depthBiasEnable = VK_FALSE;
Rene Lindsayae4977b2017-01-23 14:55:54 -07007479 rs_state_ci.lineWidth = 1.0f;
7480
7481 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7482 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7483 vi_ci.pNext = nullptr;
7484 vi_ci.vertexBindingDescriptionCount = 0;
7485 vi_ci.pVertexBindingDescriptions = nullptr;
7486 vi_ci.vertexAttributeDescriptionCount = 0;
7487 vi_ci.pVertexAttributeDescriptions = nullptr;
7488
7489 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7490 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7491 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7492
7493 VkPipelineShaderStageCreateInfo shaderStages[2];
7494 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
7495
7496 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
7497 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Dave Houlton59a20702017-02-02 17:26:23 -07007498 shaderStages[0] = fs.GetStageCreateInfo(); // should be: vs.GetStageCreateInfo();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007499 shaderStages[1] = fs.GetStageCreateInfo();
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007500
Tony Barboureb254902015-07-15 12:50:33 -06007501 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007502 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7503 gp_ci.pViewportState = &vp_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007504 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007505 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7506 gp_ci.layout = pipeline_layout;
7507 gp_ci.renderPass = renderPass();
Rene Lindsayae4977b2017-01-23 14:55:54 -07007508 gp_ci.pVertexInputState = &vi_ci;
7509 gp_ci.pInputAssemblyState = &ia_ci;
7510
7511 gp_ci.stageCount = 1;
7512 gp_ci.pStages = shaderStages;
Tony Barboureb254902015-07-15 12:50:33 -06007513
7514 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007515 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7516 pc_ci.initialDataSize = 0;
7517 pc_ci.pInitialData = 0;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007518
7519 VkPipeline pipeline;
Jon Ashburnc669cc62015-07-09 15:02:25 -06007520 VkPipelineCache pipelineCache;
7521
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007522 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Jon Ashburnc669cc62015-07-09 15:02:25 -06007523 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007524 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007525 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007526
Chia-I Wuf7458c52015-10-26 21:10:41 +08007527 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7528 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7529 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7530 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007531}
Rene Lindsayae4977b2017-01-23 14:55:54 -07007532
Tobin Ehlis912df022015-09-17 08:46:18 -06007533/*// TODO : This test should be good, but needs Tess support in compiler to run
7534TEST_F(VkLayerTest, InvalidPatchControlPoints)
7535{
7536 // Attempt to Create Gfx Pipeline w/o a VS
Tobin Ehlis912df022015-09-17 08:46:18 -06007537 VkResult err;
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06007538
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -07007539 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Karl Schultz6addd812016-02-02 17:17:23 -07007540 "Invalid Pipeline CreateInfo State: VK_PRIMITIVE_TOPOLOGY_PATCH
7541primitive ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007542
Tobin Ehlis912df022015-09-17 08:46:18 -06007543 ASSERT_NO_FATAL_FAILURE(InitState());
7544 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis912df022015-09-17 08:46:18 -06007545
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007546 VkDescriptorPoolSize ds_type_count = {};
Tobin Ehlis912df022015-09-17 08:46:18 -06007547 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007548 ds_type_count.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007549
7550 VkDescriptorPoolCreateInfo ds_pool_ci = {};
7551 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7552 ds_pool_ci.pNext = NULL;
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007553 ds_pool_ci.poolSizeCount = 1;
7554 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlis912df022015-09-17 08:46:18 -06007555
7556 VkDescriptorPool ds_pool;
Karl Schultz6addd812016-02-02 17:17:23 -07007557 err = vkCreateDescriptorPool(m_device->device(),
7558VK_DESCRIPTOR_POOL_USAGE_NON_FREE, 1, &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis912df022015-09-17 08:46:18 -06007559 ASSERT_VK_SUCCESS(err);
7560
7561 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +08007562 dsl_binding.binding = 0;
Tobin Ehlis912df022015-09-17 08:46:18 -06007563 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +08007564 dsl_binding.descriptorCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007565 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
7566 dsl_binding.pImmutableSamplers = NULL;
7567
7568 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007569 ds_layout_ci.sType =
7570VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007571 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007572 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -07007573 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis912df022015-09-17 08:46:18 -06007574
7575 VkDescriptorSetLayout ds_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007576 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL,
7577&ds_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007578 ASSERT_VK_SUCCESS(err);
7579
7580 VkDescriptorSet descriptorSet;
Karl Schultz6addd812016-02-02 17:17:23 -07007581 err = vkAllocateDescriptorSets(m_device->device(), ds_pool,
7582VK_DESCRIPTOR_SET_USAGE_NON_FREE, 1, &ds_layout, &descriptorSet);
Tobin Ehlis912df022015-09-17 08:46:18 -06007583 ASSERT_VK_SUCCESS(err);
7584
7585 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007586 pipeline_layout_ci.sType =
7587VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Tobin Ehlis912df022015-09-17 08:46:18 -06007588 pipeline_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +08007589 pipeline_layout_ci.setLayoutCount = 1;
Tobin Ehlis912df022015-09-17 08:46:18 -06007590 pipeline_layout_ci.pSetLayouts = &ds_layout;
7591
7592 VkPipelineLayout pipeline_layout;
Karl Schultz6addd812016-02-02 17:17:23 -07007593 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL,
7594&pipeline_layout);
Tobin Ehlis912df022015-09-17 08:46:18 -06007595 ASSERT_VK_SUCCESS(err);
7596
7597 VkPipelineShaderStageCreateInfo shaderStages[3];
7598 memset(&shaderStages, 0, 3 * sizeof(VkPipelineShaderStageCreateInfo));
7599
Karl Schultz6addd812016-02-02 17:17:23 -07007600 VkShaderObj vs(m_device,bindStateVertShaderText,VK_SHADER_STAGE_VERTEX_BIT,
7601this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007602 // Just using VS txt for Tess shaders as we don't care about functionality
Karl Schultz6addd812016-02-02 17:17:23 -07007603 VkShaderObj
7604tc(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT,
7605this);
7606 VkShaderObj
7607te(m_device,bindStateVertShaderText,VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT,
7608this);
Tobin Ehlis912df022015-09-17 08:46:18 -06007609
Karl Schultz6addd812016-02-02 17:17:23 -07007610 shaderStages[0].sType =
7611VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007612 shaderStages[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007613 shaderStages[0].shader = vs.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007614 shaderStages[1].sType =
7615VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007616 shaderStages[1].stage = VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007617 shaderStages[1].shader = tc.handle();
Karl Schultz6addd812016-02-02 17:17:23 -07007618 shaderStages[2].sType =
7619VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -06007620 shaderStages[2].stage = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
Tobin Ehlis912df022015-09-17 08:46:18 -06007621 shaderStages[2].shader = te.handle();
7622
7623 VkPipelineInputAssemblyStateCreateInfo iaCI = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007624 iaCI.sType =
7625VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
Chia-I Wu515eb8f2015-10-31 00:31:16 +08007626 iaCI.topology = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST;
Tobin Ehlis912df022015-09-17 08:46:18 -06007627
7628 VkPipelineTessellationStateCreateInfo tsCI = {};
7629 tsCI.sType = VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO;
7630 tsCI.patchControlPoints = 0; // This will cause an error
7631
7632 VkGraphicsPipelineCreateInfo gp_ci = {};
7633 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7634 gp_ci.pNext = NULL;
7635 gp_ci.stageCount = 3;
7636 gp_ci.pStages = shaderStages;
7637 gp_ci.pVertexInputState = NULL;
7638 gp_ci.pInputAssemblyState = &iaCI;
7639 gp_ci.pTessellationState = &tsCI;
7640 gp_ci.pViewportState = NULL;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007641 gp_ci.pRasterizationState = NULL;
Tobin Ehlis912df022015-09-17 08:46:18 -06007642 gp_ci.pMultisampleState = NULL;
7643 gp_ci.pDepthStencilState = NULL;
7644 gp_ci.pColorBlendState = NULL;
7645 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7646 gp_ci.layout = pipeline_layout;
7647 gp_ci.renderPass = renderPass();
7648
7649 VkPipelineCacheCreateInfo pc_ci = {};
7650 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
7651 pc_ci.pNext = NULL;
7652 pc_ci.initialSize = 0;
7653 pc_ci.initialData = 0;
7654 pc_ci.maxSize = 0;
7655
7656 VkPipeline pipeline;
7657 VkPipelineCache pipelineCache;
7658
Karl Schultz6addd812016-02-02 17:17:23 -07007659 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL,
7660&pipelineCache);
Tobin Ehlis912df022015-09-17 08:46:18 -06007661 ASSERT_VK_SUCCESS(err);
Karl Schultz6addd812016-02-02 17:17:23 -07007662 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1,
7663&gp_ci, NULL, &pipeline);
Tobin Ehlis912df022015-09-17 08:46:18 -06007664
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007665 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06007666
Chia-I Wuf7458c52015-10-26 21:10:41 +08007667 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7668 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7669 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7670 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis912df022015-09-17 08:46:18 -06007671}
7672*/
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007673
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007674TEST_F(VkLayerTest, PSOViewportScissorCountTests) {
Karl Schultz6addd812016-02-02 17:17:23 -07007675 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007676
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007677 TEST_DESCRIPTION("Test various cases of viewport and scissor count validation");
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007678
Tobin Ehlise68360f2015-10-01 11:15:13 -06007679 ASSERT_NO_FATAL_FAILURE(InitState());
7680 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007681
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007682 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007683 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7684 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007685
7686 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007687 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7688 ds_pool_ci.maxSets = 1;
7689 ds_pool_ci.poolSizeCount = 1;
7690 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007691
7692 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007693 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007694 ASSERT_VK_SUCCESS(err);
7695
7696 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007697 dsl_binding.binding = 0;
7698 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7699 dsl_binding.descriptorCount = 1;
7700 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007701
7702 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007703 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7704 ds_layout_ci.bindingCount = 1;
7705 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007706
7707 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007708 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007709 ASSERT_VK_SUCCESS(err);
7710
7711 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007712 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007713 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007714 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007715 alloc_info.descriptorPool = ds_pool;
7716 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007717 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007718 ASSERT_VK_SUCCESS(err);
7719
7720 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007721 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7722 pipeline_layout_ci.setLayoutCount = 1;
7723 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007724
7725 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007726 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007727 ASSERT_VK_SUCCESS(err);
7728
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007729 VkViewport vp = {};
Tobin Ehlise68360f2015-10-01 11:15:13 -06007730 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007731 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
Mark Lobodzinski510aa5c2016-12-19 07:59:10 -07007732 vp_state_ci.scissorCount = 1;
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007733 vp_state_ci.viewportCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -07007734 vp_state_ci.pViewports = &vp;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007735
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007736 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7737 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7738 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7739 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7740 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7741 rs_state_ci.depthClampEnable = VK_FALSE;
7742 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7743 rs_state_ci.depthBiasEnable = VK_FALSE;
7744
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007745 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7746 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7747 vi_ci.pNext = nullptr;
7748 vi_ci.vertexBindingDescriptionCount = 0;
7749 vi_ci.pVertexBindingDescriptions = nullptr;
7750 vi_ci.vertexAttributeDescriptionCount = 0;
7751 vi_ci.pVertexAttributeDescriptions = nullptr;
7752
7753 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7754 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7755 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7756
7757 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7758 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7759 pipe_ms_state_ci.pNext = NULL;
7760 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
7761 pipe_ms_state_ci.sampleShadingEnable = 0;
7762 pipe_ms_state_ci.minSampleShading = 1.0;
7763 pipe_ms_state_ci.pSampleMask = NULL;
7764
Cody Northropeb3a6c12015-10-05 14:44:45 -06007765 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007766 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007767
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007768 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007769 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chia-I Wu28e06912015-10-31 00:31:16 +08007770 shaderStages[0] = vs.GetStageCreateInfo();
7771 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007772
7773 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007774 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7775 gp_ci.stageCount = 2;
7776 gp_ci.pStages = shaderStages;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007777 gp_ci.pVertexInputState = &vi_ci;
7778 gp_ci.pInputAssemblyState = &ia_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007779 gp_ci.pViewportState = &vp_state_ci;
Mark Lobodzinski61dddf92016-12-16 14:54:59 -07007780 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007781 gp_ci.pRasterizationState = &rs_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007782 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7783 gp_ci.layout = pipeline_layout;
7784 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007785
7786 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007787 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007788
7789 VkPipeline pipeline;
7790 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007791 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007792 ASSERT_VK_SUCCESS(err);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007793
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007794 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007795 printf(" MultiViewport feature is disabled -- skipping enabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007796
7797 // Check case where multiViewport is disabled and viewport count is not 1
7798 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7799 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01430);
7800 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01431);
7801 vp_state_ci.scissorCount = 0;
7802 vp_state_ci.viewportCount = 0;
7803 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7804 m_errorMonitor->VerifyFound();
7805 } else {
7806 if (m_device->props.limits.maxViewports == 1) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007807 printf(" Device limit maxViewports is 1, skipping tests that require higher limits.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007808 } else {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007809 printf(" MultiViewport feature is enabled -- skipping disabled-state checks.\n");
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007810
7811 // Check is that viewportcount and scissorcount match
7812 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01434);
7813 vp_state_ci.scissorCount = 1;
7814 vp_state_ci.viewportCount = m_device->props.limits.maxViewports;
7815 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7816 m_errorMonitor->VerifyFound();
7817
Mark Lobodzinskif0eab4a2016-12-19 08:43:21 -07007818 // Check case where multiViewport is enabled and viewport count is greater than max
7819 // We check scissor/viewport simultaneously since separating them would trigger the mismatch error, 1434.
7820 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01432);
7821 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01433);
7822 vp_state_ci.scissorCount = m_device->props.limits.maxViewports + 1;
7823 vp_state_ci.viewportCount = m_device->props.limits.maxViewports + 1;
7824 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
7825 m_errorMonitor->VerifyFound();
7826 }
7827 }
Tobin Ehlise68360f2015-10-01 11:15:13 -06007828
Chia-I Wuf7458c52015-10-26 21:10:41 +08007829 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7830 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7831 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7832 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007833}
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007834
7835// 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
7836// set dynamically.
Karl Schultz6addd812016-02-02 17:17:23 -07007837TEST_F(VkLayerTest, PSOViewportStateNotSet) {
Karl Schultz6addd812016-02-02 17:17:23 -07007838 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007839
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007840 TEST_DESCRIPTION("Create a graphics pipeline with rasterization enabled but no viewport state.");
7841
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02113);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007843
Tobin Ehlise68360f2015-10-01 11:15:13 -06007844 ASSERT_NO_FATAL_FAILURE(InitState());
7845 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007846
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007847 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007848 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7849 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007850
7851 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007852 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7853 ds_pool_ci.maxSets = 1;
7854 ds_pool_ci.poolSizeCount = 1;
7855 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007856
7857 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007858 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007859 ASSERT_VK_SUCCESS(err);
7860
7861 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007862 dsl_binding.binding = 0;
7863 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7864 dsl_binding.descriptorCount = 1;
7865 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007866
7867 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007868 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
7869 ds_layout_ci.bindingCount = 1;
7870 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007871
7872 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007873 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007874 ASSERT_VK_SUCCESS(err);
7875
7876 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08007877 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08007878 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07007879 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06007880 alloc_info.descriptorPool = ds_pool;
7881 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007882 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007883 ASSERT_VK_SUCCESS(err);
7884
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007885 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
7886 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
7887 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
7888
7889 VkPipelineVertexInputStateCreateInfo vi_ci = {};
7890 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
7891 vi_ci.pNext = nullptr;
7892 vi_ci.vertexBindingDescriptionCount = 0;
7893 vi_ci.pVertexBindingDescriptions = nullptr;
7894 vi_ci.vertexAttributeDescriptionCount = 0;
7895 vi_ci.pVertexAttributeDescriptions = nullptr;
7896
7897 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
7898 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
7899 pipe_ms_state_ci.pNext = NULL;
7900 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
7901 pipe_ms_state_ci.sampleShadingEnable = 0;
7902 pipe_ms_state_ci.minSampleShading = 1.0;
7903 pipe_ms_state_ci.pSampleMask = NULL;
7904
Tobin Ehlise68360f2015-10-01 11:15:13 -06007905 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007906 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
7907 pipeline_layout_ci.setLayoutCount = 1;
7908 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007909
7910 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007911 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007912 ASSERT_VK_SUCCESS(err);
7913
7914 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
7915 // Set scissor as dynamic to avoid second error
7916 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007917 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
7918 dyn_state_ci.dynamicStateCount = 1;
7919 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007920
Cody Northropeb3a6c12015-10-05 14:44:45 -06007921 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07007922 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06007923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007924 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007925 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
7926 // 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 +08007927 shaderStages[0] = vs.GetStageCreateInfo();
7928 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007929
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007930 VkPipelineRasterizationStateCreateInfo rs_state_ci = {};
7931 rs_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
7932 rs_state_ci.polygonMode = VK_POLYGON_MODE_FILL;
7933 rs_state_ci.cullMode = VK_CULL_MODE_BACK_BIT;
7934 rs_state_ci.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
7935 rs_state_ci.depthClampEnable = VK_FALSE;
7936 rs_state_ci.rasterizerDiscardEnable = VK_FALSE;
7937 rs_state_ci.depthBiasEnable = VK_FALSE;
7938
Tobin Ehlise68360f2015-10-01 11:15:13 -06007939 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007940 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
7941 gp_ci.stageCount = 2;
7942 gp_ci.pStages = shaderStages;
Karl Schultzdfdb8d42016-03-08 10:30:21 -07007943 gp_ci.pRasterizationState = &rs_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007944 // Not setting VP state w/o dynamic vp state should cause validation error
7945 gp_ci.pViewportState = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -07007946 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski9d5eda22016-12-16 14:30:01 -07007947 gp_ci.pVertexInputState = &vi_ci;
7948 gp_ci.pInputAssemblyState = &ia_ci;
7949 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07007950 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
7951 gp_ci.layout = pipeline_layout;
7952 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007953
7954 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007955 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007956
7957 VkPipeline pipeline;
7958 VkPipelineCache pipelineCache;
7959
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007960 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007961 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007962 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007963
Chris Forbes8f36a8a2016-04-07 13:21:07 +12007964 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06007965
Chia-I Wuf7458c52015-10-26 21:10:41 +08007966 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
7967 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
7968 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
7969 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06007970}
Mark Lobodzinski73169e22016-12-16 14:01:17 -07007971
7972// Create PSO w/o non-zero viewportCount but no viewport data, then run second test where dynamic scissor count doesn't match PSO
7973// scissor count
Karl Schultz6addd812016-02-02 17:17:23 -07007974TEST_F(VkLayerTest, PSOViewportCountWithoutDataAndDynScissorMismatch) {
7975 VkResult err;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007976
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07007977 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02110);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06007978
Tobin Ehlise68360f2015-10-01 11:15:13 -06007979 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007980
7981 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07007982 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12007983 return;
7984 }
7985
Tobin Ehlise68360f2015-10-01 11:15:13 -06007986 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlise68360f2015-10-01 11:15:13 -06007987
Chia-I Wu1b99bb22015-10-27 19:25:11 +08007988 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007989 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
7990 ds_type_count.descriptorCount = 1;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007991
7992 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07007993 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
7994 ds_pool_ci.maxSets = 1;
7995 ds_pool_ci.poolSizeCount = 1;
7996 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlise68360f2015-10-01 11:15:13 -06007997
7998 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06007999 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008000 ASSERT_VK_SUCCESS(err);
8001
8002 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008003 dsl_binding.binding = 0;
8004 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8005 dsl_binding.descriptorCount = 1;
8006 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008007
8008 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008009 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8010 ds_layout_ci.bindingCount = 1;
8011 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008012
8013 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008014 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008015 ASSERT_VK_SUCCESS(err);
8016
8017 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008018 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +08008019 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -07008020 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -06008021 alloc_info.descriptorPool = ds_pool;
8022 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008023 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008024 ASSERT_VK_SUCCESS(err);
8025
8026 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008027 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8028 pipeline_layout_ci.setLayoutCount = 1;
8029 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008030
8031 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008032 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008033 ASSERT_VK_SUCCESS(err);
8034
8035 VkPipelineViewportStateCreateInfo vp_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008036 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8037 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008038 vp_state_ci.pViewports = NULL; // Null vp w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008039 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008040 vp_state_ci.pScissors = NULL; // Scissor is dynamic (below) so this won't cause error
Tobin Ehlise68360f2015-10-01 11:15:13 -06008041
8042 VkDynamicState sc_state = VK_DYNAMIC_STATE_SCISSOR;
8043 // Set scissor as dynamic to avoid that error
8044 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008045 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8046 dyn_state_ci.dynamicStateCount = 1;
8047 dyn_state_ci.pDynamicStates = &sc_state;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008048
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008049 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8050 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8051 pipe_ms_state_ci.pNext = NULL;
8052 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8053 pipe_ms_state_ci.sampleShadingEnable = 0;
8054 pipe_ms_state_ci.minSampleShading = 1.0;
8055 pipe_ms_state_ci.pSampleMask = NULL;
8056
Cody Northropeb3a6c12015-10-05 14:44:45 -06008057 VkPipelineShaderStageCreateInfo shaderStages[2];
Karl Schultz6addd812016-02-02 17:17:23 -07008058 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
Tobin Ehlise68360f2015-10-01 11:15:13 -06008059
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008060 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008061 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8062 // 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 +08008063 shaderStages[0] = vs.GetStageCreateInfo();
8064 shaderStages[1] = fs.GetStageCreateInfo();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008065
Cody Northropf6622dc2015-10-06 10:33:21 -06008066 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8067 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8068 vi_ci.pNext = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008069 vi_ci.vertexBindingDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008070 vi_ci.pVertexBindingDescriptions = nullptr;
Chia-I Wud50a7d72015-10-26 20:48:51 +08008071 vi_ci.vertexAttributeDescriptionCount = 0;
Cody Northropf6622dc2015-10-06 10:33:21 -06008072 vi_ci.pVertexAttributeDescriptions = nullptr;
8073
8074 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8075 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8076 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8077
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008078 VkPipelineRasterizationStateCreateInfo rs_ci = {};
Chia-I Wu1b99bb22015-10-27 19:25:11 +08008079 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008080 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Cody Northropf6622dc2015-10-06 10:33:21 -06008081 rs_ci.pNext = nullptr;
8082
Mark Youngc89c6312016-03-31 16:03:20 -06008083 VkPipelineColorBlendAttachmentState att = {};
8084 att.blendEnable = VK_FALSE;
8085 att.colorWriteMask = 0xf;
8086
Cody Northropf6622dc2015-10-06 10:33:21 -06008087 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8088 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8089 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008090 cb_ci.attachmentCount = 1;
8091 cb_ci.pAttachments = &att;
Cody Northropf6622dc2015-10-06 10:33:21 -06008092
Tobin Ehlise68360f2015-10-01 11:15:13 -06008093 VkGraphicsPipelineCreateInfo gp_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008094 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8095 gp_ci.stageCount = 2;
8096 gp_ci.pStages = shaderStages;
8097 gp_ci.pVertexInputState = &vi_ci;
8098 gp_ci.pInputAssemblyState = &ia_ci;
8099 gp_ci.pViewportState = &vp_state_ci;
8100 gp_ci.pRasterizationState = &rs_ci;
8101 gp_ci.pColorBlendState = &cb_ci;
8102 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski73169e22016-12-16 14:01:17 -07008103 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008104 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8105 gp_ci.layout = pipeline_layout;
8106 gp_ci.renderPass = renderPass();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008107
8108 VkPipelineCacheCreateInfo pc_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -07008109 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
Tobin Ehlise68360f2015-10-01 11:15:13 -06008110
8111 VkPipeline pipeline;
8112 VkPipelineCache pipelineCache;
8113
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008114 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008115 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008116 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008117
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008118 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008119
Tobin Ehlisd332f282015-10-02 11:00:56 -06008120 // Now hit second fail case where we set scissor w/ different count than PSO
Karl Schultz6addd812016-02-02 17:17:23 -07008121 // First need to successfully create the PSO from above by setting
8122 // pViewports
Mike Weiblen95dd0f92016-10-19 12:28:27 -06008123 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 -07008124
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008125 VkViewport vp = {}; // Just need dummy vp to point to
Karl Schultz6addd812016-02-02 17:17:23 -07008126 vp_state_ci.pViewports = &vp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008127 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008128 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008129 m_commandBuffer->BeginCommandBuffer();
8130 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008131 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008132 VkRect2D scissors[1] = {}; // don't care about data
Karl Schultz6addd812016-02-02 17:17:23 -07008133 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008134 vkCmdSetScissor(m_commandBuffer->GetBufferHandle(), 1, 1, scissors);
Karl Schultz6addd812016-02-02 17:17:23 -07008135 Draw(1, 0, 0, 0);
8136
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008137 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008138
8139 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8140 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8141 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8142 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008143 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Karl Schultz6addd812016-02-02 17:17:23 -07008144}
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008145
8146// 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 -07008147// viewportCount
8148TEST_F(VkLayerTest, PSOScissorCountWithoutDataAndDynViewportMismatch) {
8149 VkResult err;
8150
Mark Lobodzinskid04c7862016-12-16 13:17:49 -07008151 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02111);
Karl Schultz6addd812016-02-02 17:17:23 -07008152
8153 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008154
8155 if (!m_device->phy().features().multiViewport) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07008156 printf(" Device does not support multiple viewports/scissors; skipped.\n");
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008157 return;
8158 }
8159
Karl Schultz6addd812016-02-02 17:17:23 -07008160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8161
8162 VkDescriptorPoolSize ds_type_count = {};
8163 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8164 ds_type_count.descriptorCount = 1;
8165
8166 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8167 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8168 ds_pool_ci.maxSets = 1;
8169 ds_pool_ci.poolSizeCount = 1;
8170 ds_pool_ci.pPoolSizes = &ds_type_count;
8171
8172 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008173 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Karl Schultz6addd812016-02-02 17:17:23 -07008174 ASSERT_VK_SUCCESS(err);
8175
8176 VkDescriptorSetLayoutBinding dsl_binding = {};
8177 dsl_binding.binding = 0;
8178 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8179 dsl_binding.descriptorCount = 1;
8180 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8181
8182 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8183 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8184 ds_layout_ci.bindingCount = 1;
8185 ds_layout_ci.pBindings = &dsl_binding;
8186
8187 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008188 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008189 ASSERT_VK_SUCCESS(err);
8190
8191 VkDescriptorSet descriptorSet;
8192 VkDescriptorSetAllocateInfo alloc_info = {};
8193 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8194 alloc_info.descriptorSetCount = 1;
8195 alloc_info.descriptorPool = ds_pool;
8196 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008197 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Karl Schultz6addd812016-02-02 17:17:23 -07008198 ASSERT_VK_SUCCESS(err);
8199
8200 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8201 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8202 pipeline_layout_ci.setLayoutCount = 1;
8203 pipeline_layout_ci.pSetLayouts = &ds_layout;
8204
8205 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008206 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Karl Schultz6addd812016-02-02 17:17:23 -07008207 ASSERT_VK_SUCCESS(err);
8208
8209 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8210 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8211 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008212 vp_state_ci.pScissors = NULL; // Null scissor w/ count of 1 should cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008213 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008214 vp_state_ci.pViewports = NULL; // vp is dynamic (below) so this won't cause error
Karl Schultz6addd812016-02-02 17:17:23 -07008215
8216 VkDynamicState vp_state = VK_DYNAMIC_STATE_VIEWPORT;
8217 // Set scissor as dynamic to avoid that error
8218 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8219 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8220 dyn_state_ci.dynamicStateCount = 1;
8221 dyn_state_ci.pDynamicStates = &vp_state;
8222
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008223 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
8224 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
8225 pipe_ms_state_ci.pNext = NULL;
8226 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
8227 pipe_ms_state_ci.sampleShadingEnable = 0;
8228 pipe_ms_state_ci.minSampleShading = 1.0;
8229 pipe_ms_state_ci.pSampleMask = NULL;
8230
Karl Schultz6addd812016-02-02 17:17:23 -07008231 VkPipelineShaderStageCreateInfo shaderStages[2];
8232 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8233
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008234 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008235 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
8236 // 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 -07008237 shaderStages[0] = vs.GetStageCreateInfo();
8238 shaderStages[1] = fs.GetStageCreateInfo();
8239
8240 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8241 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8242 vi_ci.pNext = nullptr;
8243 vi_ci.vertexBindingDescriptionCount = 0;
8244 vi_ci.pVertexBindingDescriptions = nullptr;
8245 vi_ci.vertexAttributeDescriptionCount = 0;
8246 vi_ci.pVertexAttributeDescriptions = nullptr;
8247
8248 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8249 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8250 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8251
8252 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8253 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008254 rs_ci.lineWidth = m_device->props.limits.lineWidthRange[0];
Karl Schultz6addd812016-02-02 17:17:23 -07008255 rs_ci.pNext = nullptr;
8256
Mark Youngc89c6312016-03-31 16:03:20 -06008257 VkPipelineColorBlendAttachmentState att = {};
8258 att.blendEnable = VK_FALSE;
8259 att.colorWriteMask = 0xf;
8260
Karl Schultz6addd812016-02-02 17:17:23 -07008261 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8262 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8263 cb_ci.pNext = nullptr;
Mark Youngc89c6312016-03-31 16:03:20 -06008264 cb_ci.attachmentCount = 1;
8265 cb_ci.pAttachments = &att;
Karl Schultz6addd812016-02-02 17:17:23 -07008266
8267 VkGraphicsPipelineCreateInfo gp_ci = {};
8268 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8269 gp_ci.stageCount = 2;
8270 gp_ci.pStages = shaderStages;
8271 gp_ci.pVertexInputState = &vi_ci;
8272 gp_ci.pInputAssemblyState = &ia_ci;
8273 gp_ci.pViewportState = &vp_state_ci;
8274 gp_ci.pRasterizationState = &rs_ci;
8275 gp_ci.pColorBlendState = &cb_ci;
8276 gp_ci.pDynamicState = &dyn_state_ci;
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008277 gp_ci.pMultisampleState = &pipe_ms_state_ci;
Karl Schultz6addd812016-02-02 17:17:23 -07008278 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8279 gp_ci.layout = pipeline_layout;
8280 gp_ci.renderPass = renderPass();
8281
8282 VkPipelineCacheCreateInfo pc_ci = {};
8283 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8284
8285 VkPipeline pipeline;
8286 VkPipelineCache pipelineCache;
8287
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008288 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Karl Schultz6addd812016-02-02 17:17:23 -07008289 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008290 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Karl Schultz6addd812016-02-02 17:17:23 -07008291
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008292 m_errorMonitor->VerifyFound();
Karl Schultz6addd812016-02-02 17:17:23 -07008293
8294 // Now hit second fail case where we set scissor w/ different count than PSO
8295 // First need to successfully create the PSO from above by setting
8296 // pViewports
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008297 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8298 "Dynamic viewport(s) 0 are used by pipeline state object, ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008299
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008300 VkRect2D sc = {}; // Just need dummy vp to point to
Tobin Ehlisd332f282015-10-02 11:00:56 -06008301 vp_state_ci.pScissors = &sc;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008302 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008303 ASSERT_VK_SUCCESS(err);
Tony Barbour552f6c02016-12-21 14:34:07 -07008304 m_commandBuffer->BeginCommandBuffer();
8305 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008306 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Lobodzinski96647ab2016-12-16 14:21:04 -07008307 VkViewport viewports[1] = {};
8308 viewports[0].width = 8;
8309 viewports[0].height = 8;
Tobin Ehlisd332f282015-10-02 11:00:56 -06008310 // Count of 2 doesn't match PSO count of 1
Chris Forbesc08a6ca2016-07-28 14:14:07 +12008311 vkCmdSetViewport(m_commandBuffer->GetBufferHandle(), 1, 1, viewports);
Tobin Ehlisd332f282015-10-02 11:00:56 -06008312 Draw(1, 0, 0, 0);
8313
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008314 m_errorMonitor->VerifyFound();
Tobin Ehlise68360f2015-10-01 11:15:13 -06008315
Chia-I Wuf7458c52015-10-26 21:10:41 +08008316 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8317 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8318 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8319 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008320 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Tobin Ehlise68360f2015-10-01 11:15:13 -06008321}
8322
Mark Young7394fdd2016-03-31 14:56:43 -06008323TEST_F(VkLayerTest, PSOLineWidthInvalid) {
8324 VkResult err;
8325
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008326 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008327
8328 ASSERT_NO_FATAL_FAILURE(InitState());
8329 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8330
8331 VkDescriptorPoolSize ds_type_count = {};
8332 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8333 ds_type_count.descriptorCount = 1;
8334
8335 VkDescriptorPoolCreateInfo ds_pool_ci = {};
8336 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
8337 ds_pool_ci.maxSets = 1;
8338 ds_pool_ci.poolSizeCount = 1;
8339 ds_pool_ci.pPoolSizes = &ds_type_count;
8340
8341 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008342 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Young7394fdd2016-03-31 14:56:43 -06008343 ASSERT_VK_SUCCESS(err);
8344
8345 VkDescriptorSetLayoutBinding dsl_binding = {};
8346 dsl_binding.binding = 0;
8347 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
8348 dsl_binding.descriptorCount = 1;
8349 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
8350
8351 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
8352 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
8353 ds_layout_ci.bindingCount = 1;
8354 ds_layout_ci.pBindings = &dsl_binding;
8355
8356 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008357 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008358 ASSERT_VK_SUCCESS(err);
8359
8360 VkDescriptorSet descriptorSet;
8361 VkDescriptorSetAllocateInfo alloc_info = {};
8362 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
8363 alloc_info.descriptorSetCount = 1;
8364 alloc_info.descriptorPool = ds_pool;
8365 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008366 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Young7394fdd2016-03-31 14:56:43 -06008367 ASSERT_VK_SUCCESS(err);
8368
8369 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
8370 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
8371 pipeline_layout_ci.setLayoutCount = 1;
8372 pipeline_layout_ci.pSetLayouts = &ds_layout;
8373
8374 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008375 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Young7394fdd2016-03-31 14:56:43 -06008376 ASSERT_VK_SUCCESS(err);
8377
8378 VkPipelineViewportStateCreateInfo vp_state_ci = {};
8379 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
8380 vp_state_ci.scissorCount = 1;
8381 vp_state_ci.pScissors = NULL;
8382 vp_state_ci.viewportCount = 1;
8383 vp_state_ci.pViewports = NULL;
8384
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008385 VkDynamicState dynamic_states[3] = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_LINE_WIDTH};
Mark Young7394fdd2016-03-31 14:56:43 -06008386 // Set scissor as dynamic to avoid that error
8387 VkPipelineDynamicStateCreateInfo dyn_state_ci = {};
8388 dyn_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
8389 dyn_state_ci.dynamicStateCount = 2;
8390 dyn_state_ci.pDynamicStates = dynamic_states;
8391
8392 VkPipelineShaderStageCreateInfo shaderStages[2];
8393 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
8394
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008395 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
8396 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008397 this); // TODO - We shouldn't need a fragment shader
8398 // but add it to be able to run on more devices
Mark Young7394fdd2016-03-31 14:56:43 -06008399 shaderStages[0] = vs.GetStageCreateInfo();
8400 shaderStages[1] = fs.GetStageCreateInfo();
8401
8402 VkPipelineVertexInputStateCreateInfo vi_ci = {};
8403 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
8404 vi_ci.pNext = nullptr;
8405 vi_ci.vertexBindingDescriptionCount = 0;
8406 vi_ci.pVertexBindingDescriptions = nullptr;
8407 vi_ci.vertexAttributeDescriptionCount = 0;
8408 vi_ci.pVertexAttributeDescriptions = nullptr;
8409
8410 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
8411 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
8412 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
8413
8414 VkPipelineRasterizationStateCreateInfo rs_ci = {};
8415 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
8416 rs_ci.pNext = nullptr;
Rene Lindsay144e4842017-01-20 14:27:15 -07008417 rs_ci.rasterizerDiscardEnable = VK_TRUE;
Mark Young7394fdd2016-03-31 14:56:43 -06008418
Mark Young47107952016-05-02 15:59:55 -06008419 // Check too low (line width of -1.0f).
8420 rs_ci.lineWidth = -1.0f;
Mark Young7394fdd2016-03-31 14:56:43 -06008421
8422 VkPipelineColorBlendAttachmentState att = {};
8423 att.blendEnable = VK_FALSE;
8424 att.colorWriteMask = 0xf;
8425
8426 VkPipelineColorBlendStateCreateInfo cb_ci = {};
8427 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
8428 cb_ci.pNext = nullptr;
8429 cb_ci.attachmentCount = 1;
8430 cb_ci.pAttachments = &att;
8431
8432 VkGraphicsPipelineCreateInfo gp_ci = {};
8433 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
8434 gp_ci.stageCount = 2;
8435 gp_ci.pStages = shaderStages;
8436 gp_ci.pVertexInputState = &vi_ci;
8437 gp_ci.pInputAssemblyState = &ia_ci;
8438 gp_ci.pViewportState = &vp_state_ci;
8439 gp_ci.pRasterizationState = &rs_ci;
8440 gp_ci.pColorBlendState = &cb_ci;
8441 gp_ci.pDynamicState = &dyn_state_ci;
8442 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
8443 gp_ci.layout = pipeline_layout;
8444 gp_ci.renderPass = renderPass();
8445
8446 VkPipelineCacheCreateInfo pc_ci = {};
8447 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
8448
8449 VkPipeline pipeline;
8450 VkPipelineCache pipelineCache;
8451
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008452 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008453 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008454 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008455
8456 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008457 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008458
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008459 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008460
8461 // Check too high (line width of 65536.0f).
8462 rs_ci.lineWidth = 65536.0f;
8463
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008464 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008465 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008466 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008467
8468 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -06008469 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008470
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008471 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to -1");
Mark Young7394fdd2016-03-31 14:56:43 -06008472
8473 dyn_state_ci.dynamicStateCount = 3;
8474
8475 rs_ci.lineWidth = 1.0f;
8476
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008477 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Mark Young7394fdd2016-03-31 14:56:43 -06008478 ASSERT_VK_SUCCESS(err);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008479 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tony Barbour552f6c02016-12-21 14:34:07 -07008480 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008481 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
Mark Young7394fdd2016-03-31 14:56:43 -06008482
8483 // Check too low with dynamic setting.
Mark Young47107952016-05-02 15:59:55 -06008484 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), -1.0f);
Mark Young7394fdd2016-03-31 14:56:43 -06008485 m_errorMonitor->VerifyFound();
8486
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attempt to set lineWidth to 65536");
Mark Young7394fdd2016-03-31 14:56:43 -06008488
8489 // Check too high with dynamic setting.
8490 vkCmdSetLineWidth(m_commandBuffer->GetBufferHandle(), 65536.0f);
8491 m_errorMonitor->VerifyFound();
Tony Barbour552f6c02016-12-21 14:34:07 -07008492 m_commandBuffer->EndCommandBuffer();
Mark Young7394fdd2016-03-31 14:56:43 -06008493
8494 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
8495 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
8496 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
8497 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06008498 vkDestroyPipeline(m_device->device(), pipeline, NULL);
Mark Young7394fdd2016-03-31 14:56:43 -06008499}
8500
Karl Schultz6addd812016-02-02 17:17:23 -07008501TEST_F(VkLayerTest, NullRenderPass) {
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008502 // Bind a NULL RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Schuchardt0b1f2f82016-12-28 15:11:20 -07008504 "vkCmdBeginRenderPass: required parameter pRenderPassBegin specified as NULL");
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008505
8506 ASSERT_NO_FATAL_FAILURE(InitState());
8507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008508
Tony Barbour552f6c02016-12-21 14:34:07 -07008509 m_commandBuffer->BeginCommandBuffer();
Karl Schultz6addd812016-02-02 17:17:23 -07008510 // Don't care about RenderPass handle b/c error should be flagged before
8511 // that
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008512 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), NULL, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008513
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008514 m_errorMonitor->VerifyFound();
Tobin Ehlis98aa0ed2015-06-25 16:27:19 -06008515}
8516
Karl Schultz6addd812016-02-02 17:17:23 -07008517TEST_F(VkLayerTest, RenderPassWithinRenderPass) {
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008518 // Bind a BeginRenderPass within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008519 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8520 "It is invalid to issue this call inside an active render pass");
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008521
8522 ASSERT_NO_FATAL_FAILURE(InitState());
8523 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008524
Tony Barbour552f6c02016-12-21 14:34:07 -07008525 m_commandBuffer->BeginCommandBuffer();
8526 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Karl Schultz6addd812016-02-02 17:17:23 -07008527 // Just create a dummy Renderpass that's non-NULL so we can get to the
8528 // proper error
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008529 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlisaf1f3a42015-06-25 15:46:59 -06008530
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008531 m_errorMonitor->VerifyFound();
Tobin Ehlis49eb23d2015-05-22 12:38:55 -06008532}
8533
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008534TEST_F(VkLayerTest, RenderPassClearOpMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008535 TEST_DESCRIPTION(
8536 "Begin a renderPass where clearValueCount is less than"
8537 "the number of renderPass attachments that use loadOp"
8538 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008539
8540 ASSERT_NO_FATAL_FAILURE(InitState());
8541 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8542
8543 // Create a renderPass with a single attachment that uses loadOp CLEAR
8544 VkAttachmentReference attach = {};
8545 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8546 VkSubpassDescription subpass = {};
8547 subpass.inputAttachmentCount = 1;
8548 subpass.pInputAttachments = &attach;
8549 VkRenderPassCreateInfo rpci = {};
8550 rpci.subpassCount = 1;
8551 rpci.pSubpasses = &subpass;
8552 rpci.attachmentCount = 1;
8553 VkAttachmentDescription attach_desc = {};
Rene Lindsay4bf0e4c2017-01-31 14:20:34 -07008554 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008555 // Set loadOp to CLEAR
8556 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8557 rpci.pAttachments = &attach_desc;
8558 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8559 VkRenderPass rp;
8560 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8561
8562 VkCommandBufferInheritanceInfo hinfo = {};
8563 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
8564 hinfo.renderPass = VK_NULL_HANDLE;
8565 hinfo.subpass = 0;
8566 hinfo.framebuffer = VK_NULL_HANDLE;
8567 hinfo.occlusionQueryEnable = VK_FALSE;
8568 hinfo.queryFlags = 0;
8569 hinfo.pipelineStatistics = 0;
8570 VkCommandBufferBeginInfo info = {};
8571 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8572 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8573 info.pInheritanceInfo = &hinfo;
8574
8575 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8576 VkRenderPassBeginInfo rp_begin = {};
8577 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8578 rp_begin.pNext = NULL;
8579 rp_begin.renderPass = renderPass();
8580 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008581 rp_begin.clearValueCount = 0; // Should be 1
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008582
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07008583 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00442);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008584
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008585 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008586
8587 m_errorMonitor->VerifyFound();
Mark Lobodzinski5c70ebd2016-06-09 13:45:00 -06008588
8589 vkDestroyRenderPass(m_device->device(), rp, NULL);
Tobin Ehlis5a1c0332016-05-31 13:59:26 -06008590}
8591
Slawomir Cygan0808f392016-11-28 17:53:23 +01008592TEST_F(VkLayerTest, RenderPassClearOpTooManyValues) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008593 TEST_DESCRIPTION(
8594 "Begin a renderPass where clearValueCount is greater than"
8595 "the number of renderPass attachments that use loadOp"
8596 "VK_ATTACHMENT_LOAD_OP_CLEAR.");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008597
8598 ASSERT_NO_FATAL_FAILURE(InitState());
8599 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8600
8601 // Create a renderPass with a single attachment that uses loadOp CLEAR
8602 VkAttachmentReference attach = {};
8603 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
8604 VkSubpassDescription subpass = {};
8605 subpass.inputAttachmentCount = 1;
8606 subpass.pInputAttachments = &attach;
8607 VkRenderPassCreateInfo rpci = {};
8608 rpci.subpassCount = 1;
8609 rpci.pSubpasses = &subpass;
8610 rpci.attachmentCount = 1;
8611 VkAttachmentDescription attach_desc = {};
8612 attach_desc.format = VK_FORMAT_B8G8R8A8_UNORM;
8613 // Set loadOp to CLEAR
8614 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
8615 rpci.pAttachments = &attach_desc;
8616 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
8617 VkRenderPass rp;
8618 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
8619
8620 VkCommandBufferBeginInfo info = {};
8621 info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
8622 info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
8623
8624 vkBeginCommandBuffer(m_commandBuffer->handle(), &info);
8625 VkRenderPassBeginInfo rp_begin = {};
8626 rp_begin.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
8627 rp_begin.pNext = NULL;
8628 rp_begin.renderPass = renderPass();
8629 rp_begin.framebuffer = framebuffer();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008630 rp_begin.clearValueCount = 2; // Should be 1
Slawomir Cygan0808f392016-11-28 17:53:23 +01008631
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008632 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
8633 " has a clearValueCount of"
8634 " 2 but only first 1 entries in pClearValues array are used");
Slawomir Cygan0808f392016-11-28 17:53:23 +01008635
8636 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rp_begin, VK_SUBPASS_CONTENTS_INLINE);
8637
8638 m_errorMonitor->VerifyFound();
8639
8640 vkDestroyRenderPass(m_device->device(), rp, NULL);
8641}
8642
Cody Northrop3bb4d962016-05-09 16:15:57 -06008643TEST_F(VkLayerTest, EndCommandBufferWithinRenderPass) {
Cody Northrop3bb4d962016-05-09 16:15:57 -06008644 TEST_DESCRIPTION("End a command buffer with an active render pass");
8645
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008646 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8647 "It is invalid to issue this call inside an active render pass");
Cody Northrop3bb4d962016-05-09 16:15:57 -06008648
8649 ASSERT_NO_FATAL_FAILURE(InitState());
8650 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8651
Tony Barbour552f6c02016-12-21 14:34:07 -07008652 m_commandBuffer->BeginCommandBuffer();
8653 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
8654 vkEndCommandBuffer(m_commandBuffer->handle());
Cody Northrop3bb4d962016-05-09 16:15:57 -06008655
8656 m_errorMonitor->VerifyFound();
8657
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008658 // TODO: Add test for VK_COMMAND_BUFFER_LEVEL_SECONDARY
8659 // TODO: Add test for VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT
Cody Northrop3bb4d962016-05-09 16:15:57 -06008660}
8661
Karl Schultz6addd812016-02-02 17:17:23 -07008662TEST_F(VkLayerTest, FillBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008663 // Call CmdFillBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008664 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8665 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008666
8667 ASSERT_NO_FATAL_FAILURE(InitState());
8668 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008669
Tony Barbour552f6c02016-12-21 14:34:07 -07008670 m_commandBuffer->BeginCommandBuffer();
8671 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008672
8673 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008674 vk_testing::Buffer dstBuffer;
8675 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008676
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008677 m_commandBuffer->FillBuffer(dstBuffer.handle(), 0, 4, 0x11111111);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008678
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008679 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008680}
8681
Karl Schultz6addd812016-02-02 17:17:23 -07008682TEST_F(VkLayerTest, UpdateBufferWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008683 // Call CmdUpdateBuffer within an active renderpass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008684 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8685 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008686
8687 ASSERT_NO_FATAL_FAILURE(InitState());
8688 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008689
Tony Barbour552f6c02016-12-21 14:34:07 -07008690 m_commandBuffer->BeginCommandBuffer();
8691 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008692
8693 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008694 vk_testing::Buffer dstBuffer;
8695 dstBuffer.init_as_dst(*m_device, (VkDeviceSize)1024, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008696
Karl Schultz6addd812016-02-02 17:17:23 -07008697 VkDeviceSize dstOffset = 0;
Rene Lindsay32d26902017-02-02 16:49:24 -07008698 uint32_t Data[] = {1, 2, 3, 4, 5, 6, 7, 8};
8699 VkDeviceSize dataSize = sizeof(Data) / sizeof(uint32_t);
8700 vkCmdUpdateBuffer(m_commandBuffer->GetBufferHandle(), dstBuffer.handle(), dstOffset, dataSize, &Data);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008701
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008702 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008703}
8704
Karl Schultz6addd812016-02-02 17:17:23 -07008705TEST_F(VkLayerTest, ClearColorImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008706 // Call CmdClearColorImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8708 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008709
8710 ASSERT_NO_FATAL_FAILURE(InitState());
8711 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008712
Tony Barbour552f6c02016-12-21 14:34:07 -07008713 m_commandBuffer->BeginCommandBuffer();
8714 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008715
Michael Lentine0a369f62016-02-03 16:51:46 -06008716 VkClearColorValue clear_color;
8717 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
Karl Schultz6addd812016-02-02 17:17:23 -07008718 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8719 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
8720 const int32_t tex_width = 32;
8721 const int32_t tex_height = 32;
8722 VkImageCreateInfo image_create_info = {};
8723 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
8724 image_create_info.pNext = NULL;
8725 image_create_info.imageType = VK_IMAGE_TYPE_2D;
8726 image_create_info.format = tex_format;
8727 image_create_info.extent.width = tex_width;
8728 image_create_info.extent.height = tex_height;
8729 image_create_info.extent.depth = 1;
8730 image_create_info.mipLevels = 1;
8731 image_create_info.arrayLayers = 1;
8732 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
8733 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
Jeremy Hayesa3d5c7b2017-03-07 16:01:52 -07008734 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008735
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008736 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008737 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008738
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008739 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008740
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008741 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1, &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008742
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008743 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008744}
8745
Karl Schultz6addd812016-02-02 17:17:23 -07008746TEST_F(VkLayerTest, ClearDepthStencilImageWithinRenderPass) {
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008747 // Call CmdClearDepthStencilImage within an active RenderPass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8749 "It is invalid to issue this call inside an active render pass");
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008750
8751 ASSERT_NO_FATAL_FAILURE(InitState());
8752 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008753
Tony Barbourf887b162017-03-09 10:06:46 -07008754 auto depth_format = find_depth_stencil_format(m_device);
8755 if (!depth_format) {
8756 printf(" No Depth + Stencil format found. Skipped.\n");
8757 return;
8758 }
8759
Tony Barbour552f6c02016-12-21 14:34:07 -07008760 m_commandBuffer->BeginCommandBuffer();
8761 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008762
8763 VkClearDepthStencilValue clear_value = {0};
Dustin Gravesa2e5c942016-02-11 18:28:06 -07008764 VkMemoryPropertyFlags reqs = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008765 VkImageCreateInfo image_create_info = vk_testing::Image::create_info();
8766 image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07008767 image_create_info.format = depth_format;
Karl Schultz6addd812016-02-02 17:17:23 -07008768 image_create_info.extent.width = 64;
8769 image_create_info.extent.height = 64;
8770 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
8771 image_create_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008772
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008773 vk_testing::Image dstImage;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008774 dstImage.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008775
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008776 const VkImageSubresourceRange range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_DEPTH_BIT);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008777
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07008778 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), dstImage.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_value, 1,
8779 &range);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008780
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008781 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008782}
8783
Karl Schultz6addd812016-02-02 17:17:23 -07008784TEST_F(VkLayerTest, ClearColorAttachmentsOutsideRenderPass) {
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008785 // Call CmdClearAttachmentss outside of an active RenderPass
Karl Schultz6addd812016-02-02 17:17:23 -07008786 VkResult err;
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008787
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008788 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8789 "vkCmdClearAttachments(): This call "
8790 "must be issued inside an active "
8791 "render pass");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06008792
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008793 ASSERT_NO_FATAL_FAILURE(InitState());
8794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008795
8796 // Start no RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +08008797 err = m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008798 ASSERT_VK_SUCCESS(err);
8799
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -06008800 VkClearAttachment color_attachment;
8801 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8802 color_attachment.clearValue.color.float32[0] = 0;
8803 color_attachment.clearValue.color.float32[1] = 0;
8804 color_attachment.clearValue.color.float32[2] = 0;
8805 color_attachment.clearValue.color.float32[3] = 0;
8806 color_attachment.colorAttachment = 0;
Karl Schultz6addd812016-02-02 17:17:23 -07008807 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008808 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008809
Chris Forbes8f36a8a2016-04-07 13:21:07 +12008810 m_errorMonitor->VerifyFound();
Mark Lobodzinskid5639502015-09-24 09:51:47 -06008811}
8812
Chris Forbes3b97e932016-09-07 11:29:24 +12008813TEST_F(VkLayerTest, RenderPassExcessiveNextSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008814 TEST_DESCRIPTION(
8815 "Test that an error is produced when CmdNextSubpass is "
8816 "called too many times in a renderpass instance");
Chris Forbes3b97e932016-09-07 11:29:24 +12008817
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8819 "vkCmdNextSubpass(): Attempted to advance "
8820 "beyond final subpass");
Chris Forbes3b97e932016-09-07 11:29:24 +12008821
8822 ASSERT_NO_FATAL_FAILURE(InitState());
8823 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8824
Tony Barbour552f6c02016-12-21 14:34:07 -07008825 m_commandBuffer->BeginCommandBuffer();
8826 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes3b97e932016-09-07 11:29:24 +12008827
8828 // error here.
8829 vkCmdNextSubpass(m_commandBuffer->GetBufferHandle(), VK_SUBPASS_CONTENTS_INLINE);
8830 m_errorMonitor->VerifyFound();
8831
Tony Barbour552f6c02016-12-21 14:34:07 -07008832 m_commandBuffer->EndRenderPass();
8833 m_commandBuffer->EndCommandBuffer();
Chris Forbes3b97e932016-09-07 11:29:24 +12008834}
8835
Chris Forbes6d624702016-09-07 13:57:05 +12008836TEST_F(VkLayerTest, RenderPassEndedBeforeFinalSubpass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008837 TEST_DESCRIPTION(
8838 "Test that an error is produced when CmdEndRenderPass is "
8839 "called before the final subpass has been reached");
Chris Forbes6d624702016-09-07 13:57:05 +12008840
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008841 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8842 "vkCmdEndRenderPass(): Called before reaching "
8843 "final subpass");
Chris Forbes6d624702016-09-07 13:57:05 +12008844
8845 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008846 VkSubpassDescription sd[2] = {{0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr},
8847 {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, nullptr, 0, nullptr}};
Chris Forbes6d624702016-09-07 13:57:05 +12008848
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008849 VkRenderPassCreateInfo rcpi = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 2, sd, 0, nullptr};
Chris Forbes6d624702016-09-07 13:57:05 +12008850
8851 VkRenderPass rp;
8852 VkResult err = vkCreateRenderPass(m_device->device(), &rcpi, nullptr, &rp);
8853 ASSERT_VK_SUCCESS(err);
8854
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008855 VkFramebufferCreateInfo fbci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 16, 16, 1};
Chris Forbes6d624702016-09-07 13:57:05 +12008856
8857 VkFramebuffer fb;
8858 err = vkCreateFramebuffer(m_device->device(), &fbci, nullptr, &fb);
8859 ASSERT_VK_SUCCESS(err);
8860
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008861 m_commandBuffer->BeginCommandBuffer(); // no implicit RP begin
Chris Forbes6d624702016-09-07 13:57:05 +12008862
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008863 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 +12008864
8865 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
8866
8867 // Error here.
8868 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
8869 m_errorMonitor->VerifyFound();
8870
8871 // Clean up.
8872 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
8873 vkDestroyRenderPass(m_device->device(), rp, nullptr);
8874}
8875
Karl Schultz9e66a292016-04-21 15:57:51 -06008876TEST_F(VkLayerTest, BufferMemoryBarrierNoBuffer) {
8877 // Try to add a buffer memory barrier with no buffer.
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008878 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8879 "required parameter pBufferMemoryBarriers[0].buffer specified as VK_NULL_HANDLE");
Karl Schultz9e66a292016-04-21 15:57:51 -06008880
8881 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbour552f6c02016-12-21 14:34:07 -07008882 m_commandBuffer->BeginCommandBuffer();
Karl Schultz9e66a292016-04-21 15:57:51 -06008883
8884 VkBufferMemoryBarrier buf_barrier = {};
8885 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8886 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8887 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8888 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8889 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8890 buf_barrier.buffer = VK_NULL_HANDLE;
8891 buf_barrier.offset = 0;
8892 buf_barrier.size = VK_WHOLE_SIZE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008893 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8894 nullptr, 1, &buf_barrier, 0, nullptr);
Karl Schultz9e66a292016-04-21 15:57:51 -06008895
8896 m_errorMonitor->VerifyFound();
8897}
8898
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008899TEST_F(VkLayerTest, InvalidBarriers) {
8900 TEST_DESCRIPTION("A variety of ways to get VK_INVALID_BARRIER ");
8901
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008902 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Barriers cannot be set during subpass");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008903
8904 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07008905 auto depth_format = find_depth_stencil_format(m_device);
8906 if (!depth_format) {
8907 printf(" No Depth + Stencil format found. Skipped.\n");
8908 return;
8909 }
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008910 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
8911
8912 VkMemoryBarrier mem_barrier = {};
8913 mem_barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
8914 mem_barrier.pNext = NULL;
8915 mem_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8916 mem_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
Tony Barbour552f6c02016-12-21 14:34:07 -07008917 m_commandBuffer->BeginCommandBuffer();
8918 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008919 // BeginCommandBuffer() starts a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008920 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 1,
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008921 &mem_barrier, 0, nullptr, 0, nullptr);
8922 m_errorMonitor->VerifyFound();
8923
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008924 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Image Layout cannot be transitioned to UNDEFINED");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008925 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008926 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 -06008927 ASSERT_TRUE(image.initialized());
8928 VkImageMemoryBarrier img_barrier = {};
8929 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
8930 img_barrier.pNext = NULL;
8931 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8932 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8933 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8934 // New layout can't be UNDEFINED
8935 img_barrier.newLayout = VK_IMAGE_LAYOUT_UNDEFINED;
8936 img_barrier.image = image.handle();
8937 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8938 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8939 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
8940 img_barrier.subresourceRange.baseArrayLayer = 0;
8941 img_barrier.subresourceRange.baseMipLevel = 0;
8942 img_barrier.subresourceRange.layerCount = 1;
8943 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008944 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8945 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008946 m_errorMonitor->VerifyFound();
8947 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
8948
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07008949 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
8950 "Subresource must have the sum of the "
8951 "baseArrayLayer");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008952 // baseArrayLayer + layerCount must be <= image's arrayLayers
8953 img_barrier.subresourceRange.baseArrayLayer = 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.subresourceRange.baseArrayLayer = 0;
8958
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008959 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Subresource must have the sum of the baseMipLevel");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008960 // baseMipLevel + levelCount must be <= image's mipLevels
8961 img_barrier.subresourceRange.baseMipLevel = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008962 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8963 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008964 m_errorMonitor->VerifyFound();
8965 img_barrier.subresourceRange.baseMipLevel = 0;
8966
Mike Weiblen7053aa32017-01-25 15:21:10 -07008967 // levelCount must be non-zero.
8968 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
8969 img_barrier.subresourceRange.levelCount = 0;
8970 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8971 nullptr, 0, nullptr, 1, &img_barrier);
8972 m_errorMonitor->VerifyFound();
8973 img_barrier.subresourceRange.levelCount = 1;
8974
8975 // layerCount must be non-zero.
8976 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
8977 img_barrier.subresourceRange.layerCount = 0;
8978 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8979 nullptr, 0, nullptr, 1, &img_barrier);
8980 m_errorMonitor->VerifyFound();
8981 img_barrier.subresourceRange.layerCount = 1;
8982
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008983 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 -06008984 vk_testing::Buffer buffer;
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07008985 VkMemoryPropertyFlags mem_reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
8986 buffer.init_as_src_and_dst(*m_device, 256, mem_reqs);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06008987 VkBufferMemoryBarrier buf_barrier = {};
8988 buf_barrier.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER;
8989 buf_barrier.pNext = NULL;
8990 buf_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
8991 buf_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
8992 buf_barrier.buffer = buffer.handle();
8993 buf_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8994 buf_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
8995 buf_barrier.offset = 0;
8996 buf_barrier.size = VK_WHOLE_SIZE;
8997 // Can't send buffer barrier during a render pass
Mark Lobodzinskice751c62016-09-08 10:45:35 -06008998 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
8999 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009000 m_errorMonitor->VerifyFound();
9001 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
9002
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which is not less than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009004 buf_barrier.offset = 257;
9005 // Offset greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009006 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9007 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009008 m_errorMonitor->VerifyFound();
9009 buf_barrier.offset = 0;
9010
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009011 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "whose sum is greater than total size");
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009012 buf_barrier.size = 257;
9013 // Size greater than total size
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009014 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9015 nullptr, 1, &buf_barrier, 0, nullptr);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009016 m_errorMonitor->VerifyFound();
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009017
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009018 // Now exercise barrier aspect bit errors, first DS
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009019 m_errorMonitor->SetDesiredFailureMsg(
9020 VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -06009021 "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 -06009022 VkDepthStencilObj ds_image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -07009023 ds_image.Init(m_device, 128, 128, depth_format);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009024 ASSERT_TRUE(ds_image.initialized());
Tobin Ehlis15684a02016-07-21 14:55:26 -06009025 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
9026 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009027 img_barrier.image = ds_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009028
9029 // Not having DEPTH or STENCIL set is an error
Rene Lindsay4834cba2017-02-02 17:18:56 -07009030 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009031 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9032 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009033 m_errorMonitor->VerifyFound();
Dave Houltonfbf52152017-01-06 12:55:29 -07009034
9035 // Having anything other than DEPTH or STENCIL is an error
9036 m_errorMonitor->SetDesiredFailureMsg(
9037 VK_DEBUG_REPORT_ERROR_BIT_EXT,
9038 "Combination depth/stencil image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT and VK_IMAGE_ASPECT_STENCIL_BIT set.");
9039 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
9040 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9041 nullptr, 0, nullptr, 1, &img_barrier);
9042 m_errorMonitor->VerifyFound();
9043
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009044 // Now test depth-only
9045 VkFormatProperties format_props;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009046 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &format_props);
9047 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009048 VkDepthStencilObj d_image(m_device);
9049 d_image.Init(m_device, 128, 128, VK_FORMAT_D16_UNORM);
9050 ASSERT_TRUE(d_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009051 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009052 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009053 img_barrier.image = d_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009054
9055 // DEPTH bit must be set
9056 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9057 "Depth-only image formats must have the VK_IMAGE_ASPECT_DEPTH_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009058 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009059 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9060 0, nullptr, 0, nullptr, 1, &img_barrier);
9061 m_errorMonitor->VerifyFound();
9062
9063 // No bits other than DEPTH may be set
9064 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9065 "Depth-only image formats can have only the VK_IMAGE_ASPECT_DEPTH_BIT set.");
9066 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009067 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9068 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009069 m_errorMonitor->VerifyFound();
9070 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009071
9072 // Now test stencil-only
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009073 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &format_props);
9074 if (format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) {
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009075 VkDepthStencilObj s_image(m_device);
9076 s_image.Init(m_device, 128, 128, VK_FORMAT_S8_UINT);
9077 ASSERT_TRUE(s_image.initialized());
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009078 img_barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
Tobin Ehlis15684a02016-07-21 14:55:26 -06009079 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009080 img_barrier.image = s_image.handle();
Tobin Ehlis15684a02016-07-21 14:55:26 -06009081 // Use of COLOR aspect on depth image is error
Dave Houltonf3229d52017-02-21 15:59:08 -07009082 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9083 "Stencil-only image formats must have the VK_IMAGE_ASPECT_STENCIL_BIT set.");
Tobin Ehlis15684a02016-07-21 14:55:26 -06009084 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009085 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0,
9086 0, nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009087 m_errorMonitor->VerifyFound();
9088 }
Dave Houltonfbf52152017-01-06 12:55:29 -07009089
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009090 // Finally test color
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009091 VkImageObj c_image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009092 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 -06009093 ASSERT_TRUE(c_image.initialized());
9094 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9095 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
9096 img_barrier.image = c_image.handle();
Dave Houltonfbf52152017-01-06 12:55:29 -07009097
9098 // COLOR bit must be set
9099 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9100 "Color image formats must have the VK_IMAGE_ASPECT_COLOR_BIT set.");
Rene Lindsay4834cba2017-02-02 17:18:56 -07009101 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Dave Houltonfbf52152017-01-06 12:55:29 -07009102 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9103 nullptr, 0, nullptr, 1, &img_barrier);
9104 m_errorMonitor->VerifyFound();
9105
9106 // No bits other than COLOR may be set
9107 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9108 "Color image formats must have ONLY the VK_IMAGE_ASPECT_COLOR_BIT set.");
9109 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009110 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
9111 nullptr, 0, nullptr, 1, &img_barrier);
Tobin Ehlis17b2e7b2016-07-21 09:43:29 -06009112 m_errorMonitor->VerifyFound();
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009113
9114 // Attempt to mismatch barriers/waitEvents calls with incompatible queues
9115
9116 // Create command pool with incompatible queueflags
9117 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
9118 uint32_t queue_family_index = UINT32_MAX;
9119 for (uint32_t i = 0; i < queue_props.size(); i++) {
9120 if ((queue_props[i].queueFlags & VK_QUEUE_COMPUTE_BIT) == 0) {
9121 queue_family_index = i;
9122 break;
9123 }
9124 }
9125 if (queue_family_index == UINT32_MAX) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009126 printf(" No non-compute queue found; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009127 return;
9128 }
9129 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02513);
9130
9131 VkCommandPool command_pool;
9132 VkCommandPoolCreateInfo pool_create_info{};
9133 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
9134 pool_create_info.queueFamilyIndex = queue_family_index;
9135 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
9136 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
9137
9138 // Allocate a command buffer
9139 VkCommandBuffer bad_command_buffer;
9140 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
9141 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
9142 command_buffer_allocate_info.commandPool = command_pool;
9143 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
9144 command_buffer_allocate_info.commandBufferCount = 1;
9145 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &bad_command_buffer));
9146
9147 VkCommandBufferBeginInfo cbbi = {};
9148 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
9149 vkBeginCommandBuffer(bad_command_buffer, &cbbi);
9150 buf_barrier.offset = 0;
9151 buf_barrier.size = VK_WHOLE_SIZE;
9152 vkCmdPipelineBarrier(bad_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 1,
9153 &buf_barrier, 0, nullptr);
9154 m_errorMonitor->VerifyFound();
9155
9156 if ((queue_props[queue_family_index].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0) {
9157 vkEndCommandBuffer(bad_command_buffer);
9158 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009159 printf(" The non-compute queue does not support graphics; skipped.\n");
Mark Lobodzinskibdf378a2016-12-12 17:11:50 -07009160 return;
9161 }
9162 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02510);
9163 VkEvent event;
9164 VkEventCreateInfo event_create_info{};
9165 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
9166 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
9167 vkCmdWaitEvents(bad_command_buffer, 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, nullptr, 0,
9168 nullptr, 0, nullptr);
9169 m_errorMonitor->VerifyFound();
9170
9171 vkEndCommandBuffer(bad_command_buffer);
9172 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
Tony Barbour7fd5c0f2016-05-03 16:11:53 -06009173}
9174
Tony Barbour18ba25c2016-09-29 13:42:40 -06009175TEST_F(VkLayerTest, LayoutFromPresentWithoutAccessMemoryRead) {
9176 // Transition an image away from PRESENT_SRC_KHR without ACCESS_MEMORY_READ in srcAccessMask
9177
Mark Lobodzinski729a8d32017-01-26 12:16:30 -07009178 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "must have required access bit");
Tony Barbour18ba25c2016-09-29 13:42:40 -06009179 ASSERT_NO_FATAL_FAILURE(InitState());
9180 VkImageObj image(m_device);
Tony Barbour256c80a2016-10-05 13:23:46 -06009181 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbour18ba25c2016-09-29 13:42:40 -06009182 ASSERT_TRUE(image.initialized());
9183
9184 VkImageMemoryBarrier barrier = {};
9185 VkImageSubresourceRange range;
9186 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
9187 barrier.srcAccessMask = 0;
9188 barrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
9189 barrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
9190 barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
9191 barrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9192 barrier.image = image.handle();
9193 range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9194 range.baseMipLevel = 0;
9195 range.levelCount = 1;
9196 range.baseArrayLayer = 0;
9197 range.layerCount = 1;
9198 barrier.subresourceRange = range;
9199 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
9200 cmdbuf.BeginCommandBuffer();
9201 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9202 &barrier);
9203 barrier.oldLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
9204 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
9205 barrier.srcAccessMask = 0;
9206 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
9207 cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0, nullptr, 0, nullptr, 1,
9208 &barrier);
9209
9210 m_errorMonitor->VerifyFound();
9211}
9212
Karl Schultz6addd812016-02-02 17:17:23 -07009213TEST_F(VkLayerTest, IdxBufferAlignmentError) {
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009214 // Bind a BeginRenderPass within an active RenderPass
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009215 ASSERT_NO_FATAL_FAILURE(InitState());
9216 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009217
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009218 uint32_t const indices[] = {0};
9219 VkBufferCreateInfo buf_info = {};
9220 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9221 buf_info.size = 1024;
9222 buf_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
9223 buf_info.queueFamilyIndexCount = 1;
9224 buf_info.pQueueFamilyIndices = indices;
9225
9226 VkBuffer buffer;
9227 VkResult err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
9228 ASSERT_VK_SUCCESS(err);
9229
9230 VkMemoryRequirements requirements;
9231 vkGetBufferMemoryRequirements(m_device->device(), buffer, &requirements);
9232
9233 VkMemoryAllocateInfo alloc_info{};
9234 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9235 alloc_info.pNext = NULL;
9236 alloc_info.memoryTypeIndex = 0;
9237 alloc_info.allocationSize = requirements.size;
9238 bool pass = m_device->phy().set_memory_type(requirements.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
9239 ASSERT_TRUE(pass);
9240
9241 VkDeviceMemory memory;
9242 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &memory);
9243 ASSERT_VK_SUCCESS(err);
9244
9245 err = vkBindBufferMemory(m_device->device(), buffer, memory, 0);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009246 ASSERT_VK_SUCCESS(err);
9247
Tony Barbour552f6c02016-12-21 14:34:07 -07009248 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009249 ASSERT_VK_SUCCESS(err);
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009250
Karl Schultz6addd812016-02-02 17:17:23 -07009251 // vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(),
9252 // VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009253 // Should error before calling to driver so don't care about actual data
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009254 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdBindIndexBuffer() offset (0x7) does not fall on ");
9255 vkCmdBindIndexBuffer(m_commandBuffer->GetBufferHandle(), buffer, 7, VK_INDEX_TYPE_UINT16);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009256 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -06009257
Jeremy Hayes483d95d2017-03-08 11:03:01 -07009258 vkFreeMemory(m_device->device(), memory, NULL);
9259 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tobin Ehlisc4c23182015-09-17 12:24:13 -06009260}
9261
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009262TEST_F(VkLayerTest, InvalidQueueFamilyIndex) {
9263 // Create an out-of-range queueFamilyIndex
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009264 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
9265 "vkCreateBuffer: pCreateInfo->pQueueFamilyIndices[0] (777) must be one "
9266 "of the indices specified when the device was created, via the "
9267 "VkDeviceQueueCreateInfo structure.");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009268
9269 ASSERT_NO_FATAL_FAILURE(InitState());
9270 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
9271 VkBufferCreateInfo buffCI = {};
9272 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9273 buffCI.size = 1024;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009274 buffCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009275 buffCI.queueFamilyIndexCount = 1;
9276 // Introduce failure by specifying invalid queue_family_index
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009277 uint32_t qfi[2];
9278 qfi[0] = 777;
9279
9280 buffCI.pQueueFamilyIndices = qfi;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009281 buffCI.sharingMode = VK_SHARING_MODE_CONCURRENT; // qfi only matters in CONCURRENT mode
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009282
9283 VkBuffer ib;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009284 m_errorMonitor->SetUnexpectedError(
9285 "If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1");
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009286 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib);
9287
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009288 m_errorMonitor->VerifyFound();
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009289
9290 if (m_device->queue_props.size() > 2) {
Tony Barbour75db7402017-03-09 14:51:36 -07009291 VkBuffer ib2;
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009292 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "which was not created allowing concurrent");
9293
9294 // Create buffer shared to queue families 1 and 2, but submitted on queue family 0
9295 buffCI.queueFamilyIndexCount = 2;
9296 qfi[0] = 1;
9297 qfi[1] = 2;
Tony Barbour75db7402017-03-09 14:51:36 -07009298 vkCreateBuffer(m_device->device(), &buffCI, NULL, &ib2);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009299 VkDeviceMemory mem;
9300 VkMemoryRequirements mem_reqs;
Tony Barbour75db7402017-03-09 14:51:36 -07009301 vkGetBufferMemoryRequirements(m_device->device(), ib2, &mem_reqs);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009302
9303 VkMemoryAllocateInfo alloc_info = {};
9304 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9305 alloc_info.allocationSize = 1024;
9306 bool pass = false;
9307 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
9308 if (!pass) {
Tony Barbour75db7402017-03-09 14:51:36 -07009309 vkDestroyBuffer(m_device->device(), ib2, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009310 return;
9311 }
9312 vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
Tony Barbour75db7402017-03-09 14:51:36 -07009313 vkBindBufferMemory(m_device->device(), ib2, mem, 0);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009314
9315 m_commandBuffer->begin();
Tony Barbour75db7402017-03-09 14:51:36 -07009316 vkCmdFillBuffer(m_commandBuffer->handle(), ib2, 0, 16, 5);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009317 m_commandBuffer->end();
9318 QueueCommandBuffer(false);
9319 m_errorMonitor->VerifyFound();
Tony Barbour75db7402017-03-09 14:51:36 -07009320 vkDestroyBuffer(m_device->device(), ib2, NULL);
9321 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski4761d212017-02-28 13:12:44 -07009322 }
9323
Tony Barbourdf4c0042016-06-01 15:55:43 -06009324 vkDestroyBuffer(m_device->device(), ib, NULL);
Mark Lobodzinski52a6e7d2016-02-25 15:09:52 -07009325}
9326
Karl Schultz6addd812016-02-02 17:17:23 -07009327TEST_F(VkLayerTest, ExecuteCommandsPrimaryCB) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009328 TEST_DESCRIPTION(
9329 "Attempt vkCmdExecuteCommands with a primary command buffer"
9330 " (should only be secondary)");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -06009331
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009332 ASSERT_NO_FATAL_FAILURE(InitState());
9333 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009334
Chris Forbesf29a84f2016-10-06 18:39:28 +13009335 // An empty primary command buffer
9336 VkCommandBufferObj cb(m_device, m_commandPool);
9337 cb.BeginCommandBuffer();
9338 cb.EndCommandBuffer();
Tobin Ehlis0c94db02016-07-19 10:49:32 -06009339
Chris Forbesf29a84f2016-10-06 18:39:28 +13009340 m_commandBuffer->BeginCommandBuffer();
9341 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
9342 VkCommandBuffer handle = cb.handle();
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009343
Chris Forbesf29a84f2016-10-06 18:39:28 +13009344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdExecuteCommands() called w/ Primary Cmd Buffer ");
9345 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &handle);
Chris Forbes8f36a8a2016-04-07 13:21:07 +12009346 m_errorMonitor->VerifyFound();
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009347
9348 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Tobin Ehlis4b34ddc2015-09-17 14:18:16 -06009349}
9350
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009351TEST_F(VkLayerTest, DSUsageBitsErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009352 TEST_DESCRIPTION(
9353 "Attempt to update descriptor sets for images and buffers "
9354 "that do not have correct usage bits sets.");
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009355 VkResult err;
9356
9357 ASSERT_NO_FATAL_FAILURE(InitState());
9358 VkDescriptorPoolSize ds_type_count[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9359 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9360 ds_type_count[i].type = VkDescriptorType(i);
9361 ds_type_count[i].descriptorCount = 1;
9362 }
9363 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9364 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9365 ds_pool_ci.pNext = NULL;
9366 ds_pool_ci.maxSets = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9367 ds_pool_ci.poolSizeCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9368 ds_pool_ci.pPoolSizes = ds_type_count;
9369
9370 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009371 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009372 ASSERT_VK_SUCCESS(err);
9373
9374 // Create 10 layouts where each has a single descriptor of different type
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009375 VkDescriptorSetLayoutBinding dsl_binding[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009376 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9377 dsl_binding[i].binding = 0;
9378 dsl_binding[i].descriptorType = VkDescriptorType(i);
9379 dsl_binding[i].descriptorCount = 1;
9380 dsl_binding[i].stageFlags = VK_SHADER_STAGE_ALL;
9381 dsl_binding[i].pImmutableSamplers = NULL;
9382 }
9383
9384 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9385 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9386 ds_layout_ci.pNext = NULL;
9387 ds_layout_ci.bindingCount = 1;
9388 VkDescriptorSetLayout ds_layouts[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
9389 for (uint32_t i = 0; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
9390 ds_layout_ci.pBindings = dsl_binding + i;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009391 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, ds_layouts + i);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009392 ASSERT_VK_SUCCESS(err);
9393 }
9394 VkDescriptorSet descriptor_sets[VK_DESCRIPTOR_TYPE_RANGE_SIZE] = {};
9395 VkDescriptorSetAllocateInfo alloc_info = {};
9396 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9397 alloc_info.descriptorSetCount = VK_DESCRIPTOR_TYPE_RANGE_SIZE;
9398 alloc_info.descriptorPool = ds_pool;
9399 alloc_info.pSetLayouts = ds_layouts;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009400 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, descriptor_sets);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009401 ASSERT_VK_SUCCESS(err);
9402
9403 // Create a buffer & bufferView to be used for invalid updates
9404 VkBufferCreateInfo buff_ci = {};
9405 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
Tony Barbour415497c2017-01-24 10:06:09 -07009406 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009407 buff_ci.size = 256;
9408 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
Tony Barbour415497c2017-01-24 10:06:09 -07009409 VkBuffer buffer, storage_texel_buffer;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009410 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9411 ASSERT_VK_SUCCESS(err);
Tony Barbour415497c2017-01-24 10:06:09 -07009412
9413 // Create another buffer to use in testing the UNIFORM_TEXEL_BUFFER case
9414 buff_ci.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
9415 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &storage_texel_buffer);
9416 ASSERT_VK_SUCCESS(err);
9417
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009418 VkMemoryRequirements mem_reqs;
9419 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
9420 VkMemoryAllocateInfo mem_alloc_info = {};
9421 mem_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9422 mem_alloc_info.pNext = NULL;
9423 mem_alloc_info.memoryTypeIndex = 0;
9424 mem_alloc_info.allocationSize = mem_reqs.size;
9425 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9426 if (!pass) {
9427 vkDestroyBuffer(m_device->device(), buffer, NULL);
9428 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9429 return;
9430 }
9431 VkDeviceMemory mem;
9432 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &mem);
9433 ASSERT_VK_SUCCESS(err);
9434 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9435 ASSERT_VK_SUCCESS(err);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009436
9437 VkBufferViewCreateInfo buff_view_ci = {};
9438 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
9439 buff_view_ci.buffer = buffer;
9440 buff_view_ci.format = VK_FORMAT_R8_UNORM;
9441 buff_view_ci.range = VK_WHOLE_SIZE;
9442 VkBufferView buff_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009443 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buff_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009444 ASSERT_VK_SUCCESS(err);
9445
Tony Barbour415497c2017-01-24 10:06:09 -07009446 // Now get resources / view for storage_texel_buffer
9447 vkGetBufferMemoryRequirements(m_device->device(), storage_texel_buffer, &mem_reqs);
9448 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc_info, 0);
9449 if (!pass) {
9450 vkDestroyBuffer(m_device->device(), buffer, NULL);
9451 vkDestroyBufferView(m_device->device(), buff_view, NULL);
9452 vkFreeMemory(m_device->device(), mem, NULL);
9453 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
9454 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9455 return;
9456 }
9457 VkDeviceMemory storage_texel_buffer_mem;
9458 VkBufferView storage_texel_buffer_view;
9459 err = vkAllocateMemory(m_device->device(), &mem_alloc_info, NULL, &storage_texel_buffer_mem);
9460 ASSERT_VK_SUCCESS(err);
9461 err = vkBindBufferMemory(m_device->device(), storage_texel_buffer, storage_texel_buffer_mem, 0);
9462 ASSERT_VK_SUCCESS(err);
9463 buff_view_ci.buffer = storage_texel_buffer;
9464 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &storage_texel_buffer_view);
9465 ASSERT_VK_SUCCESS(err);
9466
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009467 // Create an image to be used for invalid updates
Tony Barbour4b4a4222017-01-24 11:46:34 -07009468 // Find a format / tiling for COLOR_ATTACHMENT
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009469 VkImageCreateInfo image_ci = {};
Tony Barbour4b4a4222017-01-24 11:46:34 -07009470 image_ci.format = VK_FORMAT_UNDEFINED;
9471 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
9472 VkFormat format = static_cast<VkFormat>(f);
9473 VkFormatProperties fProps = m_device->format_properties(format);
9474 if (fProps.linearTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9475 image_ci.format = format;
9476 image_ci.tiling = VK_IMAGE_TILING_LINEAR;
9477 break;
9478 } else if (fProps.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) {
9479 image_ci.format = format;
9480 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
9481 break;
9482 }
9483 }
9484 if (image_ci.format == VK_FORMAT_UNDEFINED) {
9485 return;
9486 }
9487
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009488 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9489 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009490 image_ci.extent.width = 64;
9491 image_ci.extent.height = 64;
9492 image_ci.extent.depth = 1;
9493 image_ci.mipLevels = 1;
9494 image_ci.arrayLayers = 1;
9495 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009496 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009497 image_ci.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009498 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9499 VkImage image;
9500 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9501 ASSERT_VK_SUCCESS(err);
9502 // Bind memory to image
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009503 VkDeviceMemory image_mem;
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009504
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009505 VkMemoryAllocateInfo mem_alloc = {};
9506 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9507 mem_alloc.pNext = NULL;
9508 mem_alloc.allocationSize = 0;
9509 mem_alloc.memoryTypeIndex = 0;
9510 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9511 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009512 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009513 ASSERT_TRUE(pass);
9514 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9515 ASSERT_VK_SUCCESS(err);
9516 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9517 ASSERT_VK_SUCCESS(err);
9518 // Now create view for image
9519 VkImageViewCreateInfo image_view_ci = {};
9520 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9521 image_view_ci.image = image;
Tony Barbour4b4a4222017-01-24 11:46:34 -07009522 image_view_ci.format = image_ci.format;
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009523 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9524 image_view_ci.subresourceRange.layerCount = 1;
9525 image_view_ci.subresourceRange.baseArrayLayer = 0;
9526 image_view_ci.subresourceRange.levelCount = 1;
9527 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
9528 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009529 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009530 ASSERT_VK_SUCCESS(err);
9531
9532 VkDescriptorBufferInfo buff_info = {};
9533 buff_info.buffer = buffer;
9534 VkDescriptorImageInfo img_info = {};
9535 img_info.imageView = image_view;
9536 VkWriteDescriptorSet descriptor_write = {};
9537 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9538 descriptor_write.dstBinding = 0;
9539 descriptor_write.descriptorCount = 1;
9540 descriptor_write.pTexelBufferView = &buff_view;
9541 descriptor_write.pBufferInfo = &buff_info;
9542 descriptor_write.pImageInfo = &img_info;
9543
9544 // These error messages align with VkDescriptorType struct
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009545 UNIQUE_VALIDATION_ERROR_CODE error_codes[] = {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009546 VALIDATION_ERROR_00943, // placeholder, no error for SAMPLER descriptor
9547 VALIDATION_ERROR_00943, // COMBINED_IMAGE_SAMPLER
9548 VALIDATION_ERROR_00943, // SAMPLED_IMAGE
9549 VALIDATION_ERROR_00943, // STORAGE_IMAGE
9550 VALIDATION_ERROR_00950, // UNIFORM_TEXEL_BUFFER
9551 VALIDATION_ERROR_00951, // STORAGE_TEXEL_BUFFER
9552 VALIDATION_ERROR_00946, // UNIFORM_BUFFER
9553 VALIDATION_ERROR_00947, // STORAGE_BUFFER
9554 VALIDATION_ERROR_00946, // UNIFORM_BUFFER_DYNAMIC
9555 VALIDATION_ERROR_00947, // STORAGE_BUFFER_DYNAMIC
9556 VALIDATION_ERROR_00943 // INPUT_ATTACHMENT
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009557 };
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009558 // Start loop at 1 as SAMPLER desc type has no usage bit error
9559 for (uint32_t i = 1; i < VK_DESCRIPTOR_TYPE_RANGE_SIZE; ++i) {
Tony Barbour415497c2017-01-24 10:06:09 -07009560 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9561 // Now check for UNIFORM_TEXEL_BUFFER using storage_texel_buffer_view
9562 descriptor_write.pTexelBufferView = &storage_texel_buffer_view;
9563 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009564 descriptor_write.descriptorType = VkDescriptorType(i);
9565 descriptor_write.dstSet = descriptor_sets[i];
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009566 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_codes[i]);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009567
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009568 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009569
9570 m_errorMonitor->VerifyFound();
9571 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[i], NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009572 if (VkDescriptorType(i) == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) {
9573 descriptor_write.pTexelBufferView = &buff_view;
9574 }
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009575 }
Tony Barbour415497c2017-01-24 10:06:09 -07009576
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009577 vkDestroyDescriptorSetLayout(m_device->device(), ds_layouts[0], NULL);
9578 vkDestroyImage(m_device->device(), image, NULL);
Tony Barbourdf4c0042016-06-01 15:55:43 -06009579 vkFreeMemory(m_device->device(), image_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009580 vkDestroyImageView(m_device->device(), image_view, NULL);
9581 vkDestroyBuffer(m_device->device(), buffer, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009582 vkDestroyBuffer(m_device->device(), storage_texel_buffer, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009583 vkDestroyBufferView(m_device->device(), buff_view, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009584 vkDestroyBufferView(m_device->device(), storage_texel_buffer_view, NULL);
Tobin Ehlis76f8b0b2017-01-02 13:21:21 -07009585 vkFreeMemory(m_device->device(), mem, NULL);
Tony Barbour415497c2017-01-24 10:06:09 -07009586 vkFreeMemory(m_device->device(), storage_texel_buffer_mem, NULL);
Tobin Ehlis17826bd2016-05-25 11:12:50 -06009587 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9588}
9589
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009590TEST_F(VkLayerTest, DSBufferInfoErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009591 TEST_DESCRIPTION(
9592 "Attempt to update buffer descriptor set that has incorrect "
9593 "parameters in VkDescriptorBufferInfo struct. This includes:\n"
9594 "1. offset value greater than buffer size\n"
9595 "2. range value of 0\n"
9596 "3. range value greater than buffer (size - offset)");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009597 VkResult err;
9598
9599 ASSERT_NO_FATAL_FAILURE(InitState());
9600 VkDescriptorPoolSize ds_type_count = {};
9601 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9602 ds_type_count.descriptorCount = 1;
9603
9604 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9605 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9606 ds_pool_ci.pNext = NULL;
9607 ds_pool_ci.maxSets = 1;
9608 ds_pool_ci.poolSizeCount = 1;
9609 ds_pool_ci.pPoolSizes = &ds_type_count;
9610
9611 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009612 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009613 ASSERT_VK_SUCCESS(err);
9614
9615 // Create layout with single uniform buffer descriptor
9616 VkDescriptorSetLayoutBinding dsl_binding = {};
9617 dsl_binding.binding = 0;
9618 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9619 dsl_binding.descriptorCount = 1;
9620 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9621 dsl_binding.pImmutableSamplers = NULL;
9622
9623 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9624 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9625 ds_layout_ci.pNext = NULL;
9626 ds_layout_ci.bindingCount = 1;
9627 ds_layout_ci.pBindings = &dsl_binding;
9628 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009629 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009630 ASSERT_VK_SUCCESS(err);
9631
9632 VkDescriptorSet descriptor_set = {};
9633 VkDescriptorSetAllocateInfo alloc_info = {};
9634 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9635 alloc_info.descriptorSetCount = 1;
9636 alloc_info.descriptorPool = ds_pool;
9637 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009638 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009639 ASSERT_VK_SUCCESS(err);
9640
9641 // Create a buffer to be used for invalid updates
9642 VkBufferCreateInfo buff_ci = {};
9643 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9644 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9645 buff_ci.size = 256;
9646 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9647 VkBuffer buffer;
9648 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
9649 ASSERT_VK_SUCCESS(err);
9650 // Have to bind memory to buffer before descriptor update
9651 VkMemoryAllocateInfo mem_alloc = {};
9652 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9653 mem_alloc.pNext = NULL;
9654 mem_alloc.allocationSize = 256;
9655 mem_alloc.memoryTypeIndex = 0;
9656
9657 VkMemoryRequirements mem_reqs;
9658 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009659 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009660 if (!pass) {
9661 vkDestroyBuffer(m_device->device(), buffer, NULL);
9662 return;
9663 }
9664
9665 VkDeviceMemory mem;
9666 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
9667 ASSERT_VK_SUCCESS(err);
9668 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
9669 ASSERT_VK_SUCCESS(err);
9670
9671 VkDescriptorBufferInfo buff_info = {};
9672 buff_info.buffer = buffer;
9673 // First make offset 1 larger than buffer size
9674 buff_info.offset = 257;
9675 buff_info.range = VK_WHOLE_SIZE;
9676 VkWriteDescriptorSet descriptor_write = {};
9677 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9678 descriptor_write.dstBinding = 0;
9679 descriptor_write.descriptorCount = 1;
9680 descriptor_write.pTexelBufferView = nullptr;
9681 descriptor_write.pBufferInfo = &buff_info;
9682 descriptor_write.pImageInfo = nullptr;
9683
9684 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9685 descriptor_write.dstSet = descriptor_set;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009686 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00959);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009687
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009688 m_errorMonitor->SetUnexpectedError(
9689 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9690 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009691 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9692
9693 m_errorMonitor->VerifyFound();
9694 // Now cause error due to range of 0
9695 buff_info.offset = 0;
9696 buff_info.range = 0;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00960);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009698
9699 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9700
9701 m_errorMonitor->VerifyFound();
9702 // Now cause error due to range exceeding buffer size - offset
9703 buff_info.offset = 128;
9704 buff_info.range = 200;
Tobin Ehlis56e1bc32017-01-02 10:09:07 -07009705 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00961);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009706
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009707 m_errorMonitor->SetUnexpectedError(
9708 "If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER or VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, the offset member of "
9709 "any given element of pBufferInfo must be a multiple of VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009710 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9711
9712 m_errorMonitor->VerifyFound();
Mark Lobodzinski4bb54092016-07-06 14:27:19 -06009713 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009714 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9715 vkDestroyBuffer(m_device->device(), buffer, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -07009716 m_errorMonitor->SetUnexpectedError(
9717 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis585f66d2016-07-01 18:23:58 -06009718 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
9719 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9720}
9721
Tobin Ehlis845887e2017-02-02 19:01:44 -07009722TEST_F(VkLayerTest, DSBufferLimitErrors) {
9723 TEST_DESCRIPTION(
9724 "Attempt to update buffer descriptor set that has VkDescriptorBufferInfo values that violate device limits.\n"
9725 "Test cases include:\n"
9726 "1. range of uniform buffer update exceeds maxUniformBufferRange\n"
9727 "2. offset of uniform buffer update is not multiple of minUniformBufferOffsetAlignment\n"
9728 "3. range of storage buffer update exceeds maxStorageBufferRange\n"
9729 "4. offset of storage buffer update is not multiple of minStorageBufferOffsetAlignment");
9730 VkResult err;
9731
9732 ASSERT_NO_FATAL_FAILURE(InitState());
9733 VkDescriptorPoolSize ds_type_count[2] = {};
9734 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9735 ds_type_count[0].descriptorCount = 1;
9736 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9737 ds_type_count[1].descriptorCount = 1;
9738
9739 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9740 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9741 ds_pool_ci.pNext = NULL;
9742 ds_pool_ci.maxSets = 1;
9743 ds_pool_ci.poolSizeCount = 2;
9744 ds_pool_ci.pPoolSizes = ds_type_count;
9745
9746 VkDescriptorPool ds_pool;
9747 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
9748 ASSERT_VK_SUCCESS(err);
9749
9750 // Create layout with single uniform buffer & single storage buffer descriptor
9751 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
9752 dsl_binding[0].binding = 0;
9753 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9754 dsl_binding[0].descriptorCount = 1;
9755 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
9756 dsl_binding[0].pImmutableSamplers = NULL;
9757 dsl_binding[1].binding = 1;
9758 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9759 dsl_binding[1].descriptorCount = 1;
9760 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
9761 dsl_binding[1].pImmutableSamplers = NULL;
9762
9763 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9764 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9765 ds_layout_ci.pNext = NULL;
9766 ds_layout_ci.bindingCount = 2;
9767 ds_layout_ci.pBindings = dsl_binding;
9768 VkDescriptorSetLayout ds_layout;
9769 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
9770 ASSERT_VK_SUCCESS(err);
9771
9772 VkDescriptorSet descriptor_set = {};
9773 VkDescriptorSetAllocateInfo alloc_info = {};
9774 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9775 alloc_info.descriptorSetCount = 1;
9776 alloc_info.descriptorPool = ds_pool;
9777 alloc_info.pSetLayouts = &ds_layout;
9778 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
9779 ASSERT_VK_SUCCESS(err);
9780
9781 // Create a buffer to be used for invalid updates
9782 auto max_ub_range = m_device->props.limits.maxUniformBufferRange;
9783 auto min_ub_align = m_device->props.limits.minUniformBufferOffsetAlignment;
9784 auto max_sb_range = m_device->props.limits.maxStorageBufferRange;
9785 auto min_sb_align = m_device->props.limits.minStorageBufferOffsetAlignment;
9786 VkBufferCreateInfo ub_ci = {};
9787 ub_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9788 ub_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
9789 ub_ci.size = max_ub_range + 128; // Make buffer bigger than range limit
9790 ub_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9791 VkBuffer uniform_buffer;
9792 err = vkCreateBuffer(m_device->device(), &ub_ci, NULL, &uniform_buffer);
9793 ASSERT_VK_SUCCESS(err);
9794 VkBufferCreateInfo sb_ci = {};
9795 sb_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
9796 sb_ci.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
9797 sb_ci.size = max_sb_range + 128; // Make buffer bigger than range limit
9798 sb_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9799 VkBuffer storage_buffer;
9800 err = vkCreateBuffer(m_device->device(), &sb_ci, NULL, &storage_buffer);
9801 ASSERT_VK_SUCCESS(err);
9802 // Have to bind memory to buffer before descriptor update
9803 VkMemoryAllocateInfo mem_alloc = {};
9804 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9805 mem_alloc.pNext = NULL;
9806 mem_alloc.allocationSize = ub_ci.size + sb_ci.size + 1024; // additional buffer for offset
9807 mem_alloc.memoryTypeIndex = 0;
9808
Cort Stratton77a0d592017-02-17 13:14:13 -08009809 VkMemoryRequirements ub_mem_reqs, sb_mem_reqs;
9810 vkGetBufferMemoryRequirements(m_device->device(), uniform_buffer, &ub_mem_reqs);
9811 bool pass = m_device->phy().set_memory_type(ub_mem_reqs.memoryTypeBits, &mem_alloc, 0);
9812 vkGetBufferMemoryRequirements(m_device->device(), storage_buffer, &sb_mem_reqs);
9813 pass &= m_device->phy().set_memory_type(sb_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009814 if (!pass) {
Tobin Ehlis15c83792017-02-07 10:09:33 -07009815 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009816 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009817 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9818 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009819 return;
9820 }
9821
9822 VkDeviceMemory mem;
9823 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
Tobin Ehlis15c83792017-02-07 10:09:33 -07009824 if (VK_SUCCESS != err) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -07009825 printf(" Failed to allocate memory in DSBufferLimitErrors; skipped.\n");
Tobin Ehlis15c83792017-02-07 10:09:33 -07009826 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9827 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9828 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9829 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9830 return;
9831 }
Tobin Ehlis845887e2017-02-02 19:01:44 -07009832 ASSERT_VK_SUCCESS(err);
9833 err = vkBindBufferMemory(m_device->device(), uniform_buffer, mem, 0);
9834 ASSERT_VK_SUCCESS(err);
Cort Stratton77a0d592017-02-17 13:14:13 -08009835 auto sb_offset = (ub_ci.size + sb_mem_reqs.alignment - 1) & ~(sb_mem_reqs.alignment - 1);
Tobin Ehlis845887e2017-02-02 19:01:44 -07009836 err = vkBindBufferMemory(m_device->device(), storage_buffer, mem, sb_offset);
9837 ASSERT_VK_SUCCESS(err);
9838
9839 VkDescriptorBufferInfo buff_info = {};
9840 buff_info.buffer = uniform_buffer;
9841 buff_info.range = ub_ci.size; // This will exceed limit
9842 VkWriteDescriptorSet descriptor_write = {};
9843 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9844 descriptor_write.dstBinding = 0;
9845 descriptor_write.descriptorCount = 1;
9846 descriptor_write.pTexelBufferView = nullptr;
9847 descriptor_write.pBufferInfo = &buff_info;
9848 descriptor_write.pImageInfo = nullptr;
9849
9850 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
9851 descriptor_write.dstSet = descriptor_set;
9852 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00948);
9853 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9854 m_errorMonitor->VerifyFound();
9855
9856 // Reduce size of range to acceptable limit & cause offset error
9857 buff_info.range = max_ub_range;
9858 buff_info.offset = min_ub_align - 1;
9859 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00944);
9860 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9861 m_errorMonitor->VerifyFound();
9862
9863 // Now break storage updates
9864 buff_info.buffer = storage_buffer;
9865 buff_info.range = sb_ci.size; // This will exceed limit
9866 buff_info.offset = 0; // Reset offset for this update
9867
9868 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
9869 descriptor_write.dstBinding = 1;
9870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00949);
9871 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9872 m_errorMonitor->VerifyFound();
9873
9874 // Reduce size of range to acceptable limit & cause offset error
9875 buff_info.range = max_sb_range;
9876 buff_info.offset = min_sb_align - 1;
9877 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00945);
9878 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
9879 m_errorMonitor->VerifyFound();
9880
9881 vkFreeMemory(m_device->device(), mem, NULL);
9882 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
9883 vkDestroyBuffer(m_device->device(), uniform_buffer, NULL);
9884 vkDestroyBuffer(m_device->device(), storage_buffer, NULL);
9885 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
9886}
9887
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009888TEST_F(VkLayerTest, DSAspectBitsErrors) {
9889 // TODO : Initially only catching case where DEPTH & STENCIL aspect bits
9890 // are set, but could expand this test to hit more cases.
Mark Lobodzinski64318ba2017-01-26 13:34:13 -07009891 TEST_DESCRIPTION(
9892 "Attempt to update descriptor sets for images "
9893 "that do not have correct aspect bits sets.");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009894 VkResult err;
9895
9896 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -07009897 auto depth_format = find_depth_stencil_format(m_device);
9898 if (!depth_format) {
9899 printf(" No Depth + Stencil format found. Skipped.\n");
9900 return;
9901 }
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009902 VkDescriptorPoolSize ds_type_count = {};
9903 ds_type_count.type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9904 ds_type_count.descriptorCount = 1;
9905
9906 VkDescriptorPoolCreateInfo ds_pool_ci = {};
9907 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
9908 ds_pool_ci.pNext = NULL;
9909 ds_pool_ci.maxSets = 5;
9910 ds_pool_ci.poolSizeCount = 1;
9911 ds_pool_ci.pPoolSizes = &ds_type_count;
9912
9913 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009914 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009915 ASSERT_VK_SUCCESS(err);
9916
9917 VkDescriptorSetLayoutBinding dsl_binding = {};
9918 dsl_binding.binding = 0;
9919 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
9920 dsl_binding.descriptorCount = 1;
9921 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
9922 dsl_binding.pImmutableSamplers = NULL;
9923
9924 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
9925 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
9926 ds_layout_ci.pNext = NULL;
9927 ds_layout_ci.bindingCount = 1;
9928 ds_layout_ci.pBindings = &dsl_binding;
9929 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009930 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009931 ASSERT_VK_SUCCESS(err);
9932
9933 VkDescriptorSet descriptor_set = {};
9934 VkDescriptorSetAllocateInfo alloc_info = {};
9935 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
9936 alloc_info.descriptorSetCount = 1;
9937 alloc_info.descriptorPool = ds_pool;
9938 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009939 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009940 ASSERT_VK_SUCCESS(err);
9941
9942 // Create an image to be used for invalid updates
9943 VkImageCreateInfo image_ci = {};
9944 image_ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
9945 image_ci.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -07009946 image_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009947 image_ci.extent.width = 64;
9948 image_ci.extent.height = 64;
9949 image_ci.extent.depth = 1;
9950 image_ci.mipLevels = 1;
9951 image_ci.arrayLayers = 1;
9952 image_ci.samples = VK_SAMPLE_COUNT_1_BIT;
Mark Young2d1fa302017-03-02 10:13:09 -07009953 image_ci.tiling = VK_IMAGE_TILING_OPTIMAL;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009954 image_ci.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
9955 image_ci.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
9956 image_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
9957 VkImage image;
9958 err = vkCreateImage(m_device->device(), &image_ci, NULL, &image);
9959 ASSERT_VK_SUCCESS(err);
9960 // Bind memory to image
9961 VkMemoryRequirements mem_reqs;
9962 VkDeviceMemory image_mem;
9963 bool pass;
9964 VkMemoryAllocateInfo mem_alloc = {};
9965 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
9966 mem_alloc.pNext = NULL;
9967 mem_alloc.allocationSize = 0;
9968 mem_alloc.memoryTypeIndex = 0;
9969 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
9970 mem_alloc.allocationSize = mem_reqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009971 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009972 ASSERT_TRUE(pass);
9973 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &image_mem);
9974 ASSERT_VK_SUCCESS(err);
9975 err = vkBindImageMemory(m_device->device(), image, image_mem, 0);
9976 ASSERT_VK_SUCCESS(err);
9977 // Now create view for image
9978 VkImageViewCreateInfo image_view_ci = {};
9979 image_view_ci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
9980 image_view_ci.image = image;
Tony Barbourf887b162017-03-09 10:06:46 -07009981 image_view_ci.format = depth_format;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009982 image_view_ci.viewType = VK_IMAGE_VIEW_TYPE_2D;
9983 image_view_ci.subresourceRange.layerCount = 1;
9984 image_view_ci.subresourceRange.baseArrayLayer = 0;
9985 image_view_ci.subresourceRange.levelCount = 1;
9986 // Setting both depth & stencil aspect bits is illegal for descriptor
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009987 image_view_ci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009988
9989 VkImageView image_view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -06009990 err = vkCreateImageView(m_device->device(), &image_view_ci, NULL, &image_view);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -06009991 ASSERT_VK_SUCCESS(err);
9992
9993 VkDescriptorImageInfo img_info = {};
9994 img_info.imageView = image_view;
9995 VkWriteDescriptorSet descriptor_write = {};
9996 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
9997 descriptor_write.dstBinding = 0;
9998 descriptor_write.descriptorCount = 1;
9999 descriptor_write.pTexelBufferView = NULL;
10000 descriptor_write.pBufferInfo = NULL;
10001 descriptor_write.pImageInfo = &img_info;
10002 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
10003 descriptor_write.dstSet = descriptor_set;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010004 const char *error_msg =
10005 " please only set either VK_IMAGE_ASPECT_DEPTH_BIT "
10006 "or VK_IMAGE_ASPECT_STENCIL_BIT ";
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010007 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, error_msg);
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010008
10009 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10010
10011 m_errorMonitor->VerifyFound();
10012 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10013 vkDestroyImage(m_device->device(), image, NULL);
10014 vkFreeMemory(m_device->device(), image_mem, NULL);
10015 vkDestroyImageView(m_device->device(), image_view, NULL);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010016 m_errorMonitor->SetUnexpectedError(
10017 "descriptorPool must have been created with the VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT flag");
Tobin Ehlis2fc296b2016-06-15 14:05:27 -060010018 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
10019 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10020}
10021
Karl Schultz6addd812016-02-02 17:17:23 -070010022TEST_F(VkLayerTest, DSTypeMismatch) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010023 // Create DS w/ layout of one type and attempt Update w/ mis-matched type
Karl Schultz6addd812016-02-02 17:17:23 -070010024 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010025
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010026 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10027 " binding #0 with type VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER but update "
10028 "type is VK_DESCRIPTOR_TYPE_SAMPLER");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010029
Tobin Ehlis3b780662015-05-28 12:11:26 -060010030 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010031 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010032 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010033 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10034 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010035
10036 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010037 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10038 ds_pool_ci.pNext = NULL;
10039 ds_pool_ci.maxSets = 1;
10040 ds_pool_ci.poolSizeCount = 1;
10041 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010042
Tobin Ehlis3b780662015-05-28 12:11:26 -060010043 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010044 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010045 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010046 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010047 dsl_binding.binding = 0;
10048 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10049 dsl_binding.descriptorCount = 1;
10050 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10051 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010052
Tony Barboureb254902015-07-15 12:50:33 -060010053 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010054 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10055 ds_layout_ci.pNext = NULL;
10056 ds_layout_ci.bindingCount = 1;
10057 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010058
Tobin Ehlis3b780662015-05-28 12:11:26 -060010059 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010060 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010061 ASSERT_VK_SUCCESS(err);
10062
10063 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010064 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010065 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010066 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010067 alloc_info.descriptorPool = ds_pool;
10068 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010069 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010070 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010071
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010072 VkSamplerCreateInfo sampler_ci = {};
10073 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10074 sampler_ci.pNext = NULL;
10075 sampler_ci.magFilter = VK_FILTER_NEAREST;
10076 sampler_ci.minFilter = VK_FILTER_NEAREST;
10077 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10078 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10079 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10080 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10081 sampler_ci.mipLodBias = 1.0;
10082 sampler_ci.anisotropyEnable = VK_FALSE;
10083 sampler_ci.maxAnisotropy = 1;
10084 sampler_ci.compareEnable = VK_FALSE;
10085 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10086 sampler_ci.minLod = 1.0;
10087 sampler_ci.maxLod = 1.0;
10088 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10089 sampler_ci.unnormalizedCoordinates = VK_FALSE;
10090 VkSampler sampler;
10091 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10092 ASSERT_VK_SUCCESS(err);
10093
10094 VkDescriptorImageInfo info = {};
10095 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010096
10097 VkWriteDescriptorSet descriptor_write;
10098 memset(&descriptor_write, 0, sizeof(descriptor_write));
10099 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010100 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010101 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010102 // This is a mismatched type for the layout which expects BUFFER
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010103 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010104 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010105
10106 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10107
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010108 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010109
Chia-I Wuf7458c52015-10-26 21:10:41 +080010110 vkDestroySampler(m_device->device(), sampler, NULL);
10111 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10112 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010113}
10114
Karl Schultz6addd812016-02-02 17:17:23 -070010115TEST_F(VkLayerTest, DSUpdateOutOfBounds) {
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010116 // For overlapping Update, have arrayIndex exceed that of layout
Karl Schultz6addd812016-02-02 17:17:23 -070010117 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010118
Tobin Ehlisf922ef82016-11-30 10:19:14 -070010119 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00938);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010120
Tobin Ehlis3b780662015-05-28 12:11:26 -060010121 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010122 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010123 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010124 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10125 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010126
10127 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010128 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10129 ds_pool_ci.pNext = NULL;
10130 ds_pool_ci.maxSets = 1;
10131 ds_pool_ci.poolSizeCount = 1;
10132 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060010133
Tobin Ehlis3b780662015-05-28 12:11:26 -060010134 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010135 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010136 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010137
Tony Barboureb254902015-07-15 12:50:33 -060010138 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010139 dsl_binding.binding = 0;
10140 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10141 dsl_binding.descriptorCount = 1;
10142 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10143 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010144
10145 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010146 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10147 ds_layout_ci.pNext = NULL;
10148 ds_layout_ci.bindingCount = 1;
10149 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010150
Tobin Ehlis3b780662015-05-28 12:11:26 -060010151 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010152 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010153 ASSERT_VK_SUCCESS(err);
10154
10155 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010156 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010157 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010158 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010159 alloc_info.descriptorPool = ds_pool;
10160 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010161 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010162 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010163
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010164 // Correctly update descriptor to avoid "NOT_UPDATED" error
10165 VkDescriptorBufferInfo buff_info = {};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010166 buff_info.buffer = VkBuffer(0); // Don't care about buffer handle for this test
Tobin Ehlis30db8f82016-05-05 08:19:48 -060010167 buff_info.offset = 0;
10168 buff_info.range = 1024;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010169
10170 VkWriteDescriptorSet descriptor_write;
10171 memset(&descriptor_write, 0, sizeof(descriptor_write));
10172 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010173 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010174 descriptor_write.dstArrayElement = 1; /* This index out of bounds for the update */
Chia-I Wud50a7d72015-10-26 20:48:51 +080010175 descriptor_write.descriptorCount = 1;
Tobin Ehlis0a43bde2016-05-03 08:31:08 -060010176 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10177 descriptor_write.pBufferInfo = &buff_info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010178
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070010179 m_errorMonitor->SetUnexpectedError("required parameter pDescriptorWrites");
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010180 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10181
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010182 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010183
Chia-I Wuf7458c52015-10-26 21:10:41 +080010184 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10185 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010186}
10187
Karl Schultz6addd812016-02-02 17:17:23 -070010188TEST_F(VkLayerTest, InvalidDSUpdateIndex) {
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010189 // Create layout w/ count of 1 and attempt update to that layout w/ binding index 2
Karl Schultz6addd812016-02-02 17:17:23 -070010190 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010191
Tobin Ehlisc8d352d2016-11-21 10:33:40 -070010192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00936);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010193
Tobin Ehlis3b780662015-05-28 12:11:26 -060010194 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010195 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010196 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010197 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10198 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010199
10200 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010201 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10202 ds_pool_ci.pNext = NULL;
10203 ds_pool_ci.maxSets = 1;
10204 ds_pool_ci.poolSizeCount = 1;
10205 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010206
Tobin Ehlis3b780662015-05-28 12:11:26 -060010207 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010208 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010209 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010210
Tony Barboureb254902015-07-15 12:50:33 -060010211 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010212 dsl_binding.binding = 0;
10213 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10214 dsl_binding.descriptorCount = 1;
10215 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10216 dsl_binding.pImmutableSamplers = NULL;
Tony Barboureb254902015-07-15 12:50:33 -060010217
10218 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010219 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10220 ds_layout_ci.pNext = NULL;
10221 ds_layout_ci.bindingCount = 1;
10222 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010223 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010224 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010225 ASSERT_VK_SUCCESS(err);
10226
10227 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010228 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010229 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010230 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010231 alloc_info.descriptorPool = ds_pool;
10232 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010233 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010234 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010235
Tony Barboureb254902015-07-15 12:50:33 -060010236 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010237 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10238 sampler_ci.pNext = NULL;
10239 sampler_ci.magFilter = VK_FILTER_NEAREST;
10240 sampler_ci.minFilter = VK_FILTER_NEAREST;
10241 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10242 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10243 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10244 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10245 sampler_ci.mipLodBias = 1.0;
10246 sampler_ci.anisotropyEnable = VK_FALSE;
10247 sampler_ci.maxAnisotropy = 1;
10248 sampler_ci.compareEnable = VK_FALSE;
10249 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10250 sampler_ci.minLod = 1.0;
10251 sampler_ci.maxLod = 1.0;
10252 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10253 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tony Barboureb254902015-07-15 12:50:33 -060010254
Tobin Ehlis3b780662015-05-28 12:11:26 -060010255 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010256 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010257 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010258
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010259 VkDescriptorImageInfo info = {};
10260 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010261
10262 VkWriteDescriptorSet descriptor_write;
10263 memset(&descriptor_write, 0, sizeof(descriptor_write));
10264 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010265 descriptor_write.dstSet = descriptorSet;
10266 descriptor_write.dstBinding = 2;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010267 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010268 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010269 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010270 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010271
10272 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10273
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010274 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010275
Chia-I Wuf7458c52015-10-26 21:10:41 +080010276 vkDestroySampler(m_device->device(), sampler, NULL);
10277 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10278 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010279}
10280
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010281TEST_F(VkLayerTest, DSUpdateEmptyBinding) {
10282 // Create layout w/ empty binding and attempt to update it
10283 VkResult err;
10284
10285 ASSERT_NO_FATAL_FAILURE(InitState());
10286
10287 VkDescriptorPoolSize ds_type_count = {};
10288 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10289 ds_type_count.descriptorCount = 1;
10290
10291 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10292 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10293 ds_pool_ci.pNext = NULL;
10294 ds_pool_ci.maxSets = 1;
10295 ds_pool_ci.poolSizeCount = 1;
10296 ds_pool_ci.pPoolSizes = &ds_type_count;
10297
10298 VkDescriptorPool ds_pool;
10299 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
10300 ASSERT_VK_SUCCESS(err);
10301
10302 VkDescriptorSetLayoutBinding dsl_binding = {};
10303 dsl_binding.binding = 0;
10304 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10305 dsl_binding.descriptorCount = 0;
10306 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10307 dsl_binding.pImmutableSamplers = NULL;
10308
10309 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10310 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10311 ds_layout_ci.pNext = NULL;
10312 ds_layout_ci.bindingCount = 1;
10313 ds_layout_ci.pBindings = &dsl_binding;
10314 VkDescriptorSetLayout ds_layout;
10315 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
10316 ASSERT_VK_SUCCESS(err);
10317
10318 VkDescriptorSet descriptor_set;
10319 VkDescriptorSetAllocateInfo alloc_info = {};
10320 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
10321 alloc_info.descriptorSetCount = 1;
10322 alloc_info.descriptorPool = ds_pool;
10323 alloc_info.pSetLayouts = &ds_layout;
10324 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
10325 ASSERT_VK_SUCCESS(err);
10326
10327 VkSamplerCreateInfo sampler_ci = {};
10328 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10329 sampler_ci.magFilter = VK_FILTER_NEAREST;
10330 sampler_ci.minFilter = VK_FILTER_NEAREST;
10331 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10332 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10333 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10334 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10335 sampler_ci.mipLodBias = 1.0;
10336 sampler_ci.maxAnisotropy = 1;
10337 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10338 sampler_ci.minLod = 1.0;
10339 sampler_ci.maxLod = 1.0;
10340 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10341
10342 VkSampler sampler;
10343 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
10344 ASSERT_VK_SUCCESS(err);
10345
10346 VkDescriptorImageInfo info = {};
10347 info.sampler = sampler;
10348
10349 VkWriteDescriptorSet descriptor_write;
10350 memset(&descriptor_write, 0, sizeof(descriptor_write));
10351 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
10352 descriptor_write.dstSet = descriptor_set;
10353 descriptor_write.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010354 descriptor_write.descriptorCount = 1; // Lie here to avoid parameter_validation error
Tobin Ehlise202b2d2016-11-21 10:36:16 -070010355 // This is the wrong type, but empty binding error will be flagged first
10356 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10357 descriptor_write.pImageInfo = &info;
10358
10359 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02348);
10360 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10361 m_errorMonitor->VerifyFound();
10362
10363 vkDestroySampler(m_device->device(), sampler, NULL);
10364 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10365 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
10366}
10367
Karl Schultz6addd812016-02-02 17:17:23 -070010368TEST_F(VkLayerTest, InvalidDSUpdateStruct) {
10369 // Call UpdateDS w/ struct type other than valid VK_STRUCTUR_TYPE_UPDATE_*
10370 // types
10371 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010372
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010373 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 -060010374
Tobin Ehlis3b780662015-05-28 12:11:26 -060010375 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski209b5292015-09-17 09:44:05 -060010376
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010377 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010378 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10379 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010380
10381 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010382 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10383 ds_pool_ci.pNext = NULL;
10384 ds_pool_ci.maxSets = 1;
10385 ds_pool_ci.poolSizeCount = 1;
10386 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010387
Tobin Ehlis3b780662015-05-28 12:11:26 -060010388 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010389 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010390 ASSERT_VK_SUCCESS(err);
Tony Barboureb254902015-07-15 12:50:33 -060010391 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010392 dsl_binding.binding = 0;
10393 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10394 dsl_binding.descriptorCount = 1;
10395 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10396 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010397
Tony Barboureb254902015-07-15 12:50:33 -060010398 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010399 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10400 ds_layout_ci.pNext = NULL;
10401 ds_layout_ci.bindingCount = 1;
10402 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010403
Tobin Ehlis3b780662015-05-28 12:11:26 -060010404 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010405 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010406 ASSERT_VK_SUCCESS(err);
10407
10408 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010409 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010410 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010411 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010412 alloc_info.descriptorPool = ds_pool;
10413 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010414 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010415 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010416
Tony Barboureb254902015-07-15 12:50:33 -060010417 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010418 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10419 sampler_ci.pNext = NULL;
10420 sampler_ci.magFilter = VK_FILTER_NEAREST;
10421 sampler_ci.minFilter = VK_FILTER_NEAREST;
10422 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10423 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10424 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10425 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10426 sampler_ci.mipLodBias = 1.0;
10427 sampler_ci.anisotropyEnable = VK_FALSE;
10428 sampler_ci.maxAnisotropy = 1;
10429 sampler_ci.compareEnable = VK_FALSE;
10430 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10431 sampler_ci.minLod = 1.0;
10432 sampler_ci.maxLod = 1.0;
10433 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10434 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010435 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010436 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010437 ASSERT_VK_SUCCESS(err);
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010438
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010439 VkDescriptorImageInfo info = {};
10440 info.sampler = sampler;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010441
10442 VkWriteDescriptorSet descriptor_write;
10443 memset(&descriptor_write, 0, sizeof(descriptor_write));
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010444 descriptor_write.sType = (VkStructureType)0x99999999; /* Intentionally broken struct type */
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010445 descriptor_write.dstSet = descriptorSet;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010446 descriptor_write.descriptorCount = 1;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010447 // This is the wrong type, but out of bounds will be flagged first
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010448 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
Courtney Goeltzenleuchter4cb6d922015-10-23 13:38:14 -060010449 descriptor_write.pImageInfo = &info;
Chia-I Wu9d00ed72015-05-25 16:27:55 +080010450
10451 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10452
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010453 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010454
Chia-I Wuf7458c52015-10-26 21:10:41 +080010455 vkDestroySampler(m_device->device(), sampler, NULL);
10456 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10457 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010458}
10459
Karl Schultz6addd812016-02-02 17:17:23 -070010460TEST_F(VkLayerTest, SampleDescriptorUpdateError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010461 // Create a single Sampler descriptor and send it an invalid Sampler
Karl Schultz6addd812016-02-02 17:17:23 -070010462 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010463
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070010464 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00942);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010465
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010466 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010467 // TODO : Farm Descriptor setup code to helper function(s) to reduce copied
10468 // code
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010469 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010470 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLER;
10471 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010472
10473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10475 ds_pool_ci.pNext = NULL;
10476 ds_pool_ci.maxSets = 1;
10477 ds_pool_ci.poolSizeCount = 1;
10478 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010479
10480 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010481 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010482 ASSERT_VK_SUCCESS(err);
10483
10484 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010485 dsl_binding.binding = 0;
10486 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10487 dsl_binding.descriptorCount = 1;
10488 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10489 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010490
10491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10493 ds_layout_ci.pNext = NULL;
10494 ds_layout_ci.bindingCount = 1;
10495 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010496 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010498 ASSERT_VK_SUCCESS(err);
10499
10500 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010501 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010502 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010503 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010504 alloc_info.descriptorPool = ds_pool;
10505 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010506 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010507 ASSERT_VK_SUCCESS(err);
10508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010509 VkSampler sampler = (VkSampler)((size_t)0xbaadbeef); // Sampler with invalid handle
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010510
10511 VkDescriptorImageInfo descriptor_info;
10512 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10513 descriptor_info.sampler = sampler;
10514
10515 VkWriteDescriptorSet descriptor_write;
10516 memset(&descriptor_write, 0, sizeof(descriptor_write));
10517 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010518 descriptor_write.dstSet = descriptorSet;
10519 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010520 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010521 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10522 descriptor_write.pImageInfo = &descriptor_info;
10523
10524 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10525
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010526 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010527
Chia-I Wuf7458c52015-10-26 21:10:41 +080010528 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10529 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010530}
10531
Karl Schultz6addd812016-02-02 17:17:23 -070010532TEST_F(VkLayerTest, ImageViewDescriptorUpdateError) {
10533 // Create a single combined Image/Sampler descriptor and send it an invalid
10534 // imageView
10535 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010536
Karl Schultzf78bcdd2016-11-30 12:36:01 -070010537 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00943);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010538
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010539 ASSERT_NO_FATAL_FAILURE(InitState());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010540 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010541 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10542 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010543
10544 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010545 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10546 ds_pool_ci.pNext = NULL;
10547 ds_pool_ci.maxSets = 1;
10548 ds_pool_ci.poolSizeCount = 1;
10549 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010550
10551 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010552 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010553 ASSERT_VK_SUCCESS(err);
10554
10555 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010556 dsl_binding.binding = 0;
10557 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10558 dsl_binding.descriptorCount = 1;
10559 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10560 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010561
10562 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010563 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10564 ds_layout_ci.pNext = NULL;
10565 ds_layout_ci.bindingCount = 1;
10566 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010567 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010568 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010569 ASSERT_VK_SUCCESS(err);
10570
10571 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010572 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010573 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010574 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010575 alloc_info.descriptorPool = ds_pool;
10576 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010577 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010578 ASSERT_VK_SUCCESS(err);
10579
10580 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010581 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10582 sampler_ci.pNext = NULL;
10583 sampler_ci.magFilter = VK_FILTER_NEAREST;
10584 sampler_ci.minFilter = VK_FILTER_NEAREST;
10585 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10586 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10587 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10588 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10589 sampler_ci.mipLodBias = 1.0;
10590 sampler_ci.anisotropyEnable = VK_FALSE;
10591 sampler_ci.maxAnisotropy = 1;
10592 sampler_ci.compareEnable = VK_FALSE;
10593 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10594 sampler_ci.minLod = 1.0;
10595 sampler_ci.maxLod = 1.0;
10596 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10597 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010598
10599 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010600 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010601 ASSERT_VK_SUCCESS(err);
10602
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010603 VkImageView view = (VkImageView)((size_t)0xbaadbeef); // invalid imageView object
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010604
10605 VkDescriptorImageInfo descriptor_info;
10606 memset(&descriptor_info, 0, sizeof(VkDescriptorImageInfo));
10607 descriptor_info.sampler = sampler;
10608 descriptor_info.imageView = view;
10609
10610 VkWriteDescriptorSet descriptor_write;
10611 memset(&descriptor_write, 0, sizeof(descriptor_write));
10612 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010613 descriptor_write.dstSet = descriptorSet;
10614 descriptor_write.dstBinding = 0;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010615 descriptor_write.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010616 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
10617 descriptor_write.pImageInfo = &descriptor_info;
10618
10619 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10620
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010621 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010622
Chia-I Wuf7458c52015-10-26 21:10:41 +080010623 vkDestroySampler(m_device->device(), sampler, NULL);
10624 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10625 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060010626}
10627
Karl Schultz6addd812016-02-02 17:17:23 -070010628TEST_F(VkLayerTest, CopyDescriptorUpdateErrors) {
10629 // Create DS w/ layout of 2 types, write update 1 and attempt to copy-update
10630 // into the other
10631 VkResult err;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010632
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010633 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10634 " binding #1 with type "
10635 "VK_DESCRIPTOR_TYPE_SAMPLER. Types do "
10636 "not match.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010637
Tobin Ehlis04356f92015-10-27 16:35:27 -060010638 ASSERT_NO_FATAL_FAILURE(InitState());
Karl Schultz6addd812016-02-02 17:17:23 -070010639 // VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010640 VkDescriptorPoolSize ds_type_count[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010641 ds_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10642 ds_type_count[0].descriptorCount = 1;
10643 ds_type_count[1].type = VK_DESCRIPTOR_TYPE_SAMPLER;
10644 ds_type_count[1].descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010645
10646 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010647 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10648 ds_pool_ci.pNext = NULL;
10649 ds_pool_ci.maxSets = 1;
10650 ds_pool_ci.poolSizeCount = 2;
10651 ds_pool_ci.pPoolSizes = ds_type_count;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010652
10653 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010654 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010655 ASSERT_VK_SUCCESS(err);
10656 VkDescriptorSetLayoutBinding dsl_binding[2] = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010657 dsl_binding[0].binding = 0;
10658 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10659 dsl_binding[0].descriptorCount = 1;
10660 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
10661 dsl_binding[0].pImmutableSamplers = NULL;
10662 dsl_binding[1].binding = 1;
10663 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10664 dsl_binding[1].descriptorCount = 1;
10665 dsl_binding[1].stageFlags = VK_SHADER_STAGE_ALL;
10666 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010667
10668 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010669 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10670 ds_layout_ci.pNext = NULL;
10671 ds_layout_ci.bindingCount = 2;
10672 ds_layout_ci.pBindings = dsl_binding;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010673
10674 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010675 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010676 ASSERT_VK_SUCCESS(err);
10677
10678 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010679 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010680 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010681 alloc_info.descriptorSetCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010682 alloc_info.descriptorPool = ds_pool;
10683 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010684 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010685 ASSERT_VK_SUCCESS(err);
10686
10687 VkSamplerCreateInfo sampler_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010688 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
10689 sampler_ci.pNext = NULL;
10690 sampler_ci.magFilter = VK_FILTER_NEAREST;
10691 sampler_ci.minFilter = VK_FILTER_NEAREST;
10692 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
10693 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10694 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10695 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
10696 sampler_ci.mipLodBias = 1.0;
10697 sampler_ci.anisotropyEnable = VK_FALSE;
10698 sampler_ci.maxAnisotropy = 1;
10699 sampler_ci.compareEnable = VK_FALSE;
10700 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
10701 sampler_ci.minLod = 1.0;
10702 sampler_ci.maxLod = 1.0;
10703 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
10704 sampler_ci.unnormalizedCoordinates = VK_FALSE;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010705
10706 VkSampler sampler;
Chia-I Wuf7458c52015-10-26 21:10:41 +080010707 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010708 ASSERT_VK_SUCCESS(err);
10709
10710 VkDescriptorImageInfo info = {};
10711 info.sampler = sampler;
10712
10713 VkWriteDescriptorSet descriptor_write;
10714 memset(&descriptor_write, 0, sizeof(VkWriteDescriptorSet));
10715 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010716 descriptor_write.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010717 descriptor_write.dstBinding = 1; // SAMPLER binding from layout above
Chia-I Wud50a7d72015-10-26 20:48:51 +080010718 descriptor_write.descriptorCount = 1;
Tobin Ehlis04356f92015-10-27 16:35:27 -060010719 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER;
10720 descriptor_write.pImageInfo = &info;
10721 // This write update should succeed
10722 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
10723 // Now perform a copy update that fails due to type mismatch
10724 VkCopyDescriptorSet copy_ds_update;
10725 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10726 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10727 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010728 copy_ds_update.srcBinding = 1; // Copy from SAMPLER binding
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010729 copy_ds_update.dstSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010730 copy_ds_update.dstBinding = 0; // ERROR : copy to UNIFORM binding
10731 copy_ds_update.descriptorCount = 1; // copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010732 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10733
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010734 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010735 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010736 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 -060010737 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10738 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10739 copy_ds_update.srcSet = descriptorSet;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010740 copy_ds_update.srcBinding = 3; // ERROR : Invalid binding for matching layout
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010741 copy_ds_update.dstSet = descriptorSet;
10742 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010743 copy_ds_update.descriptorCount = 1; // Copy 1 descriptor
Tobin Ehlis04356f92015-10-27 16:35:27 -060010744 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10745
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010746 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010747
Tobin Ehlis04356f92015-10-27 16:35:27 -060010748 // Now perform a copy update that fails due to binding out of bounds
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010749 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
10750 " binding#1 with offset index of 1 plus "
10751 "update array offset of 0 and update of "
10752 "5 descriptors oversteps total number "
10753 "of descriptors in set: 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010754
Tobin Ehlis04356f92015-10-27 16:35:27 -060010755 memset(&copy_ds_update, 0, sizeof(VkCopyDescriptorSet));
10756 copy_ds_update.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET;
10757 copy_ds_update.srcSet = descriptorSet;
10758 copy_ds_update.srcBinding = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010759 copy_ds_update.dstSet = descriptorSet;
10760 copy_ds_update.dstBinding = 0;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010761 copy_ds_update.descriptorCount = 5; // ERROR copy 5 descriptors (out of bounds for layout)
Tobin Ehlis04356f92015-10-27 16:35:27 -060010762 vkUpdateDescriptorSets(m_device->device(), 0, NULL, 1, &copy_ds_update);
10763
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010764 m_errorMonitor->VerifyFound();
Tobin Ehlis04356f92015-10-27 16:35:27 -060010765
Chia-I Wuf7458c52015-10-26 21:10:41 +080010766 vkDestroySampler(m_device->device(), sampler, NULL);
10767 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10768 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis04356f92015-10-27 16:35:27 -060010769}
10770
Karl Schultz6addd812016-02-02 17:17:23 -070010771TEST_F(VkLayerTest, NumSamplesMismatch) {
10772 // Create CommandBuffer where MSAA samples doesn't match RenderPass
10773 // sampleCount
10774 VkResult err;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010775
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010776 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Num samples mismatch! ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060010777
Tobin Ehlis3b780662015-05-28 12:11:26 -060010778 ASSERT_NO_FATAL_FAILURE(InitState());
10779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chia-I Wu1b99bb22015-10-27 19:25:11 +080010780 VkDescriptorPoolSize ds_type_count = {};
Tony Barboureb254902015-07-15 12:50:33 -060010781 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010782 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010783
10784 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010785 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10786 ds_pool_ci.pNext = NULL;
10787 ds_pool_ci.maxSets = 1;
10788 ds_pool_ci.poolSizeCount = 1;
10789 ds_pool_ci.pPoolSizes = &ds_type_count;
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060010790
Tobin Ehlis3b780662015-05-28 12:11:26 -060010791 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010792 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010793 ASSERT_VK_SUCCESS(err);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010794
Tony Barboureb254902015-07-15 12:50:33 -060010795 VkDescriptorSetLayoutBinding dsl_binding = {};
Chia-I Wud46e6ae2015-10-31 00:31:16 +080010796 dsl_binding.binding = 0;
Tony Barboureb254902015-07-15 12:50:33 -060010797 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Chia-I Wu02124482015-11-06 06:42:02 +080010798 dsl_binding.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060010799 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10800 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010801
Tony Barboureb254902015-07-15 12:50:33 -060010802 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10803 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10804 ds_layout_ci.pNext = NULL;
Chia-I Wud50a7d72015-10-26 20:48:51 +080010805 ds_layout_ci.bindingCount = 1;
Jon Ashburn6e23c1f2015-12-30 18:01:16 -070010806 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060010807
Tobin Ehlis3b780662015-05-28 12:11:26 -060010808 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010809 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010810 ASSERT_VK_SUCCESS(err);
10811
10812 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080010813 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080010814 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070010815 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060010816 alloc_info.descriptorPool = ds_pool;
10817 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010818 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010819 ASSERT_VK_SUCCESS(err);
10820
Tony Barboureb254902015-07-15 12:50:33 -060010821 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010822 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070010823 pipe_ms_state_ci.pNext = NULL;
10824 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
10825 pipe_ms_state_ci.sampleShadingEnable = 0;
10826 pipe_ms_state_ci.minSampleShading = 1.0;
10827 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010828
Tony Barboureb254902015-07-15 12:50:33 -060010829 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070010830 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10831 pipeline_layout_ci.pNext = NULL;
10832 pipeline_layout_ci.setLayoutCount = 1;
10833 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis3b780662015-05-28 12:11:26 -060010834
10835 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010836 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis3b780662015-05-28 12:11:26 -060010837 ASSERT_VK_SUCCESS(err);
10838
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010839 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010840 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 -060010841 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010842 VkPipelineObj pipe(m_device);
10843 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060010844 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060010845 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060010846 pipe.SetMSAA(&pipe_ms_state_ci);
10847 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010848
Tony Barbour552f6c02016-12-21 14:34:07 -070010849 m_commandBuffer->BeginCommandBuffer();
10850 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010851 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis3b780662015-05-28 12:11:26 -060010852
Rene Lindsay3bdc7a42017-01-06 13:20:15 -070010853 VkViewport viewport = {0, 0, 16, 16, 0, 1};
10854 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
10855 VkRect2D scissor = {{0, 0}, {16, 16}};
10856 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
10857
Mark Young29927482016-05-04 14:38:51 -060010858 // Render triangle (the error should trigger on the attempt to draw).
10859 Draw(3, 1, 0, 0);
10860
10861 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010862 m_commandBuffer->EndRenderPass();
10863 m_commandBuffer->EndCommandBuffer();
Mark Young29927482016-05-04 14:38:51 -060010864
Chris Forbes8f36a8a2016-04-07 13:21:07 +120010865 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060010866
Chia-I Wuf7458c52015-10-26 21:10:41 +080010867 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10868 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10869 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis49eb23d2015-05-22 12:38:55 -060010870}
Mark Young29927482016-05-04 14:38:51 -060010871
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010872TEST_F(VkLayerTest, RenderPassIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010873 TEST_DESCRIPTION(
10874 "Hit RenderPass incompatible cases. "
10875 "Initial case is drawing with an active renderpass that's "
10876 "not compatible with the bound pipeline state object's creation renderpass");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010877 VkResult err;
10878
10879 ASSERT_NO_FATAL_FAILURE(InitState());
10880 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10881
10882 VkDescriptorSetLayoutBinding dsl_binding = {};
10883 dsl_binding.binding = 0;
10884 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10885 dsl_binding.descriptorCount = 1;
10886 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
10887 dsl_binding.pImmutableSamplers = NULL;
10888
10889 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
10890 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
10891 ds_layout_ci.pNext = NULL;
10892 ds_layout_ci.bindingCount = 1;
10893 ds_layout_ci.pBindings = &dsl_binding;
10894
10895 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010896 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010897 ASSERT_VK_SUCCESS(err);
10898
10899 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
10900 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
10901 pipeline_layout_ci.pNext = NULL;
10902 pipeline_layout_ci.setLayoutCount = 1;
10903 pipeline_layout_ci.pSetLayouts = &ds_layout;
10904
10905 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010906 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010907 ASSERT_VK_SUCCESS(err);
10908
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010909 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070010910 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 -060010911 // but add it to be able to run on more devices
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010912 // Create a renderpass that will be incompatible with default renderpass
10913 VkAttachmentReference attach = {};
10914 attach.layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
10915 VkAttachmentReference color_att = {};
10916 color_att.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
10917 VkSubpassDescription subpass = {};
10918 subpass.inputAttachmentCount = 1;
10919 subpass.pInputAttachments = &attach;
10920 subpass.colorAttachmentCount = 1;
10921 subpass.pColorAttachments = &color_att;
10922 VkRenderPassCreateInfo rpci = {};
10923 rpci.subpassCount = 1;
10924 rpci.pSubpasses = &subpass;
10925 rpci.attachmentCount = 1;
10926 VkAttachmentDescription attach_desc = {};
10927 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
Cody Northropbd16af12016-06-21 09:25:48 -060010928 // Format incompatible with PSO RP color attach format B8G8R8A8_UNORM
10929 attach_desc.format = VK_FORMAT_R8G8B8A8_UNORM;
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010930 rpci.pAttachments = &attach_desc;
10931 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
10932 VkRenderPass rp;
10933 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
10934 VkPipelineObj pipe(m_device);
10935 pipe.AddShader(&vs);
10936 pipe.AddShader(&fs);
10937 pipe.AddColorAttachment();
10938 VkViewport view_port = {};
10939 m_viewports.push_back(view_port);
10940 pipe.SetViewport(m_viewports);
10941 VkRect2D rect = {};
10942 m_scissors.push_back(rect);
10943 pipe.SetScissor(m_scissors);
10944 pipe.CreateVKPipeline(pipeline_layout, renderPass());
10945
10946 VkCommandBufferInheritanceInfo cbii = {};
10947 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
10948 cbii.renderPass = rp;
10949 cbii.subpass = 0;
10950 VkCommandBufferBeginInfo cbbi = {};
10951 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
10952 cbbi.pInheritanceInfo = &cbii;
10953 vkBeginCommandBuffer(m_commandBuffer->handle(), &cbbi);
10954 VkRenderPassBeginInfo rpbi = {};
10955 rpbi.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
10956 rpbi.framebuffer = m_framebuffer;
10957 rpbi.renderPass = rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010958 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
10959 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010960
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010961 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, " is incompatible w/ gfx pipeline ");
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010962 // Render triangle (the error should trigger on the attempt to draw).
10963 Draw(3, 1, 0, 0);
10964
10965 // Finalize recording of the command buffer
Tony Barbour552f6c02016-12-21 14:34:07 -070010966 m_commandBuffer->EndRenderPass();
10967 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis85aa15a2016-06-15 10:52:37 -060010968
10969 m_errorMonitor->VerifyFound();
10970
10971 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
10972 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
10973 vkDestroyRenderPass(m_device->device(), rp, NULL);
10974}
10975
Mark Youngc89c6312016-03-31 16:03:20 -060010976TEST_F(VkLayerTest, NumBlendAttachMismatch) {
10977 // Create Pipeline where the number of blend attachments doesn't match the
10978 // number of color attachments. In this case, we don't add any color
10979 // blend attachments even though we have a color attachment.
10980 VkResult err;
10981
Tobin Ehlis974c0d92017-02-01 13:31:22 -070010982 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02109);
Mark Youngc89c6312016-03-31 16:03:20 -060010983
10984 ASSERT_NO_FATAL_FAILURE(InitState());
10985 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
10986 VkDescriptorPoolSize ds_type_count = {};
10987 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
10988 ds_type_count.descriptorCount = 1;
10989
10990 VkDescriptorPoolCreateInfo ds_pool_ci = {};
10991 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
10992 ds_pool_ci.pNext = NULL;
10993 ds_pool_ci.maxSets = 1;
10994 ds_pool_ci.poolSizeCount = 1;
10995 ds_pool_ci.pPoolSizes = &ds_type_count;
10996
10997 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060010998 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Mark Youngc89c6312016-03-31 16:03:20 -060010999 ASSERT_VK_SUCCESS(err);
11000
11001 VkDescriptorSetLayoutBinding dsl_binding = {};
11002 dsl_binding.binding = 0;
11003 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11004 dsl_binding.descriptorCount = 1;
11005 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11006 dsl_binding.pImmutableSamplers = NULL;
11007
11008 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11009 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11010 ds_layout_ci.pNext = NULL;
11011 ds_layout_ci.bindingCount = 1;
11012 ds_layout_ci.pBindings = &dsl_binding;
11013
11014 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011015 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011016 ASSERT_VK_SUCCESS(err);
11017
11018 VkDescriptorSet descriptorSet;
11019 VkDescriptorSetAllocateInfo alloc_info = {};
11020 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11021 alloc_info.descriptorSetCount = 1;
11022 alloc_info.descriptorPool = ds_pool;
11023 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011024 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Mark Youngc89c6312016-03-31 16:03:20 -060011025 ASSERT_VK_SUCCESS(err);
11026
11027 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011028 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Youngc89c6312016-03-31 16:03:20 -060011029 pipe_ms_state_ci.pNext = NULL;
11030 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11031 pipe_ms_state_ci.sampleShadingEnable = 0;
11032 pipe_ms_state_ci.minSampleShading = 1.0;
11033 pipe_ms_state_ci.pSampleMask = NULL;
11034
11035 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11036 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11037 pipeline_layout_ci.pNext = NULL;
11038 pipeline_layout_ci.setLayoutCount = 1;
11039 pipeline_layout_ci.pSetLayouts = &ds_layout;
11040
11041 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011042 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Mark Youngc89c6312016-03-31 16:03:20 -060011043 ASSERT_VK_SUCCESS(err);
11044
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011045 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011046 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 -060011047 // but add it to be able to run on more devices
Mark Youngc89c6312016-03-31 16:03:20 -060011048 VkPipelineObj pipe(m_device);
11049 pipe.AddShader(&vs);
11050 pipe.AddShader(&fs);
11051 pipe.SetMSAA(&pipe_ms_state_ci);
11052 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011053 m_errorMonitor->VerifyFound();
Mark Youngc89c6312016-03-31 16:03:20 -060011054
11055 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11056 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11057 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
11058}
Mark Young29927482016-05-04 14:38:51 -060011059
Mark Muellerd4914412016-06-13 17:52:06 -060011060TEST_F(VkLayerTest, MissingClearAttachment) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011061 TEST_DESCRIPTION(
11062 "Points to a wrong colorAttachment index in a VkClearAttachment "
11063 "structure passed to vkCmdClearAttachments");
Cody Northropc31a84f2016-08-22 10:41:47 -060011064 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070011065 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01114);
Mark Muellerd4914412016-06-13 17:52:06 -060011066
11067 VKTriangleTest(bindStateVertShaderText, bindStateFragShaderText, BsoFailCmdClearAttachments);
11068 m_errorMonitor->VerifyFound();
11069}
11070
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011071TEST_F(VkLayerTest, CmdClearAttachmentTests) {
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011072 TEST_DESCRIPTION("Various tests for validating usage of vkCmdClearAttachments");
11073 VkResult err;
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011074
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011075 ASSERT_NO_FATAL_FAILURE(InitState());
11076 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011077
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011078 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011079 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11080 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011081
11082 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011083 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11084 ds_pool_ci.pNext = NULL;
11085 ds_pool_ci.maxSets = 1;
11086 ds_pool_ci.poolSizeCount = 1;
11087 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011088
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011089 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011090 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011091 ASSERT_VK_SUCCESS(err);
11092
Tony Barboureb254902015-07-15 12:50:33 -060011093 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011094 dsl_binding.binding = 0;
11095 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11096 dsl_binding.descriptorCount = 1;
11097 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11098 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011099
Tony Barboureb254902015-07-15 12:50:33 -060011100 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011101 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11102 ds_layout_ci.pNext = NULL;
11103 ds_layout_ci.bindingCount = 1;
11104 ds_layout_ci.pBindings = &dsl_binding;
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011105
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011106 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011107 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011108 ASSERT_VK_SUCCESS(err);
11109
11110 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011111 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011112 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011113 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011114 alloc_info.descriptorPool = ds_pool;
11115 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011116 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011117 ASSERT_VK_SUCCESS(err);
11118
Tony Barboureb254902015-07-15 12:50:33 -060011119 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011120 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011121 pipe_ms_state_ci.pNext = NULL;
11122 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_4_BIT;
11123 pipe_ms_state_ci.sampleShadingEnable = 0;
11124 pipe_ms_state_ci.minSampleShading = 1.0;
11125 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011126
Tony Barboureb254902015-07-15 12:50:33 -060011127 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011128 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11129 pipeline_layout_ci.pNext = NULL;
11130 pipeline_layout_ci.setLayoutCount = 1;
11131 pipeline_layout_ci.pSetLayouts = &ds_layout;
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011132
11133 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011134 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011135 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski209b5292015-09-17 09:44:05 -060011136
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011137 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Karl Schultzbdb75952016-04-19 11:36:49 -060011138 // We shouldn't need a fragment shader but add it to be able to run
Karl Schultz6addd812016-02-02 17:17:23 -070011139 // on more devices
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011140 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011141
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011142 VkPipelineObj pipe(m_device);
11143 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011144 pipe.AddShader(&fs);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011145 pipe.SetMSAA(&pipe_ms_state_ci);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011146 m_errorMonitor->SetUnexpectedError(
11147 "If pColorBlendState is not NULL, The attachmentCount member of pColorBlendState must be equal to the colorAttachmentCount "
11148 "used to create subpass");
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011149 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011150
Tony Barbour552f6c02016-12-21 14:34:07 -070011151 m_commandBuffer->BeginCommandBuffer();
11152 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011153
Karl Schultz6addd812016-02-02 17:17:23 -070011154 // Main thing we care about for this test is that the VkImage obj we're
11155 // clearing matches Color Attachment of FB
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011156 // Also pass down other dummy params to keep driver and paramchecker happy
Courtney Goeltzenleuchterc9323e02015-10-15 16:51:05 -060011157 VkClearAttachment color_attachment;
11158 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11159 color_attachment.clearValue.color.float32[0] = 1.0;
11160 color_attachment.clearValue.color.float32[1] = 1.0;
11161 color_attachment.clearValue.color.float32[2] = 1.0;
11162 color_attachment.clearValue.color.float32[3] = 1.0;
11163 color_attachment.colorAttachment = 0;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011164 VkClearRect clear_rect = {{{0, 0}, {(uint32_t)m_width, (uint32_t)m_height}}};
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011165
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011166 // Call for full-sized FB Color attachment prior to issuing a Draw
11167 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070011168 "vkCmdClearAttachments() issued on command buffer object ");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011169 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011170 m_errorMonitor->VerifyFound();
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011171
Mark Lobodzinskie0d1f4f2017-01-18 15:44:53 -070011172 clear_rect.rect.extent.width = renderPassBeginInfo().renderArea.extent.width + 4;
11173 clear_rect.rect.extent.height = clear_rect.rect.extent.height / 2;
11174 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01115);
11175 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
11176 m_errorMonitor->VerifyFound();
11177
11178 clear_rect.rect.extent.width = (uint32_t)m_width / 2;
11179 clear_rect.layerCount = 2;
11180 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01116);
11181 vkCmdClearAttachments(m_commandBuffer->GetBufferHandle(), 1, &color_attachment, 1, &clear_rect);
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011182 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011183
Chia-I Wuf7458c52015-10-26 21:10:41 +080011184 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11185 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11186 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis53eddda2015-07-01 16:46:13 -060011187}
11188
Karl Schultz6addd812016-02-02 17:17:23 -070011189TEST_F(VkLayerTest, VtxBufferBadIndex) {
11190 VkResult err;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011191
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011192 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11193 "but no vertex buffers are attached to this Pipeline State Object");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060011194
Tobin Ehlis502480b2015-06-24 15:53:07 -060011195 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisd332f282015-10-02 11:00:56 -060011196 ASSERT_NO_FATAL_FAILURE(InitViewport());
Tobin Ehlis502480b2015-06-24 15:53:07 -060011197 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Tony Barboureb254902015-07-15 12:50:33 -060011198
Chia-I Wu1b99bb22015-10-27 19:25:11 +080011199 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011200 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11201 ds_type_count.descriptorCount = 1;
Tony Barboureb254902015-07-15 12:50:33 -060011202
11203 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011204 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11205 ds_pool_ci.pNext = NULL;
11206 ds_pool_ci.maxSets = 1;
11207 ds_pool_ci.poolSizeCount = 1;
11208 ds_pool_ci.pPoolSizes = &ds_type_count;
Tony Barboureb254902015-07-15 12:50:33 -060011209
Courtney Goeltzenleuchterfe908d32015-09-16 16:12:45 -060011210 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011211 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011212 ASSERT_VK_SUCCESS(err);
11213
Tony Barboureb254902015-07-15 12:50:33 -060011214 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011215 dsl_binding.binding = 0;
11216 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
11217 dsl_binding.descriptorCount = 1;
11218 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
11219 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011220
Tony Barboureb254902015-07-15 12:50:33 -060011221 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011222 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11223 ds_layout_ci.pNext = NULL;
11224 ds_layout_ci.bindingCount = 1;
11225 ds_layout_ci.pBindings = &dsl_binding;
Tony Barboureb254902015-07-15 12:50:33 -060011226
Tobin Ehlis502480b2015-06-24 15:53:07 -060011227 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011228 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011229 ASSERT_VK_SUCCESS(err);
11230
11231 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080011232 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080011233 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070011234 alloc_info.descriptorSetCount = 1;
Courtney Goeltzenleuchterbee18a92015-10-23 14:21:05 -060011235 alloc_info.descriptorPool = ds_pool;
11236 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011237 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011238 ASSERT_VK_SUCCESS(err);
11239
Tony Barboureb254902015-07-15 12:50:33 -060011240 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011241 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070011242 pipe_ms_state_ci.pNext = NULL;
11243 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11244 pipe_ms_state_ci.sampleShadingEnable = 0;
11245 pipe_ms_state_ci.minSampleShading = 1.0;
11246 pipe_ms_state_ci.pSampleMask = NULL;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011247
Tony Barboureb254902015-07-15 12:50:33 -060011248 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070011249 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11250 pipeline_layout_ci.pNext = NULL;
11251 pipeline_layout_ci.setLayoutCount = 1;
11252 pipeline_layout_ci.pSetLayouts = &ds_layout;
11253 VkPipelineLayout pipeline_layout;
Tobin Ehlis502480b2015-06-24 15:53:07 -060011254
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011255 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011256 ASSERT_VK_SUCCESS(err);
11257
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011258 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011259 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 -060011260 // but add it to be able to run on more devices
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011261 VkPipelineObj pipe(m_device);
11262 pipe.AddShader(&vs);
Tony Barbour1c94d372015-08-06 11:21:08 -060011263 pipe.AddShader(&fs);
Mark Youngc89c6312016-03-31 16:03:20 -060011264 pipe.AddColorAttachment();
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011265 pipe.SetMSAA(&pipe_ms_state_ci);
Tobin Ehlisd332f282015-10-02 11:00:56 -060011266 pipe.SetViewport(m_viewports);
11267 pipe.SetScissor(m_scissors);
Tony Barbour62e1a5b2015-08-06 10:16:07 -060011268 pipe.CreateVKPipeline(pipeline_layout, renderPass());
Tony Barbourfe3351b2015-07-28 10:17:20 -060011269
Tony Barbour552f6c02016-12-21 14:34:07 -070011270 m_commandBuffer->BeginCommandBuffer();
11271 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011272 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisf7bf4502015-09-09 15:12:35 -060011273 // Don't care about actual data, just need to get to draw to flag error
11274 static const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011275 VkConstantBufferObj vbo(m_device, sizeof(vbo_data), sizeof(float), (const void *)&vbo_data);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011276 BindVertexBuffer(&vbo, (VkDeviceSize)0, 1); // VBO idx 1, but no VBO in PSO
Courtney Goeltzenleuchter08c26372015-09-23 12:31:50 -060011277 Draw(1, 0, 0, 0);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011278
Chris Forbes8f36a8a2016-04-07 13:21:07 +120011279 m_errorMonitor->VerifyFound();
Mike Stroyand1c84a52015-08-18 14:40:24 -060011280
Chia-I Wuf7458c52015-10-26 21:10:41 +080011281 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11282 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
11283 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Tobin Ehlis502480b2015-06-24 15:53:07 -060011284}
Mark Muellerdfe37552016-07-07 14:47:42 -060011285
Mark Mueller2ee294f2016-08-04 12:59:48 -060011286TEST_F(VkLayerTest, MismatchCountQueueCreateRequestedFeature) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011287 TEST_DESCRIPTION(
11288 "Use an invalid count in a vkEnumeratePhysicalDevices call."
11289 "Use invalid Queue Family Index in vkCreateDevice");
Cody Northropc31a84f2016-08-22 10:41:47 -060011290 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Mueller2ee294f2016-08-04 12:59:48 -060011291
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011292 const char *invalid_queueFamilyIndex_message =
11293 "Invalid queue create request in vkCreateDevice(). Invalid "
11294 "queueFamilyIndex ";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011295
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011296 const char *unavailable_feature_message = "While calling vkCreateDevice(), requesting feature #";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011297
Mark Mueller880fce52016-08-17 15:23:23 -060011298 // The following test fails with recent NVidia drivers.
11299 // By the time core_validation is reached, the NVidia
11300 // driver has sanitized the invalid condition and core_validation
11301 // is not introduced to the failure condition. This is not the case
11302 // with AMD and Mesa drivers. Futher investigation is required
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011303 // uint32_t count = static_cast<uint32_t>(~0);
11304 // VkPhysicalDevice physical_device;
11305 // vkEnumeratePhysicalDevices(instance(), &count, &physical_device);
11306 // m_errorMonitor->VerifyFound();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011307
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011308 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queueFamilyIndex_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011309 float queue_priority = 0.0;
11310
11311 VkDeviceQueueCreateInfo queue_create_info = {};
11312 queue_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11313 queue_create_info.queueCount = 1;
11314 queue_create_info.pQueuePriorities = &queue_priority;
11315 queue_create_info.queueFamilyIndex = static_cast<uint32_t>(~0);
11316
11317 VkPhysicalDeviceFeatures features = m_device->phy().features();
11318 VkDevice testDevice;
11319 VkDeviceCreateInfo device_create_info = {};
11320 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11321 device_create_info.queueCreateInfoCount = 1;
11322 device_create_info.pQueueCreateInfos = &queue_create_info;
11323 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011324 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011325 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11326 m_errorMonitor->VerifyFound();
11327
11328 queue_create_info.queueFamilyIndex = 1;
11329
11330 unsigned feature_count = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
11331 VkBool32 *feature_array = reinterpret_cast<VkBool32 *>(&features);
11332 for (unsigned i = 0; i < feature_count; i++) {
11333 if (VK_FALSE == feature_array[i]) {
11334 feature_array[i] = VK_TRUE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011335 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, unavailable_feature_message);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011336 device_create_info.pEnabledFeatures = &features;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011337 m_errorMonitor->SetUnexpectedError(
11338 "You requested features that are unavailable on this device. You should first query feature availability by "
11339 "calling vkGetPhysicalDeviceFeatures().");
11340 m_errorMonitor->SetUnexpectedError("Failed to create device chain.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011341 vkCreateDevice(gpu(), &device_create_info, nullptr, &testDevice);
11342 m_errorMonitor->VerifyFound();
11343 break;
11344 }
11345 }
11346}
11347
Tobin Ehlis16edf082016-11-21 12:33:49 -070011348TEST_F(VkLayerTest, InvalidQueryPoolCreate) {
11349 TEST_DESCRIPTION("Attempt to create a query pool for PIPELINE_STATISTICS without enabling pipeline stats for the device.");
11350
11351 ASSERT_NO_FATAL_FAILURE(InitState());
11352
11353 const std::vector<VkQueueFamilyProperties> queue_props = m_device->queue_props;
11354 std::vector<VkDeviceQueueCreateInfo> queue_info;
11355 queue_info.reserve(queue_props.size());
11356 std::vector<std::vector<float>> queue_priorities;
11357 for (uint32_t i = 0; i < (uint32_t)queue_props.size(); i++) {
11358 VkDeviceQueueCreateInfo qi{};
11359 qi.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
11360 qi.queueFamilyIndex = i;
11361 qi.queueCount = queue_props[i].queueCount;
11362 queue_priorities.emplace_back(qi.queueCount, 0.0f);
11363 qi.pQueuePriorities = queue_priorities[i].data();
11364 queue_info.push_back(qi);
11365 }
11366
11367 std::vector<const char *> device_extension_names;
11368
11369 VkDevice local_device;
11370 VkDeviceCreateInfo device_create_info = {};
11371 auto features = m_device->phy().features();
11372 // Intentionally disable pipeline stats
11373 features.pipelineStatisticsQuery = VK_FALSE;
11374 device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
11375 device_create_info.pNext = NULL;
11376 device_create_info.queueCreateInfoCount = queue_info.size();
11377 device_create_info.pQueueCreateInfos = queue_info.data();
11378 device_create_info.enabledLayerCount = 0;
11379 device_create_info.ppEnabledLayerNames = NULL;
11380 device_create_info.pEnabledFeatures = &features;
11381 VkResult err = vkCreateDevice(gpu(), &device_create_info, nullptr, &local_device);
11382 ASSERT_VK_SUCCESS(err);
11383
11384 VkQueryPoolCreateInfo qpci{};
11385 qpci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11386 qpci.queryType = VK_QUERY_TYPE_PIPELINE_STATISTICS;
11387 qpci.queryCount = 1;
11388 VkQueryPool query_pool;
11389
11390 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01006);
11391 vkCreateQueryPool(local_device, &qpci, nullptr, &query_pool);
11392 m_errorMonitor->VerifyFound();
11393
11394 vkDestroyDevice(local_device, nullptr);
11395}
11396
Mark Mueller2ee294f2016-08-04 12:59:48 -060011397TEST_F(VkLayerTest, InvalidQueueIndexInvalidQuery) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011398 TEST_DESCRIPTION(
11399 "Use an invalid queue index in a vkCmdWaitEvents call."
11400 "End a command buffer with a query still in progress.");
Mark Mueller2ee294f2016-08-04 12:59:48 -060011401
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011402 const char *invalid_queue_index =
11403 "was created with sharingMode of VK_SHARING_MODE_EXCLUSIVE. If one "
11404 "of src- or dstQueueFamilyIndex is VK_QUEUE_FAMILY_IGNORED, both "
11405 "must be.";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011406
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011407 const char *invalid_query = "Ending command buffer with in progress query: queryPool 0x";
Mark Mueller2ee294f2016-08-04 12:59:48 -060011408
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011409 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_queue_index);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011410
11411 ASSERT_NO_FATAL_FAILURE(InitState());
11412
11413 VkEvent event;
11414 VkEventCreateInfo event_create_info{};
11415 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
11416 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
11417
Mark Mueller2ee294f2016-08-04 12:59:48 -060011418 VkQueue queue = VK_NULL_HANDLE;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011419 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011420
Tony Barbour552f6c02016-12-21 14:34:07 -070011421 m_commandBuffer->BeginCommandBuffer();
Mark Mueller2ee294f2016-08-04 12:59:48 -060011422
11423 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011424 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 -060011425 ASSERT_TRUE(image.initialized());
11426 VkImageMemoryBarrier img_barrier = {};
11427 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11428 img_barrier.pNext = NULL;
11429 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
11430 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
11431 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11432 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
11433 img_barrier.image = image.handle();
11434 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
Mark Lobodzinski2a74c5c2016-08-17 13:26:28 -060011435
11436 // QueueFamilyIndex must be VK_QUEUE_FAMILY_IGNORED, this verifies
11437 // that layer validation catches the case when it is not.
11438 img_barrier.dstQueueFamilyIndex = 0;
Mark Mueller2ee294f2016-08-04 12:59:48 -060011439 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11440 img_barrier.subresourceRange.baseArrayLayer = 0;
11441 img_barrier.subresourceRange.baseMipLevel = 0;
11442 img_barrier.subresourceRange.layerCount = 1;
11443 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011444 vkCmdWaitEvents(m_commandBuffer->handle(), 1, &event, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0,
11445 nullptr, 0, nullptr, 1, &img_barrier);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011446 m_errorMonitor->VerifyFound();
11447
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011448 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_query);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011449
11450 VkQueryPool query_pool;
11451 VkQueryPoolCreateInfo query_pool_create_info = {};
11452 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
11453 query_pool_create_info.queryType = VK_QUERY_TYPE_OCCLUSION;
11454 query_pool_create_info.queryCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011455 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011456
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011457 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0 /*startQuery*/, 1 /*queryCount*/);
Mark Mueller2ee294f2016-08-04 12:59:48 -060011458 vkCmdBeginQuery(m_commandBuffer->handle(), query_pool, 0, 0);
11459
11460 vkEndCommandBuffer(m_commandBuffer->handle());
11461 m_errorMonitor->VerifyFound();
11462
11463 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
11464 vkDestroyEvent(m_device->device(), event, nullptr);
11465}
11466
Mark Muellerdfe37552016-07-07 14:47:42 -060011467TEST_F(VkLayerTest, VertexBufferInvalid) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011468 TEST_DESCRIPTION(
11469 "Submit a command buffer using deleted vertex buffer, "
11470 "delete a buffer twice, use an invalid offset for each "
11471 "buffer type, and attempt to bind a null buffer");
Mark Muellerdfe37552016-07-07 14:47:42 -060011472
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011473 const char *deleted_buffer_in_command_buffer =
11474 "Cannot submit cmd buffer "
11475 "using deleted buffer ";
11476 const char *invalid_offset_message =
11477 "vkBindBufferMemory(): "
11478 "memoryOffset is 0x";
11479 const char *invalid_storage_buffer_offset_message =
11480 "vkBindBufferMemory(): "
11481 "storage memoryOffset "
11482 "is 0x";
11483 const char *invalid_texel_buffer_offset_message =
11484 "vkBindBufferMemory(): "
11485 "texel memoryOffset "
11486 "is 0x";
11487 const char *invalid_uniform_buffer_offset_message =
11488 "vkBindBufferMemory(): "
11489 "uniform memoryOffset "
11490 "is 0x";
Mark Muellerdfe37552016-07-07 14:47:42 -060011491
11492 ASSERT_NO_FATAL_FAILURE(InitState());
11493 ASSERT_NO_FATAL_FAILURE(InitViewport());
11494 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
11495
11496 VkPipelineMultisampleStateCreateInfo pipe_ms_state_ci = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011497 pipe_ms_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
Mark Muellerdfe37552016-07-07 14:47:42 -060011498 pipe_ms_state_ci.pNext = NULL;
11499 pipe_ms_state_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
11500 pipe_ms_state_ci.sampleShadingEnable = 0;
11501 pipe_ms_state_ci.minSampleShading = 1.0;
11502 pipe_ms_state_ci.pSampleMask = nullptr;
11503
11504 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11505 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11506 VkPipelineLayout pipeline_layout;
11507
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011508 VkResult err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, nullptr, &pipeline_layout);
Mark Muellerdfe37552016-07-07 14:47:42 -060011509 ASSERT_VK_SUCCESS(err);
11510
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011511 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
11512 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Muellerdfe37552016-07-07 14:47:42 -060011513 VkPipelineObj pipe(m_device);
11514 pipe.AddShader(&vs);
11515 pipe.AddShader(&fs);
11516 pipe.AddColorAttachment();
11517 pipe.SetMSAA(&pipe_ms_state_ci);
11518 pipe.SetViewport(m_viewports);
11519 pipe.SetScissor(m_scissors);
11520 pipe.CreateVKPipeline(pipeline_layout, renderPass());
11521
Tony Barbour552f6c02016-12-21 14:34:07 -070011522 m_commandBuffer->BeginCommandBuffer();
11523 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011524 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Mark Muellerdfe37552016-07-07 14:47:42 -060011525
11526 {
11527 // Create and bind a vertex buffer in a reduced scope, which will cause
11528 // it to be deleted upon leaving this scope
11529 const float vbo_data[3] = {1.f, 0.f, 1.f};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011530 VkVerticesObj draw_verticies(m_device, 1, 1, sizeof(vbo_data), 3, vbo_data);
Mark Muellerdfe37552016-07-07 14:47:42 -060011531 draw_verticies.BindVertexBuffers(m_commandBuffer->handle());
11532 draw_verticies.AddVertexInputToPipe(pipe);
11533 }
11534
11535 Draw(1, 0, 0, 0);
11536
Tony Barbour552f6c02016-12-21 14:34:07 -070011537 m_commandBuffer->EndRenderPass();
11538 m_commandBuffer->EndCommandBuffer();
Mark Muellerdfe37552016-07-07 14:47:42 -060011539
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011540 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, deleted_buffer_in_command_buffer);
Mark Muellerdfe37552016-07-07 14:47:42 -060011541 QueueCommandBuffer(false);
11542 m_errorMonitor->VerifyFound();
11543
11544 {
11545 // Create and bind a vertex buffer in a reduced scope, and delete it
11546 // twice, the second through the destructor
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011547 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eDoubleDelete);
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011548 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00680);
Mark Muellerdfe37552016-07-07 14:47:42 -060011549 buffer_test.TestDoubleDestroy();
11550 }
11551 m_errorMonitor->VerifyFound();
11552
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011553 m_errorMonitor->SetUnexpectedError("value of pCreateInfo->usage must not be 0");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011554 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidMemoryOffset)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011555 // Create and bind a memory buffer with an invalid offset.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011556 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011557 m_errorMonitor->SetUnexpectedError(
11558 "If buffer was created with the VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT or VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT, "
11559 "memoryOffset must be a multiple of VkPhysicalDeviceLimits::minTexelBufferOffsetAlignment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011560 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidMemoryOffset);
11561 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011562 m_errorMonitor->VerifyFound();
11563 }
11564
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011565 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset,
11566 VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011567 // Create and bind a memory buffer with an invalid offset again,
11568 // but look for a texel buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011569 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_texel_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011570 m_errorMonitor->SetUnexpectedError(
11571 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11572 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011573 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11574 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011575 m_errorMonitor->VerifyFound();
11576 }
11577
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011578 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011579 // Create and bind a memory buffer with an invalid offset again, but
11580 // look for a uniform buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011581 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_uniform_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011582 m_errorMonitor->SetUnexpectedError(
11583 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11584 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011585 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11586 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011587 m_errorMonitor->VerifyFound();
11588 }
11589
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011590 if (VkBufferTest::GetTestConditionValid(m_device, VkBufferTest::eInvalidDeviceOffset, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT)) {
Mark Muellerdfe37552016-07-07 14:47:42 -060011591 // Create and bind a memory buffer with an invalid offset again, but
11592 // look for a storage buffer message.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, invalid_storage_buffer_offset_message);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011594 m_errorMonitor->SetUnexpectedError(
11595 "memoryOffset must be an integer multiple of the alignment member of the VkMemoryRequirements structure returned from "
11596 "a call to vkGetBufferMemoryRequirements with buffer");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011597 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eInvalidDeviceOffset);
11598 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011599 m_errorMonitor->VerifyFound();
11600 }
11601
11602 {
11603 // Attempt to bind a null buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011604 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00799);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011605 m_errorMonitor->SetUnexpectedError("required parameter memory specified as VK_NULL_HANDLE");
11606 m_errorMonitor->SetUnexpectedError("memory must be a valid VkDeviceMemory handle");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011607 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eBindNullBuffer);
11608 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011609 m_errorMonitor->VerifyFound();
11610 }
11611
11612 {
11613 // Attempt to use an invalid handle to delete a buffer.
Karl Schultzf78bcdd2016-11-30 12:36:01 -070011614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00622);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011615 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VkBufferTest::eFreeInvalidHandle);
11616 (void)buffer_test;
Mark Muellerdfe37552016-07-07 14:47:42 -060011617 }
11618 m_errorMonitor->VerifyFound();
11619
11620 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
11621}
11622
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011623// INVALID_IMAGE_LAYOUT tests (one other case is hit by MapMemWithoutHostVisibleBit and not here)
11624TEST_F(VkLayerTest, InvalidImageLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011625 TEST_DESCRIPTION(
11626 "Hit all possible validation checks associated with the "
11627 "DRAWSTATE_INVALID_IMAGE_LAYOUT enum. Generally these involve having"
11628 "images in the wrong layout when they're copied or transitioned.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011629 // 3 in ValidateCmdBufImageLayouts
11630 // * -1 Attempt to submit cmd buf w/ deleted image
11631 // * -2 Cmd buf submit of image w/ layout not matching first use w/ subresource
11632 // * -3 Cmd buf submit of image w/ layout not matching first use w/o subresource
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011633
11634 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070011635 auto depth_format = find_depth_stencil_format(m_device);
11636 if (!depth_format) {
11637 printf(" No Depth + Stencil format found. Skipped.\n");
11638 return;
11639 }
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011640 // Create src & dst images to use for copy operations
11641 VkImage src_image;
11642 VkImage dst_image;
Cort3b021012016-12-07 12:00:57 -080011643 VkImage depth_image;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011644
11645 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
11646 const int32_t tex_width = 32;
11647 const int32_t tex_height = 32;
11648
11649 VkImageCreateInfo image_create_info = {};
11650 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
11651 image_create_info.pNext = NULL;
11652 image_create_info.imageType = VK_IMAGE_TYPE_2D;
11653 image_create_info.format = tex_format;
11654 image_create_info.extent.width = tex_width;
11655 image_create_info.extent.height = tex_height;
11656 image_create_info.extent.depth = 1;
11657 image_create_info.mipLevels = 1;
11658 image_create_info.arrayLayers = 4;
11659 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
11660 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
11661 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Cort3b021012016-12-07 12:00:57 -080011662 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011663 image_create_info.flags = 0;
11664
11665 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &src_image);
11666 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011667 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011668 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dst_image);
11669 ASSERT_VK_SUCCESS(err);
Cort3b021012016-12-07 12:00:57 -080011670 image_create_info.format = VK_FORMAT_D32_SFLOAT;
11671 image_create_info.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
11672 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &depth_image);
11673 ASSERT_VK_SUCCESS(err);
11674
11675 // Allocate memory
11676 VkMemoryRequirements img_mem_reqs = {};
Cort530cf382016-12-08 09:59:47 -080011677 VkMemoryAllocateInfo mem_alloc = {};
Cort3b021012016-12-07 12:00:57 -080011678 VkDeviceMemory src_image_mem, dst_image_mem, depth_image_mem;
Cort530cf382016-12-08 09:59:47 -080011679 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
11680 mem_alloc.pNext = NULL;
11681 mem_alloc.allocationSize = 0;
11682 mem_alloc.memoryTypeIndex = 0;
Cort3b021012016-12-07 12:00:57 -080011683
11684 vkGetImageMemoryRequirements(m_device->device(), src_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011685 mem_alloc.allocationSize = img_mem_reqs.size;
11686 bool pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011687 ASSERT_TRUE(pass);
Cort530cf382016-12-08 09:59:47 -080011688 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &src_image_mem);
Cort3b021012016-12-07 12:00:57 -080011689 ASSERT_VK_SUCCESS(err);
11690
11691 vkGetImageMemoryRequirements(m_device->device(), dst_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011692 mem_alloc.allocationSize = img_mem_reqs.size;
11693 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011694 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011695 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &dst_image_mem);
Cort3b021012016-12-07 12:00:57 -080011696 ASSERT_VK_SUCCESS(err);
11697
11698 vkGetImageMemoryRequirements(m_device->device(), depth_image, &img_mem_reqs);
Cort530cf382016-12-08 09:59:47 -080011699 mem_alloc.allocationSize = img_mem_reqs.size;
11700 pass = m_device->phy().set_memory_type(img_mem_reqs.memoryTypeBits, &mem_alloc, 0);
Cort3b021012016-12-07 12:00:57 -080011701 ASSERT_VK_SUCCESS(err);
Cort530cf382016-12-08 09:59:47 -080011702 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &depth_image_mem);
Cort3b021012016-12-07 12:00:57 -080011703 ASSERT_VK_SUCCESS(err);
11704
11705 err = vkBindImageMemory(m_device->device(), src_image, src_image_mem, 0);
11706 ASSERT_VK_SUCCESS(err);
11707 err = vkBindImageMemory(m_device->device(), dst_image, dst_image_mem, 0);
11708 ASSERT_VK_SUCCESS(err);
11709 err = vkBindImageMemory(m_device->device(), depth_image, depth_image_mem, 0);
11710 ASSERT_VK_SUCCESS(err);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011711
Tony Barbour552f6c02016-12-21 14:34:07 -070011712 m_commandBuffer->BeginCommandBuffer();
Cort530cf382016-12-08 09:59:47 -080011713 VkImageCopy copy_region;
11714 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11715 copy_region.srcSubresource.mipLevel = 0;
11716 copy_region.srcSubresource.baseArrayLayer = 0;
11717 copy_region.srcSubresource.layerCount = 1;
11718 copy_region.srcOffset.x = 0;
11719 copy_region.srcOffset.y = 0;
11720 copy_region.srcOffset.z = 0;
11721 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11722 copy_region.dstSubresource.mipLevel = 0;
11723 copy_region.dstSubresource.baseArrayLayer = 0;
11724 copy_region.dstSubresource.layerCount = 1;
11725 copy_region.dstOffset.x = 0;
11726 copy_region.dstOffset.y = 0;
11727 copy_region.dstOffset.z = 0;
11728 copy_region.extent.width = 1;
11729 copy_region.extent.height = 1;
11730 copy_region.extent.depth = 1;
11731
11732 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11733 "Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011734 m_errorMonitor->SetUnexpectedError("Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011735 m_commandBuffer->CopyImage(src_image, VK_IMAGE_LAYOUT_GENERAL, dst_image, VK_IMAGE_LAYOUT_GENERAL, 1, &copy_region);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011736 m_errorMonitor->VerifyFound();
11737 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011738 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11739 "Cannot copy from an image whose source layout is "
11740 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11741 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011742 m_errorMonitor->SetUnexpectedError(
11743 "srcImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011744 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 -060011745 m_errorMonitor->VerifyFound();
11746 // Final src error is due to bad layout type
11747 m_errorMonitor->SetDesiredFailureMsg(
11748 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11749 "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 -070011750 m_errorMonitor->SetUnexpectedError(
11751 "Cannot copy from an image whose source layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11752 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011753 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 -060011754 m_errorMonitor->VerifyFound();
11755 // Now verify same checks for dst
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11757 "Layout for output image should be TRANSFER_DST_OPTIMAL instead of GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011758 m_errorMonitor->SetUnexpectedError("Layout for input image should be TRANSFER_SRC_OPTIMAL instead of GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011759 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 -060011760 m_errorMonitor->VerifyFound();
11761 // Now cause error due to src image layout changing
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011762 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11763 "Cannot copy from an image whose dest layout is "
11764 "VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current "
11765 "layout VK_IMAGE_LAYOUT_GENERAL.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070011766 m_errorMonitor->SetUnexpectedError(
11767 "dstImageLayout must be either of VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL");
Cort530cf382016-12-08 09:59:47 -080011768 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 -060011769 m_errorMonitor->VerifyFound();
11770 m_errorMonitor->SetDesiredFailureMsg(
11771 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11772 "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 -070011773 m_errorMonitor->SetUnexpectedError(
11774 "Cannot copy from an image whose dest layout is VK_IMAGE_LAYOUT_UNDEFINED and doesn't match the current layout "
11775 "VK_IMAGE_LAYOUT_GENERAL.");
Cort530cf382016-12-08 09:59:47 -080011776 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 -060011777 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011778
Cort3b021012016-12-07 12:00:57 -080011779 // Convert dst and depth images to TRANSFER_DST for subsequent tests
11780 VkImageMemoryBarrier transfer_dst_image_barrier[1] = {};
11781 transfer_dst_image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
11782 transfer_dst_image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
11783 transfer_dst_image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
11784 transfer_dst_image_barrier[0].srcAccessMask = 0;
11785 transfer_dst_image_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
11786 transfer_dst_image_barrier[0].image = dst_image;
11787 transfer_dst_image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11788 transfer_dst_image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
11789 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11790 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11791 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11792 transfer_dst_image_barrier[0].image = depth_image;
11793 transfer_dst_image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
11794 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11795 NULL, 0, NULL, 1, transfer_dst_image_barrier);
11796
11797 // Cause errors due to clearing with invalid image layouts
Cort530cf382016-12-08 09:59:47 -080011798 VkClearColorValue color_clear_value = {};
11799 VkImageSubresourceRange clear_range;
11800 clear_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
11801 clear_range.baseMipLevel = 0;
11802 clear_range.baseArrayLayer = 0;
11803 clear_range.layerCount = 1;
11804 clear_range.levelCount = 1;
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011805
Cort3b021012016-12-07 12:00:57 -080011806 // Fail due to explicitly prohibited layout for color clear (only GENERAL and TRANSFER_DST are permitted).
11807 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11808 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01086);
11809 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011810 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_UNDEFINED, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011811 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011812 // Fail due to provided layout not matching actual current layout for color clear.
11813 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01085);
Cort530cf382016-12-08 09:59:47 -080011814 m_commandBuffer->ClearColorImage(dst_image, VK_IMAGE_LAYOUT_GENERAL, &color_clear_value, 1, &clear_range);
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011815 m_errorMonitor->VerifyFound();
Cort3b021012016-12-07 12:00:57 -080011816
Cort530cf382016-12-08 09:59:47 -080011817 VkClearDepthStencilValue depth_clear_value = {};
11818 clear_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
Cort3b021012016-12-07 12:00:57 -080011819
11820 // Fail due to explicitly prohibited layout for depth clear (only GENERAL and TRANSFER_DST are permitted).
11821 // Since the image is currently not in UNDEFINED layout, this will emit two errors.
11822 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01101);
11823 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011824 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_UNDEFINED, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011825 m_errorMonitor->VerifyFound();
11826 // Fail due to provided layout not matching actual current layout for depth clear.
11827 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01100);
Cort530cf382016-12-08 09:59:47 -080011828 m_commandBuffer->ClearDepthStencilImage(depth_image, VK_IMAGE_LAYOUT_GENERAL, &depth_clear_value, 1, &clear_range);
Cort3b021012016-12-07 12:00:57 -080011829 m_errorMonitor->VerifyFound();
Slawomir Cygan4f73b7f2016-11-28 19:17:38 +010011830
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011831 // Now cause error due to bad image layout transition in PipelineBarrier
11832 VkImageMemoryBarrier image_barrier[1] = {};
Cort3b021012016-12-07 12:00:57 -080011833 image_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011834 image_barrier[0].oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
Cort3b021012016-12-07 12:00:57 -080011835 image_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011836 image_barrier[0].image = src_image;
Cort3b021012016-12-07 12:00:57 -080011837 image_barrier[0].subresourceRange.layerCount = image_create_info.arrayLayers;
11838 image_barrier[0].subresourceRange.levelCount = image_create_info.mipLevels;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011839 image_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11841 "You cannot transition the layout of aspect 1 from "
11842 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL when "
11843 "current layout is VK_IMAGE_LAYOUT_GENERAL.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011844 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, 0,
11845 NULL, 0, NULL, 1, image_barrier);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011846 m_errorMonitor->VerifyFound();
11847
11848 // Finally some layout errors at RenderPass create time
11849 // Just hacking in specific state to get to the errors we want so don't copy this unless you know what you're doing.
11850 VkAttachmentReference attach = {};
11851 // perf warning for GENERAL layout w/ non-DS input attachment
11852 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11853 VkSubpassDescription subpass = {};
11854 subpass.inputAttachmentCount = 1;
11855 subpass.pInputAttachments = &attach;
11856 VkRenderPassCreateInfo rpci = {};
11857 rpci.subpassCount = 1;
11858 rpci.pSubpasses = &subpass;
11859 rpci.attachmentCount = 1;
11860 VkAttachmentDescription attach_desc = {};
11861 attach_desc.format = VK_FORMAT_UNDEFINED;
11862 rpci.pAttachments = &attach_desc;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011863 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011864 VkRenderPass rp;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011865 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11866 "Layout for input attachment is GENERAL but should be READ_ONLY_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011867 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11868 m_errorMonitor->VerifyFound();
11869 // error w/ non-general layout
11870 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11871
11872 m_errorMonitor->SetDesiredFailureMsg(
11873 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11874 "Layout for input attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be READ_ONLY_OPTIMAL or GENERAL.");
11875 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11876 m_errorMonitor->VerifyFound();
11877 subpass.inputAttachmentCount = 0;
11878 subpass.colorAttachmentCount = 1;
11879 subpass.pColorAttachments = &attach;
11880 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11881 // perf warning for GENERAL layout on color attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011882 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11883 "Layout for color attachment is GENERAL but should be COLOR_ATTACHMENT_OPTIMAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011884 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11885 m_errorMonitor->VerifyFound();
11886 // error w/ non-color opt or GENERAL layout for color attachment
11887 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
11888 m_errorMonitor->SetDesiredFailureMsg(
11889 VK_DEBUG_REPORT_ERROR_BIT_EXT,
11890 "Layout for color attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be COLOR_ATTACHMENT_OPTIMAL or GENERAL.");
11891 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11892 m_errorMonitor->VerifyFound();
11893 subpass.colorAttachmentCount = 0;
11894 subpass.pDepthStencilAttachment = &attach;
11895 attach.layout = VK_IMAGE_LAYOUT_GENERAL;
11896 // perf warning for GENERAL layout on DS attachment
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011897 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT,
11898 "GENERAL layout for depth attachment may not give optimal performance.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011899 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11900 m_errorMonitor->VerifyFound();
11901 // error w/ non-ds opt or GENERAL layout for color attachment
11902 attach.layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060011903 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11904 "Layout for depth attachment is VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL but can only be "
11905 "DEPTH_STENCIL_ATTACHMENT_OPTIMAL, DEPTH_STENCIL_READ_ONLY_OPTIMAL or GENERAL.");
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011906 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11907 m_errorMonitor->VerifyFound();
Tobin Ehlis1efce022016-05-11 10:40:34 -060011908 // For this error we need a valid renderpass so create default one
11909 attach.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11910 attach.attachment = 0;
Tony Barbourf887b162017-03-09 10:06:46 -070011911 attach_desc.format = depth_format;
Tobin Ehlis1efce022016-05-11 10:40:34 -060011912 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
11913 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
11914 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
11915 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
11916 // Can't do a CLEAR load on READ_ONLY initialLayout
11917 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
11918 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
11919 attach_desc.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070011920 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
11921 " with invalid first layout "
11922 "VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_"
11923 "ONLY_OPTIMAL");
Tobin Ehlis1efce022016-05-11 10:40:34 -060011924 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
11925 m_errorMonitor->VerifyFound();
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011926
Cort3b021012016-12-07 12:00:57 -080011927 vkFreeMemory(m_device->device(), src_image_mem, NULL);
11928 vkFreeMemory(m_device->device(), dst_image_mem, NULL);
11929 vkFreeMemory(m_device->device(), depth_image_mem, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011930 vkDestroyImage(m_device->device(), src_image, NULL);
11931 vkDestroyImage(m_device->device(), dst_image, NULL);
Cort3b021012016-12-07 12:00:57 -080011932 vkDestroyImage(m_device->device(), depth_image, NULL);
Tobin Ehlisc555a3c2016-05-04 14:08:34 -060011933}
Tobin Ehlisd8d89182016-07-18 20:13:11 -060011934
Tobin Ehlise0936662016-10-11 08:10:51 -060011935TEST_F(VkLayerTest, InvalidStorageImageLayout) {
11936 TEST_DESCRIPTION("Attempt to update a STORAGE_IMAGE descriptor w/o GENERAL layout.");
11937 VkResult err;
11938
11939 ASSERT_NO_FATAL_FAILURE(InitState());
11940
11941 const VkFormat tex_format = VK_FORMAT_R8G8B8A8_UNORM;
11942 VkImageTiling tiling;
11943 VkFormatProperties format_properties;
11944 vkGetPhysicalDeviceFormatProperties(gpu(), tex_format, &format_properties);
11945 if (format_properties.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11946 tiling = VK_IMAGE_TILING_LINEAR;
11947 } else if (format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) {
11948 tiling = VK_IMAGE_TILING_OPTIMAL;
11949 } else {
Dave Houlton584d51e2017-02-16 12:52:54 -070011950 printf(" Device does not support VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT; skipped.\n");
Tobin Ehlise0936662016-10-11 08:10:51 -060011951 return;
11952 }
11953
11954 VkDescriptorPoolSize ds_type = {};
11955 ds_type.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11956 ds_type.descriptorCount = 1;
11957
11958 VkDescriptorPoolCreateInfo ds_pool_ci = {};
11959 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
11960 ds_pool_ci.maxSets = 1;
11961 ds_pool_ci.poolSizeCount = 1;
11962 ds_pool_ci.pPoolSizes = &ds_type;
11963 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
11964
11965 VkDescriptorPool ds_pool;
11966 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
11967 ASSERT_VK_SUCCESS(err);
11968
11969 VkDescriptorSetLayoutBinding dsl_binding = {};
11970 dsl_binding.binding = 0;
11971 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
11972 dsl_binding.descriptorCount = 1;
11973 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
11974 dsl_binding.pImmutableSamplers = NULL;
11975
11976 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
11977 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
11978 ds_layout_ci.pNext = NULL;
11979 ds_layout_ci.bindingCount = 1;
11980 ds_layout_ci.pBindings = &dsl_binding;
11981
11982 VkDescriptorSetLayout ds_layout;
11983 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
11984 ASSERT_VK_SUCCESS(err);
11985
11986 VkDescriptorSetAllocateInfo alloc_info = {};
11987 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
11988 alloc_info.descriptorSetCount = 1;
11989 alloc_info.descriptorPool = ds_pool;
11990 alloc_info.pSetLayouts = &ds_layout;
11991 VkDescriptorSet descriptor_set;
11992 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
11993 ASSERT_VK_SUCCESS(err);
11994
11995 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
11996 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
11997 pipeline_layout_ci.pNext = NULL;
11998 pipeline_layout_ci.setLayoutCount = 1;
11999 pipeline_layout_ci.pSetLayouts = &ds_layout;
12000 VkPipelineLayout pipeline_layout;
12001 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12002 ASSERT_VK_SUCCESS(err);
12003
12004 VkImageObj image(m_device);
12005 image.init(32, 32, tex_format, VK_IMAGE_USAGE_STORAGE_BIT, tiling, 0);
12006 ASSERT_TRUE(image.initialized());
12007 VkImageView view = image.targetView(tex_format);
12008
12009 VkDescriptorImageInfo image_info = {};
12010 image_info.imageView = view;
12011 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12012
12013 VkWriteDescriptorSet descriptor_write = {};
12014 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12015 descriptor_write.dstSet = descriptor_set;
12016 descriptor_write.dstBinding = 0;
12017 descriptor_write.descriptorCount = 1;
12018 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
12019 descriptor_write.pImageInfo = &image_info;
12020
12021 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
12022 " of VK_DESCRIPTOR_TYPE_STORAGE_IMAGE type is being updated with layout "
12023 "VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL but according to spec ");
12024 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12025 m_errorMonitor->VerifyFound();
12026
12027 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12028 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12029 vkFreeDescriptorSets(m_device->device(), ds_pool, 1, &descriptor_set);
12030 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12031}
12032
Mark Mueller93b938f2016-08-18 10:27:40 -060012033TEST_F(VkLayerTest, SimultaneousUse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012034 TEST_DESCRIPTION(
12035 "Use vkCmdExecuteCommands with invalid state "
12036 "in primary and secondary command buffers.");
Mark Mueller93b938f2016-08-18 10:27:40 -060012037
12038 ASSERT_NO_FATAL_FAILURE(InitState());
12039 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12040
Mike Weiblen95dd0f92016-10-19 12:28:27 -060012041 const char *simultaneous_use_message1 = "without VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set!";
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012042 const char *simultaneous_use_message2 =
12043 "does not have VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT set and "
12044 "will cause primary command buffer";
Mark Mueller93b938f2016-08-18 10:27:40 -060012045
12046 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012047 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012048 command_buffer_allocate_info.commandPool = m_commandPool;
12049 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
12050 command_buffer_allocate_info.commandBufferCount = 1;
12051
12052 VkCommandBuffer secondary_command_buffer;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012053 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
Mark Mueller93b938f2016-08-18 10:27:40 -060012054 VkCommandBufferBeginInfo command_buffer_begin_info = {};
12055 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012056 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Mark Mueller93b938f2016-08-18 10:27:40 -060012057 command_buffer_inheritance_info.renderPass = m_renderPass;
12058 command_buffer_inheritance_info.framebuffer = m_framebuffer;
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012059
Mark Mueller93b938f2016-08-18 10:27:40 -060012060 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012061 command_buffer_begin_info.flags =
12062 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
Mark Mueller93b938f2016-08-18 10:27:40 -060012063 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
12064
12065 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
12066 vkEndCommandBuffer(secondary_command_buffer);
12067
Mark Mueller93b938f2016-08-18 10:27:40 -060012068 VkSubmitInfo submit_info = {};
12069 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12070 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012071 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller93b938f2016-08-18 10:27:40 -060012072
Mark Mueller4042b652016-09-05 22:52:21 -060012073 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012074 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
12075 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message1);
12076 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012077 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012078 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012079 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12080 vkEndCommandBuffer(m_commandBuffer->handle());
Mark Mueller93b938f2016-08-18 10:27:40 -060012081
Dave Houltonfbf52152017-01-06 12:55:29 -070012082 m_errorMonitor->ExpectSuccess(0);
Mark Mueller93b938f2016-08-18 10:27:40 -060012083 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012084 m_errorMonitor->VerifyNotFound();
Mark Mueller93b938f2016-08-18 10:27:40 -060012085
Mark Mueller4042b652016-09-05 22:52:21 -060012086 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012087 m_errorMonitor->SetUnexpectedError("commandBuffer must not currently be pending execution");
12088 m_errorMonitor->SetUnexpectedError(
12089 "If commandBuffer was allocated from a VkCommandPool which did not have the "
12090 "VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT flag set, commandBuffer must be in the initial state");
Mark Mueller93b938f2016-08-18 10:27:40 -060012091 vkBeginCommandBuffer(m_commandBuffer->handle(), &command_buffer_begin_info);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012092 vkCmdBeginRenderPass(m_commandBuffer->handle(), &renderPassBeginInfo(), VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Mark Mueller4042b652016-09-05 22:52:21 -060012093
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012094 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, simultaneous_use_message2);
12095 vkCmdExecuteCommands(m_commandBuffer->handle(), 1, &secondary_command_buffer);
Mark Mueller93b938f2016-08-18 10:27:40 -060012096 m_errorMonitor->VerifyFound();
Mark Mueller4042b652016-09-05 22:52:21 -060012097 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
12098 vkEndCommandBuffer(m_commandBuffer->handle());
Rene Lindsay24cf6c52017-01-04 12:06:59 -070012099
12100 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012101
12102 m_errorMonitor->SetUnexpectedError("All elements of pCommandBuffers must not be pending execution");
Mark Mueller93b938f2016-08-18 10:27:40 -060012103}
12104
Tony Barbour626994c2017-02-08 15:29:37 -070012105TEST_F(VkLayerTest, SimultaneousUseOneShot) {
12106 TEST_DESCRIPTION(
12107 "Submit the same command buffer twice in one submit looking for simultaneous use and one time submit"
12108 "errors");
12109 const char *simultaneous_use_message = "is already in use and is not marked for simultaneous use";
12110 const char *one_shot_message = "VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT set, but has been submitted";
12111 ASSERT_NO_FATAL_FAILURE(InitState());
12112
12113 VkCommandBuffer cmd_bufs[2];
12114 VkCommandBufferAllocateInfo alloc_info;
12115 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12116 alloc_info.pNext = NULL;
12117 alloc_info.commandBufferCount = 2;
12118 alloc_info.commandPool = m_commandPool;
12119 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12120 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
12121
12122 VkCommandBufferBeginInfo cb_binfo;
12123 cb_binfo.pNext = NULL;
12124 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12125 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
12126 cb_binfo.flags = 0;
12127 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
12128 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12129 vkCmdSetViewport(cmd_bufs[0], 0, 1, &viewport);
12130 vkEndCommandBuffer(cmd_bufs[0]);
12131 VkCommandBuffer duplicates[2] = {cmd_bufs[0], cmd_bufs[0]};
12132
12133 VkSubmitInfo submit_info = {};
12134 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12135 submit_info.commandBufferCount = 2;
12136 submit_info.pCommandBuffers = duplicates;
12137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, simultaneous_use_message);
12138 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12139 m_errorMonitor->VerifyFound();
12140 vkQueueWaitIdle(m_device->m_queue);
12141
12142 // Set one time use and now look for one time submit
12143 duplicates[0] = duplicates[1] = cmd_bufs[1];
12144 cb_binfo.flags = VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT | VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
12145 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
12146 vkCmdSetViewport(cmd_bufs[1], 0, 1, &viewport);
12147 vkEndCommandBuffer(cmd_bufs[1]);
12148 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, one_shot_message);
12149 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12150 m_errorMonitor->VerifyFound();
12151 vkQueueWaitIdle(m_device->m_queue);
12152}
12153
Tobin Ehlisb093da82017-01-19 12:05:27 -070012154TEST_F(VkLayerTest, StageMaskGsTsEnabled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012155 TEST_DESCRIPTION(
12156 "Attempt to use a stageMask w/ geometry shader and tesselation shader bits enabled when those features are "
12157 "disabled on the device.");
Tobin Ehlisb093da82017-01-19 12:05:27 -070012158
12159 ASSERT_NO_FATAL_FAILURE(InitState());
12160 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12161
12162 std::vector<const char *> device_extension_names;
12163 auto features = m_device->phy().features();
12164 // Make sure gs & ts are disabled
12165 features.geometryShader = false;
12166 features.tessellationShader = false;
12167 // The sacrificial device object
12168 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
12169
12170 VkCommandPoolCreateInfo pool_create_info{};
12171 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
12172 pool_create_info.queueFamilyIndex = test_device.graphics_queue_node_index_;
12173
12174 VkCommandPool command_pool;
12175 vkCreateCommandPool(test_device.handle(), &pool_create_info, nullptr, &command_pool);
12176
12177 VkCommandBufferAllocateInfo cmd = {};
12178 cmd.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
12179 cmd.pNext = NULL;
12180 cmd.commandPool = command_pool;
12181 cmd.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
12182 cmd.commandBufferCount = 1;
12183
12184 VkCommandBuffer cmd_buffer;
12185 VkResult err = vkAllocateCommandBuffers(test_device.handle(), &cmd, &cmd_buffer);
12186 ASSERT_VK_SUCCESS(err);
12187
12188 VkEvent event;
12189 VkEventCreateInfo evci = {};
12190 evci.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12191 VkResult result = vkCreateEvent(test_device.handle(), &evci, NULL, &event);
12192 ASSERT_VK_SUCCESS(result);
12193
12194 VkCommandBufferBeginInfo cbbi = {};
12195 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
12196 vkBeginCommandBuffer(cmd_buffer, &cbbi);
12197 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00230);
12198 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT);
12199 m_errorMonitor->VerifyFound();
12200
12201 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00231);
12202 vkCmdSetEvent(cmd_buffer, event, VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT);
12203 m_errorMonitor->VerifyFound();
12204
12205 vkDestroyEvent(test_device.handle(), event, NULL);
12206 vkDestroyCommandPool(test_device.handle(), command_pool, NULL);
12207}
12208
Mark Mueller917f6bc2016-08-30 10:57:19 -060012209TEST_F(VkLayerTest, InUseDestroyedSignaled) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012210 TEST_DESCRIPTION(
12211 "Use vkCmdExecuteCommands with invalid state "
12212 "in primary and secondary command buffers. "
12213 "Delete objects that are inuse. Call VkQueueSubmit "
12214 "with an event that has been deleted.");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012215
12216 ASSERT_NO_FATAL_FAILURE(InitState());
12217 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12218
Tony Barbour552f6c02016-12-21 14:34:07 -070012219 m_commandBuffer->BeginCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012220
12221 VkEvent event;
12222 VkEventCreateInfo event_create_info = {};
12223 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
12224 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012225 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012226
Tony Barbour552f6c02016-12-21 14:34:07 -070012227 m_commandBuffer->EndCommandBuffer();
Mark Muellerc8d441e2016-08-23 17:36:00 -060012228 vkDestroyEvent(m_device->device(), event, nullptr);
12229
12230 VkSubmitInfo submit_info = {};
12231 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12232 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012233 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Lobodzinskife4be302017-02-14 13:08:15 -070012234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is invalid because bound");
Mark Muellerc8d441e2016-08-23 17:36:00 -060012235 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12236 m_errorMonitor->VerifyFound();
12237
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012238 m_errorMonitor->ExpectSuccess(0); // disable all log message processing with flags==0
Mark Muellerc8d441e2016-08-23 17:36:00 -060012239 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
12240
12241 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
12242
Mark Mueller917f6bc2016-08-30 10:57:19 -060012243 VkSemaphoreCreateInfo semaphore_create_info = {};
12244 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12245 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012246 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012247 VkFenceCreateInfo fence_create_info = {};
12248 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
12249 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012250 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012251
12252 VkDescriptorPoolSize descriptor_pool_type_count = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012253 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012254 descriptor_pool_type_count.descriptorCount = 1;
12255
12256 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
12257 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12258 descriptor_pool_create_info.maxSets = 1;
12259 descriptor_pool_create_info.poolSizeCount = 1;
12260 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012261 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012262
12263 VkDescriptorPool descriptorset_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012264 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012265
12266 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
Mark Mueller4042b652016-09-05 22:52:21 -060012267 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012268 descriptorset_layout_binding.descriptorCount = 1;
12269 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
12270
12271 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012272 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012273 descriptorset_layout_create_info.bindingCount = 1;
12274 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
12275
12276 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012277 ASSERT_VK_SUCCESS(
12278 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012279
12280 VkDescriptorSet descriptorset;
12281 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012282 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012283 descriptorset_allocate_info.descriptorSetCount = 1;
12284 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
12285 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012286 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012287
Mark Mueller4042b652016-09-05 22:52:21 -060012288 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
12289
12290 VkDescriptorBufferInfo buffer_info = {};
12291 buffer_info.buffer = buffer_test.GetBuffer();
12292 buffer_info.offset = 0;
12293 buffer_info.range = 1024;
12294
12295 VkWriteDescriptorSet write_descriptor_set = {};
12296 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12297 write_descriptor_set.dstSet = descriptorset;
12298 write_descriptor_set.descriptorCount = 1;
12299 write_descriptor_set.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
12300 write_descriptor_set.pBufferInfo = &buffer_info;
12301
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012302 vkUpdateDescriptorSets(m_device->device(), 1, &write_descriptor_set, 0, nullptr);
Mark Mueller4042b652016-09-05 22:52:21 -060012303
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012304 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12305 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012306
12307 VkPipelineObj pipe(m_device);
12308 pipe.AddColorAttachment();
12309 pipe.AddShader(&vs);
12310 pipe.AddShader(&fs);
12311
12312 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012313 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
Mark Mueller917f6bc2016-08-30 10:57:19 -060012314 pipeline_layout_create_info.setLayoutCount = 1;
12315 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
12316
12317 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012318 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
Mark Mueller917f6bc2016-08-30 10:57:19 -060012319
12320 pipe.CreateVKPipeline(pipeline_layout, m_renderPass);
12321
Tony Barbour552f6c02016-12-21 14:34:07 -070012322 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012323 vkCmdSetEvent(m_commandBuffer->handle(), event, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
Mark Muellerc8d441e2016-08-23 17:36:00 -060012324
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012325 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12326 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12327 &descriptorset, 0, NULL);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012328
Tony Barbour552f6c02016-12-21 14:34:07 -070012329 m_commandBuffer->EndCommandBuffer();
Mark Mueller917f6bc2016-08-30 10:57:19 -060012330
Mark Mueller917f6bc2016-08-30 10:57:19 -060012331 submit_info.signalSemaphoreCount = 1;
12332 submit_info.pSignalSemaphores = &semaphore;
12333 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012334 m_errorMonitor->Reset(); // resume logmsg processing
Mark Muellerc8d441e2016-08-23 17:36:00 -060012335
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012336 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00213);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012337 vkDestroyEvent(m_device->device(), event, nullptr);
12338 m_errorMonitor->VerifyFound();
12339
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00199);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012341 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
12342 m_errorMonitor->VerifyFound();
12343
Jeremy Hayes08369882017-02-02 10:31:06 -070012344 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Fence 0x");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012345 vkDestroyFence(m_device->device(), fence, nullptr);
12346 m_errorMonitor->VerifyFound();
12347
Tobin Ehlis122207b2016-09-01 08:50:06 -070012348 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012349 m_errorMonitor->SetUnexpectedError("If semaphore is not VK_NULL_HANDLE, semaphore must be a valid VkSemaphore handle");
12350 m_errorMonitor->SetUnexpectedError("Unable to remove Semaphore obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012351 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012352 m_errorMonitor->SetUnexpectedError("If fence is not VK_NULL_HANDLE, fence must be a valid VkFence handle");
12353 m_errorMonitor->SetUnexpectedError("Unable to remove Fence obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012354 vkDestroyFence(m_device->device(), fence, nullptr);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012355 m_errorMonitor->SetUnexpectedError("If event is not VK_NULL_HANDLE, event must be a valid VkEvent handle");
12356 m_errorMonitor->SetUnexpectedError("Unable to remove Event obj");
Mark Mueller917f6bc2016-08-30 10:57:19 -060012357 vkDestroyEvent(m_device->device(), event, nullptr);
12358 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012359 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
Mark Mueller917f6bc2016-08-30 10:57:19 -060012360 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
12361}
12362
Tobin Ehlis2adda372016-09-01 08:51:06 -070012363TEST_F(VkLayerTest, QueryPoolInUseDestroyedSignaled) {
12364 TEST_DESCRIPTION("Delete in-use query pool.");
12365
12366 ASSERT_NO_FATAL_FAILURE(InitState());
12367 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12368
12369 VkQueryPool query_pool;
12370 VkQueryPoolCreateInfo query_pool_ci{};
12371 query_pool_ci.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
12372 query_pool_ci.queryType = VK_QUERY_TYPE_TIMESTAMP;
12373 query_pool_ci.queryCount = 1;
12374 vkCreateQueryPool(m_device->device(), &query_pool_ci, nullptr, &query_pool);
Tony Barbour552f6c02016-12-21 14:34:07 -070012375 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012376 // Reset query pool to create binding with cmd buffer
12377 vkCmdResetQueryPool(m_commandBuffer->handle(), query_pool, 0, 1);
12378
Tony Barbour552f6c02016-12-21 14:34:07 -070012379 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis2adda372016-09-01 08:51:06 -070012380
12381 VkSubmitInfo submit_info = {};
12382 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12383 submit_info.commandBufferCount = 1;
12384 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12385 // Submit cmd buffer and then destroy query pool while in-flight
12386 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12387
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012388 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01012);
Tobin Ehlis2adda372016-09-01 08:51:06 -070012389 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12390 m_errorMonitor->VerifyFound();
12391
12392 vkQueueWaitIdle(m_device->m_queue);
12393 // Now that cmd buffer done we can safely destroy query_pool
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012394 m_errorMonitor->SetUnexpectedError("If queryPool is not VK_NULL_HANDLE, queryPool must be a valid VkQueryPool handle");
12395 m_errorMonitor->SetUnexpectedError("Unable to remove Query Pool obj");
Tobin Ehlis2adda372016-09-01 08:51:06 -070012396 vkDestroyQueryPool(m_device->handle(), query_pool, NULL);
12397}
12398
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012399TEST_F(VkLayerTest, PipelineInUseDestroyedSignaled) {
12400 TEST_DESCRIPTION("Delete in-use pipeline.");
12401
12402 ASSERT_NO_FATAL_FAILURE(InitState());
12403 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12404
12405 // Empty pipeline layout used for binding PSO
12406 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12407 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12408 pipeline_layout_ci.setLayoutCount = 0;
12409 pipeline_layout_ci.pSetLayouts = NULL;
12410
12411 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012412 VkResult err = vkCreatePipelineLayout(m_device->handle(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012413 ASSERT_VK_SUCCESS(err);
12414
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012415 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00555);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012416 // Create PSO to be used for draw-time errors below
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012417 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
12418 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012419 // Store pipeline handle so we can actually delete it before test finishes
12420 VkPipeline delete_this_pipeline;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012421 { // Scope pipeline so it will be auto-deleted
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012422 VkPipelineObj pipe(m_device);
12423 pipe.AddShader(&vs);
12424 pipe.AddShader(&fs);
12425 pipe.AddColorAttachment();
12426 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12427 delete_this_pipeline = pipe.handle();
12428
Tony Barbour552f6c02016-12-21 14:34:07 -070012429 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012430 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012431 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012432
Tony Barbour552f6c02016-12-21 14:34:07 -070012433 m_commandBuffer->EndCommandBuffer();
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012434
12435 VkSubmitInfo submit_info = {};
12436 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12437 submit_info.commandBufferCount = 1;
12438 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12439 // Submit cmd buffer and then pipeline destroyed while in-flight
12440 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012441 } // Pipeline deletion triggered here
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012442 m_errorMonitor->VerifyFound();
12443 // Make sure queue finished and then actually delete pipeline
12444 vkQueueWaitIdle(m_device->m_queue);
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012445 m_errorMonitor->SetUnexpectedError("If pipeline is not VK_NULL_HANDLE, pipeline must be a valid VkPipeline handle");
12446 m_errorMonitor->SetUnexpectedError("Unable to remove Pipeline obj");
Tobin Ehlisfafab2d2016-09-07 13:51:24 -060012447 vkDestroyPipeline(m_device->handle(), delete_this_pipeline, nullptr);
12448 vkDestroyPipelineLayout(m_device->handle(), pipeline_layout, nullptr);
12449}
12450
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012451TEST_F(VkLayerTest, ImageViewInUseDestroyedSignaled) {
12452 TEST_DESCRIPTION("Delete in-use imageView.");
12453
12454 ASSERT_NO_FATAL_FAILURE(InitState());
12455 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12456
12457 VkDescriptorPoolSize ds_type_count;
12458 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12459 ds_type_count.descriptorCount = 1;
12460
12461 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12462 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12463 ds_pool_ci.maxSets = 1;
12464 ds_pool_ci.poolSizeCount = 1;
12465 ds_pool_ci.pPoolSizes = &ds_type_count;
12466
12467 VkDescriptorPool ds_pool;
12468 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12469 ASSERT_VK_SUCCESS(err);
12470
12471 VkSamplerCreateInfo sampler_ci = {};
12472 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12473 sampler_ci.pNext = NULL;
12474 sampler_ci.magFilter = VK_FILTER_NEAREST;
12475 sampler_ci.minFilter = VK_FILTER_NEAREST;
12476 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12477 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12478 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12479 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12480 sampler_ci.mipLodBias = 1.0;
12481 sampler_ci.anisotropyEnable = VK_FALSE;
12482 sampler_ci.maxAnisotropy = 1;
12483 sampler_ci.compareEnable = VK_FALSE;
12484 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12485 sampler_ci.minLod = 1.0;
12486 sampler_ci.maxLod = 1.0;
12487 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12488 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12489 VkSampler sampler;
12490
12491 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12492 ASSERT_VK_SUCCESS(err);
12493
12494 VkDescriptorSetLayoutBinding layout_binding;
12495 layout_binding.binding = 0;
12496 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12497 layout_binding.descriptorCount = 1;
12498 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12499 layout_binding.pImmutableSamplers = NULL;
12500
12501 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12502 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12503 ds_layout_ci.bindingCount = 1;
12504 ds_layout_ci.pBindings = &layout_binding;
12505 VkDescriptorSetLayout ds_layout;
12506 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12507 ASSERT_VK_SUCCESS(err);
12508
12509 VkDescriptorSetAllocateInfo alloc_info = {};
12510 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12511 alloc_info.descriptorSetCount = 1;
12512 alloc_info.descriptorPool = ds_pool;
12513 alloc_info.pSetLayouts = &ds_layout;
12514 VkDescriptorSet descriptor_set;
12515 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12516 ASSERT_VK_SUCCESS(err);
12517
12518 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12519 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12520 pipeline_layout_ci.pNext = NULL;
12521 pipeline_layout_ci.setLayoutCount = 1;
12522 pipeline_layout_ci.pSetLayouts = &ds_layout;
12523
12524 VkPipelineLayout pipeline_layout;
12525 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12526 ASSERT_VK_SUCCESS(err);
12527
12528 VkImageObj image(m_device);
12529 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
12530 ASSERT_TRUE(image.initialized());
12531
12532 VkImageView view;
12533 VkImageViewCreateInfo ivci = {};
12534 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12535 ivci.image = image.handle();
12536 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12537 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12538 ivci.subresourceRange.layerCount = 1;
12539 ivci.subresourceRange.baseMipLevel = 0;
12540 ivci.subresourceRange.levelCount = 1;
12541 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12542
12543 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12544 ASSERT_VK_SUCCESS(err);
12545
12546 VkDescriptorImageInfo image_info{};
12547 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12548 image_info.imageView = view;
12549 image_info.sampler = sampler;
12550
12551 VkWriteDescriptorSet descriptor_write = {};
12552 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12553 descriptor_write.dstSet = descriptor_set;
12554 descriptor_write.dstBinding = 0;
12555 descriptor_write.descriptorCount = 1;
12556 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12557 descriptor_write.pImageInfo = &image_info;
12558
12559 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12560
12561 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012562 char const *vsSource =
12563 "#version 450\n"
12564 "\n"
12565 "out gl_PerVertex { \n"
12566 " vec4 gl_Position;\n"
12567 "};\n"
12568 "void main(){\n"
12569 " gl_Position = vec4(1);\n"
12570 "}\n";
12571 char const *fsSource =
12572 "#version 450\n"
12573 "\n"
12574 "layout(set=0, binding=0) uniform sampler2D s;\n"
12575 "layout(location=0) out vec4 x;\n"
12576 "void main(){\n"
12577 " x = texture(s, vec2(1));\n"
12578 "}\n";
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012579 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12580 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12581 VkPipelineObj pipe(m_device);
12582 pipe.AddShader(&vs);
12583 pipe.AddShader(&fs);
12584 pipe.AddColorAttachment();
12585 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12586
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012587 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00776);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012588
Tony Barbour552f6c02016-12-21 14:34:07 -070012589 m_commandBuffer->BeginCommandBuffer();
12590 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012591 // Bind pipeline to cmd buffer
12592 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12593 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12594 &descriptor_set, 0, nullptr);
Rene Lindsaya8880622017-01-18 13:12:59 -070012595
12596 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12597 VkRect2D scissor = {{0, 0}, {16, 16}};
12598 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12599 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12600
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012601 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012602 m_commandBuffer->EndRenderPass();
12603 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012604 // Submit cmd buffer then destroy sampler
12605 VkSubmitInfo submit_info = {};
12606 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12607 submit_info.commandBufferCount = 1;
12608 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12609 // Submit cmd buffer and then destroy imageView while in-flight
12610 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12611
12612 vkDestroyImageView(m_device->device(), view, nullptr);
12613 m_errorMonitor->VerifyFound();
12614 vkQueueWaitIdle(m_device->m_queue);
12615 // Now we can actually destroy imageView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012616 m_errorMonitor->SetUnexpectedError("If imageView is not VK_NULL_HANDLE, imageView must be a valid VkImageView handle");
12617 m_errorMonitor->SetUnexpectedError("Unable to remove Image View obj");
Tobin Ehlis7d965da2016-09-19 16:15:45 -060012618 vkDestroyImageView(m_device->device(), view, NULL);
12619 vkDestroySampler(m_device->device(), sampler, nullptr);
12620 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12621 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12622 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12623}
12624
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012625TEST_F(VkLayerTest, BufferViewInUseDestroyedSignaled) {
12626 TEST_DESCRIPTION("Delete in-use bufferView.");
12627
12628 ASSERT_NO_FATAL_FAILURE(InitState());
12629 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12630
12631 VkDescriptorPoolSize ds_type_count;
12632 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12633 ds_type_count.descriptorCount = 1;
12634
12635 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12636 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12637 ds_pool_ci.maxSets = 1;
12638 ds_pool_ci.poolSizeCount = 1;
12639 ds_pool_ci.pPoolSizes = &ds_type_count;
12640
12641 VkDescriptorPool ds_pool;
12642 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
12643 ASSERT_VK_SUCCESS(err);
12644
12645 VkDescriptorSetLayoutBinding layout_binding;
12646 layout_binding.binding = 0;
12647 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12648 layout_binding.descriptorCount = 1;
12649 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12650 layout_binding.pImmutableSamplers = NULL;
12651
12652 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12653 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12654 ds_layout_ci.bindingCount = 1;
12655 ds_layout_ci.pBindings = &layout_binding;
12656 VkDescriptorSetLayout ds_layout;
12657 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
12658 ASSERT_VK_SUCCESS(err);
12659
12660 VkDescriptorSetAllocateInfo alloc_info = {};
12661 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12662 alloc_info.descriptorSetCount = 1;
12663 alloc_info.descriptorPool = ds_pool;
12664 alloc_info.pSetLayouts = &ds_layout;
12665 VkDescriptorSet descriptor_set;
12666 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
12667 ASSERT_VK_SUCCESS(err);
12668
12669 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12670 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12671 pipeline_layout_ci.pNext = NULL;
12672 pipeline_layout_ci.setLayoutCount = 1;
12673 pipeline_layout_ci.pSetLayouts = &ds_layout;
12674
12675 VkPipelineLayout pipeline_layout;
12676 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
12677 ASSERT_VK_SUCCESS(err);
12678
12679 VkBuffer buffer;
12680 uint32_t queue_family_index = 0;
12681 VkBufferCreateInfo buffer_create_info = {};
12682 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
12683 buffer_create_info.size = 1024;
12684 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
12685 buffer_create_info.queueFamilyIndexCount = 1;
12686 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
12687
12688 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
12689 ASSERT_VK_SUCCESS(err);
12690
12691 VkMemoryRequirements memory_reqs;
12692 VkDeviceMemory buffer_memory;
12693
12694 VkMemoryAllocateInfo memory_info = {};
12695 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
12696 memory_info.allocationSize = 0;
12697 memory_info.memoryTypeIndex = 0;
12698
12699 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
12700 memory_info.allocationSize = memory_reqs.size;
12701 bool pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
12702 ASSERT_TRUE(pass);
12703
12704 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
12705 ASSERT_VK_SUCCESS(err);
12706 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
12707 ASSERT_VK_SUCCESS(err);
12708
12709 VkBufferView view;
12710 VkBufferViewCreateInfo bvci = {};
12711 bvci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
12712 bvci.buffer = buffer;
12713 bvci.format = VK_FORMAT_R8_UNORM;
12714 bvci.range = VK_WHOLE_SIZE;
12715
12716 err = vkCreateBufferView(m_device->device(), &bvci, NULL, &view);
12717 ASSERT_VK_SUCCESS(err);
12718
12719 VkWriteDescriptorSet descriptor_write = {};
12720 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12721 descriptor_write.dstSet = descriptor_set;
12722 descriptor_write.dstBinding = 0;
12723 descriptor_write.descriptorCount = 1;
12724 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
12725 descriptor_write.pTexelBufferView = &view;
12726
12727 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12728
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012729 char const *vsSource =
12730 "#version 450\n"
12731 "\n"
12732 "out gl_PerVertex { \n"
12733 " vec4 gl_Position;\n"
12734 "};\n"
12735 "void main(){\n"
12736 " gl_Position = vec4(1);\n"
12737 "}\n";
12738 char const *fsSource =
12739 "#version 450\n"
12740 "\n"
12741 "layout(set=0, binding=0, r8) uniform imageBuffer s;\n"
12742 "layout(location=0) out vec4 x;\n"
12743 "void main(){\n"
12744 " x = imageLoad(s, 0);\n"
12745 "}\n";
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012746 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12747 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12748 VkPipelineObj pipe(m_device);
12749 pipe.AddShader(&vs);
12750 pipe.AddShader(&fs);
12751 pipe.AddColorAttachment();
12752 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12753
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012754 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00701);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012755
Tony Barbour552f6c02016-12-21 14:34:07 -070012756 m_commandBuffer->BeginCommandBuffer();
12757 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012758 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12759 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12760 VkRect2D scissor = {{0, 0}, {16, 16}};
12761 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12762 // Bind pipeline to cmd buffer
12763 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12764 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12765 &descriptor_set, 0, nullptr);
12766 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012767 m_commandBuffer->EndRenderPass();
12768 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012769
12770 VkSubmitInfo submit_info = {};
12771 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12772 submit_info.commandBufferCount = 1;
12773 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12774 // Submit cmd buffer and then destroy bufferView while in-flight
12775 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12776
12777 vkDestroyBufferView(m_device->device(), view, nullptr);
12778 m_errorMonitor->VerifyFound();
12779 vkQueueWaitIdle(m_device->m_queue);
12780 // Now we can actually destroy bufferView
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012781 m_errorMonitor->SetUnexpectedError("If bufferView is not VK_NULL_HANDLE, bufferView must be a valid VkBufferView handle");
12782 m_errorMonitor->SetUnexpectedError("Unable to remove Buffer View obj");
Tobin Ehlis757ce9e2016-09-28 09:59:07 -060012783 vkDestroyBufferView(m_device->device(), view, NULL);
12784 vkDestroyBuffer(m_device->device(), buffer, NULL);
12785 vkFreeMemory(m_device->device(), buffer_memory, NULL);
12786 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12787 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12788 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12789}
12790
Tobin Ehlis209532e2016-09-07 13:52:18 -060012791TEST_F(VkLayerTest, SamplerInUseDestroyedSignaled) {
12792 TEST_DESCRIPTION("Delete in-use sampler.");
12793
12794 ASSERT_NO_FATAL_FAILURE(InitState());
12795 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12796
12797 VkDescriptorPoolSize ds_type_count;
12798 ds_type_count.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12799 ds_type_count.descriptorCount = 1;
12800
12801 VkDescriptorPoolCreateInfo ds_pool_ci = {};
12802 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
12803 ds_pool_ci.maxSets = 1;
12804 ds_pool_ci.poolSizeCount = 1;
12805 ds_pool_ci.pPoolSizes = &ds_type_count;
12806
12807 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012808 VkResult err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012809 ASSERT_VK_SUCCESS(err);
12810
12811 VkSamplerCreateInfo sampler_ci = {};
12812 sampler_ci.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
12813 sampler_ci.pNext = NULL;
12814 sampler_ci.magFilter = VK_FILTER_NEAREST;
12815 sampler_ci.minFilter = VK_FILTER_NEAREST;
12816 sampler_ci.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
12817 sampler_ci.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12818 sampler_ci.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12819 sampler_ci.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
12820 sampler_ci.mipLodBias = 1.0;
12821 sampler_ci.anisotropyEnable = VK_FALSE;
12822 sampler_ci.maxAnisotropy = 1;
12823 sampler_ci.compareEnable = VK_FALSE;
12824 sampler_ci.compareOp = VK_COMPARE_OP_NEVER;
12825 sampler_ci.minLod = 1.0;
12826 sampler_ci.maxLod = 1.0;
12827 sampler_ci.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
12828 sampler_ci.unnormalizedCoordinates = VK_FALSE;
12829 VkSampler sampler;
12830
12831 err = vkCreateSampler(m_device->device(), &sampler_ci, NULL, &sampler);
12832 ASSERT_VK_SUCCESS(err);
12833
12834 VkDescriptorSetLayoutBinding layout_binding;
12835 layout_binding.binding = 0;
Tobin Ehlis94fc0ad2016-09-19 16:23:01 -060012836 layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
Tobin Ehlis209532e2016-09-07 13:52:18 -060012837 layout_binding.descriptorCount = 1;
12838 layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
12839 layout_binding.pImmutableSamplers = NULL;
12840
12841 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
12842 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
12843 ds_layout_ci.bindingCount = 1;
12844 ds_layout_ci.pBindings = &layout_binding;
12845 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012846 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012847 ASSERT_VK_SUCCESS(err);
12848
12849 VkDescriptorSetAllocateInfo alloc_info = {};
12850 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
12851 alloc_info.descriptorSetCount = 1;
12852 alloc_info.descriptorPool = ds_pool;
12853 alloc_info.pSetLayouts = &ds_layout;
12854 VkDescriptorSet descriptor_set;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012855 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012856 ASSERT_VK_SUCCESS(err);
12857
12858 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
12859 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
12860 pipeline_layout_ci.pNext = NULL;
12861 pipeline_layout_ci.setLayoutCount = 1;
12862 pipeline_layout_ci.pSetLayouts = &ds_layout;
12863
12864 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012865 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012866 ASSERT_VK_SUCCESS(err);
12867
12868 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012869 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 -060012870 ASSERT_TRUE(image.initialized());
12871
12872 VkImageView view;
12873 VkImageViewCreateInfo ivci = {};
12874 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
12875 ivci.image = image.handle();
12876 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
12877 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
12878 ivci.subresourceRange.layerCount = 1;
12879 ivci.subresourceRange.baseMipLevel = 0;
12880 ivci.subresourceRange.levelCount = 1;
12881 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
12882
12883 err = vkCreateImageView(m_device->device(), &ivci, NULL, &view);
12884 ASSERT_VK_SUCCESS(err);
12885
12886 VkDescriptorImageInfo image_info{};
12887 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
12888 image_info.imageView = view;
12889 image_info.sampler = sampler;
12890
12891 VkWriteDescriptorSet descriptor_write = {};
12892 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
12893 descriptor_write.dstSet = descriptor_set;
12894 descriptor_write.dstBinding = 0;
12895 descriptor_write.descriptorCount = 1;
12896 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
12897 descriptor_write.pImageInfo = &image_info;
12898
12899 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
12900
12901 // Create PSO to use the sampler
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012902 char const *vsSource =
12903 "#version 450\n"
12904 "\n"
12905 "out gl_PerVertex { \n"
12906 " vec4 gl_Position;\n"
12907 "};\n"
12908 "void main(){\n"
12909 " gl_Position = vec4(1);\n"
12910 "}\n";
12911 char const *fsSource =
12912 "#version 450\n"
12913 "\n"
12914 "layout(set=0, binding=0) uniform sampler2D s;\n"
12915 "layout(location=0) out vec4 x;\n"
12916 "void main(){\n"
12917 " x = texture(s, vec2(1));\n"
12918 "}\n";
Tobin Ehlis209532e2016-09-07 13:52:18 -060012919 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
12920 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
12921 VkPipelineObj pipe(m_device);
12922 pipe.AddShader(&vs);
12923 pipe.AddShader(&fs);
12924 pipe.AddColorAttachment();
12925 pipe.CreateVKPipeline(pipeline_layout, renderPass());
12926
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070012927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00837);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012928
Tony Barbour552f6c02016-12-21 14:34:07 -070012929 m_commandBuffer->BeginCommandBuffer();
12930 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis209532e2016-09-07 13:52:18 -060012931 // Bind pipeline to cmd buffer
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012932 vkCmdBindPipeline(m_commandBuffer->handle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
12933 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
12934 &descriptor_set, 0, nullptr);
Rene Lindsay4da11732017-01-13 14:42:10 -070012935
12936 VkViewport viewport = {0, 0, 16, 16, 0, 1};
12937 VkRect2D scissor = {{0, 0}, {16, 16}};
12938 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
12939 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
12940
Tobin Ehlis209532e2016-09-07 13:52:18 -060012941 Draw(1, 0, 0, 0);
Tony Barbour552f6c02016-12-21 14:34:07 -070012942 m_commandBuffer->EndRenderPass();
12943 m_commandBuffer->EndCommandBuffer();
Tobin Ehlis209532e2016-09-07 13:52:18 -060012944 // Submit cmd buffer then destroy sampler
12945 VkSubmitInfo submit_info = {};
12946 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12947 submit_info.commandBufferCount = 1;
12948 submit_info.pCommandBuffers = &m_commandBuffer->handle();
12949 // Submit cmd buffer and then destroy sampler while in-flight
12950 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
12951
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012952 vkDestroySampler(m_device->device(), sampler, nullptr); // Destroyed too soon
Tobin Ehlis209532e2016-09-07 13:52:18 -060012953 m_errorMonitor->VerifyFound();
12954 vkQueueWaitIdle(m_device->m_queue);
Rene Lindsay4da11732017-01-13 14:42:10 -070012955
Tobin Ehlis209532e2016-09-07 13:52:18 -060012956 // Now we can actually destroy sampler
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070012957 m_errorMonitor->SetUnexpectedError("If sampler is not VK_NULL_HANDLE, sampler must be a valid VkSampler handle");
12958 m_errorMonitor->SetUnexpectedError("Unable to remove Sampler obj");
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012959 vkDestroySampler(m_device->device(), sampler, NULL); // Destroyed for real
Tobin Ehlis209532e2016-09-07 13:52:18 -060012960 vkDestroyImageView(m_device->device(), view, NULL);
12961 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
12962 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
12963 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
12964}
12965
Mark Mueller1cd9f412016-08-25 13:23:52 -060012966TEST_F(VkLayerTest, QueueForwardProgressFenceWait) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070012967 TEST_DESCRIPTION(
12968 "Call VkQueueSubmit with a semaphore that is already "
12969 "signaled but not waited on by the queue. Wait on a "
12970 "fence that has not yet been submitted to a queue.");
Mark Mueller96a56d52016-08-24 10:28:05 -060012971
12972 ASSERT_NO_FATAL_FAILURE(InitState());
12973 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
12974
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012975 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 -070012976 const char *invalid_fence_wait_message =
12977 " which has not been submitted on a Queue or during "
12978 "acquire next image.";
Mark Mueller96a56d52016-08-24 10:28:05 -060012979
Tony Barbour552f6c02016-12-21 14:34:07 -070012980 m_commandBuffer->BeginCommandBuffer();
12981 m_commandBuffer->EndCommandBuffer();
Mark Mueller96a56d52016-08-24 10:28:05 -060012982
12983 VkSemaphoreCreateInfo semaphore_create_info = {};
12984 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
12985 VkSemaphore semaphore;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012986 ASSERT_VK_SUCCESS(vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore));
Mark Mueller96a56d52016-08-24 10:28:05 -060012987 VkSubmitInfo submit_info = {};
12988 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
12989 submit_info.commandBufferCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012990 submit_info.pCommandBuffers = &m_commandBuffer->handle();
Mark Mueller96a56d52016-08-24 10:28:05 -060012991 submit_info.signalSemaphoreCount = 1;
12992 submit_info.pSignalSemaphores = &semaphore;
12993 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
Dave Houltonfbf52152017-01-06 12:55:29 -070012994 m_errorMonitor->ExpectSuccess(0);
Mark Mueller96a56d52016-08-24 10:28:05 -060012995 vkResetCommandBuffer(m_commandBuffer->handle(), 0);
Dave Houltonfbf52152017-01-06 12:55:29 -070012996 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070012997 m_commandBuffer->BeginCommandBuffer();
12998 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskice751c62016-09-08 10:45:35 -060012999 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, queue_forward_progress_message);
Mark Mueller96a56d52016-08-24 10:28:05 -060013000 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
13001 m_errorMonitor->VerifyFound();
13002
Mark Mueller1cd9f412016-08-25 13:23:52 -060013003 VkFenceCreateInfo fence_create_info = {};
13004 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
13005 VkFence fence;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013006 ASSERT_VK_SUCCESS(vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence));
Mark Mueller1cd9f412016-08-25 13:23:52 -060013007
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013008 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, invalid_fence_wait_message);
Mark Mueller1cd9f412016-08-25 13:23:52 -060013009 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
13010 m_errorMonitor->VerifyFound();
13011
Mark Mueller4042b652016-09-05 22:52:21 -060013012 vkDeviceWaitIdle(m_device->device());
Mark Mueller1cd9f412016-08-25 13:23:52 -060013013 vkDestroyFence(m_device->device(), fence, nullptr);
Mark Mueller96a56d52016-08-24 10:28:05 -060013014 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
13015}
13016
Tobin Ehlis4af23302016-07-19 10:50:30 -060013017TEST_F(VkLayerTest, FramebufferIncompatible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013018 TEST_DESCRIPTION(
13019 "Bind a secondary command buffer with with a framebuffer "
13020 "that does not match the framebuffer for the active "
13021 "renderpass.");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013022 ASSERT_NO_FATAL_FAILURE(InitState());
13023 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13024
13025 // A renderpass with one color attachment.
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013026 VkAttachmentDescription attachment = {0,
13027 VK_FORMAT_B8G8R8A8_UNORM,
13028 VK_SAMPLE_COUNT_1_BIT,
13029 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13030 VK_ATTACHMENT_STORE_OP_STORE,
13031 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
13032 VK_ATTACHMENT_STORE_OP_DONT_CARE,
13033 VK_IMAGE_LAYOUT_UNDEFINED,
13034 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013035
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013036 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013037
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013038 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013039
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013040 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013041
13042 VkRenderPass rp;
13043 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
13044 ASSERT_VK_SUCCESS(err);
13045
13046 // A compatible framebuffer.
13047 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013048 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 -060013049 ASSERT_TRUE(image.initialized());
13050
13051 VkImageViewCreateInfo ivci = {
13052 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
13053 nullptr,
13054 0,
13055 image.handle(),
13056 VK_IMAGE_VIEW_TYPE_2D,
13057 VK_FORMAT_B8G8R8A8_UNORM,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013058 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
13059 VK_COMPONENT_SWIZZLE_IDENTITY},
Tobin Ehlis4af23302016-07-19 10:50:30 -060013060 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
13061 };
13062 VkImageView view;
13063 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
13064 ASSERT_VK_SUCCESS(err);
13065
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013066 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Tobin Ehlis4af23302016-07-19 10:50:30 -060013067 VkFramebuffer fb;
13068 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
13069 ASSERT_VK_SUCCESS(err);
13070
13071 VkCommandBufferAllocateInfo cbai = {};
13072 cbai.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
13073 cbai.commandPool = m_commandPool;
13074 cbai.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
13075 cbai.commandBufferCount = 1;
13076
13077 VkCommandBuffer sec_cb;
13078 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &sec_cb);
13079 ASSERT_VK_SUCCESS(err);
13080 VkCommandBufferBeginInfo cbbi = {};
13081 VkCommandBufferInheritanceInfo cbii = {};
Chris Forbes98420382016-11-28 17:56:51 +130013082 cbii.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
Tobin Ehlis4af23302016-07-19 10:50:30 -060013083 cbii.renderPass = renderPass();
13084 cbii.framebuffer = fb;
13085 cbbi.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
13086 cbbi.pNext = NULL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013087 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 -060013088 cbbi.pInheritanceInfo = &cbii;
13089 vkBeginCommandBuffer(sec_cb, &cbbi);
13090 vkEndCommandBuffer(sec_cb);
13091
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013092 VkCommandBufferBeginInfo cbbi2 = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Chris Forbes3400bc52016-09-13 18:10:34 +120013093 vkBeginCommandBuffer(m_commandBuffer->GetBufferHandle(), &cbbi2);
13094 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
Tobin Ehlis4af23302016-07-19 10:50:30 -060013095
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013096 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060013097 " that is not the same as the primary command buffer's current active framebuffer ");
Tobin Ehlis4af23302016-07-19 10:50:30 -060013098 vkCmdExecuteCommands(m_commandBuffer->GetBufferHandle(), 1, &sec_cb);
13099 m_errorMonitor->VerifyFound();
13100 // Cleanup
13101 vkDestroyImageView(m_device->device(), view, NULL);
13102 vkDestroyRenderPass(m_device->device(), rp, NULL);
13103 vkDestroyFramebuffer(m_device->device(), fb, NULL);
13104}
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013105
13106TEST_F(VkLayerTest, ColorBlendLogicOpTests) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013107 TEST_DESCRIPTION(
13108 "If logicOp is available on the device, set it to an "
13109 "invalid value. If logicOp is not available, attempt to "
13110 "use it and verify that we see the correct error.");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013111 ASSERT_NO_FATAL_FAILURE(InitState());
13112 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13113
13114 auto features = m_device->phy().features();
13115 // Set the expected error depending on whether or not logicOp available
13116 if (VK_FALSE == features.logicOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013117 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13118 "If logic operations feature not "
13119 "enabled, logicOpEnable must be "
13120 "VK_FALSE");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013121 } else {
Chris Forbes34797bc2016-10-03 15:28:49 +130013122 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "pColorBlendState->logicOp (16)");
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013123 }
13124 // Create a pipeline using logicOp
13125 VkResult err;
13126
13127 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
13128 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13129
13130 VkPipelineLayout pipeline_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013131 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013132 ASSERT_VK_SUCCESS(err);
13133
13134 VkPipelineViewportStateCreateInfo vp_state_ci = {};
13135 vp_state_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13136 vp_state_ci.viewportCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013137 VkViewport vp = {}; // Just need dummy vp to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013138 vp_state_ci.pViewports = &vp;
13139 vp_state_ci.scissorCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013140 VkRect2D scissors = {}; // Dummy scissors to point to
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013141 vp_state_ci.pScissors = &scissors;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013142
13143 VkPipelineShaderStageCreateInfo shaderStages[2];
13144 memset(&shaderStages, 0, 2 * sizeof(VkPipelineShaderStageCreateInfo));
13145
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013146 VkShaderObj vs(m_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
13147 VkShaderObj fs(m_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013148 shaderStages[0] = vs.GetStageCreateInfo();
13149 shaderStages[1] = fs.GetStageCreateInfo();
13150
13151 VkPipelineVertexInputStateCreateInfo vi_ci = {};
13152 vi_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13153
13154 VkPipelineInputAssemblyStateCreateInfo ia_ci = {};
13155 ia_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13156 ia_ci.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13157
13158 VkPipelineRasterizationStateCreateInfo rs_ci = {};
13159 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
Chris Forbes14088512016-10-03 14:28:00 +130013160 rs_ci.lineWidth = 1.0f;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013161
13162 VkPipelineColorBlendAttachmentState att = {};
13163 att.blendEnable = VK_FALSE;
13164 att.colorWriteMask = 0xf;
13165
13166 VkPipelineColorBlendStateCreateInfo cb_ci = {};
13167 cb_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13168 // Enable logicOp & set logicOp to value 1 beyond allowed entries
13169 cb_ci.logicOpEnable = VK_TRUE;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013170 cb_ci.logicOp = VK_LOGIC_OP_RANGE_SIZE; // This should cause an error
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013171 cb_ci.attachmentCount = 1;
13172 cb_ci.pAttachments = &att;
13173
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013174 VkPipelineMultisampleStateCreateInfo ms_ci = {};
13175 ms_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
13176 ms_ci.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
13177
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013178 VkGraphicsPipelineCreateInfo gp_ci = {};
13179 gp_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13180 gp_ci.stageCount = 2;
13181 gp_ci.pStages = shaderStages;
13182 gp_ci.pVertexInputState = &vi_ci;
13183 gp_ci.pInputAssemblyState = &ia_ci;
13184 gp_ci.pViewportState = &vp_state_ci;
13185 gp_ci.pRasterizationState = &rs_ci;
13186 gp_ci.pColorBlendState = &cb_ci;
Chris Forbes8aeacbf2016-10-03 14:25:08 +130013187 gp_ci.pMultisampleState = &ms_ci;
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013188 gp_ci.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13189 gp_ci.layout = pipeline_layout;
13190 gp_ci.renderPass = renderPass();
13191
13192 VkPipelineCacheCreateInfo pc_ci = {};
13193 pc_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13194
13195 VkPipeline pipeline;
13196 VkPipelineCache pipelineCache;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013197 err = vkCreatePipelineCache(m_device->device(), &pc_ci, NULL, &pipelineCache);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013198 ASSERT_VK_SUCCESS(err);
13199
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013200 err = vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &gp_ci, NULL, &pipeline);
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013201 m_errorMonitor->VerifyFound();
13202 if (VK_SUCCESS == err) {
13203 vkDestroyPipeline(m_device->device(), pipeline, NULL);
13204 }
Tobin Ehlis52b504f2016-07-19 13:25:12 -060013205 vkDestroyPipelineCache(m_device->device(), pipelineCache, NULL);
13206 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
13207}
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013208
Mike Stroyanaccf7692015-05-12 16:00:45 -060013209#if GTEST_IS_THREADSAFE
13210struct thread_data_struct {
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013211 VkCommandBuffer commandBuffer;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013212 VkEvent event;
13213 bool bailout;
13214};
13215
Karl Schultz6addd812016-02-02 17:17:23 -070013216extern "C" void *AddToCommandBuffer(void *arg) {
13217 struct thread_data_struct *data = (struct thread_data_struct *)arg;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013218
Mike Stroyana6d14942016-07-13 15:10:05 -060013219 for (int i = 0; i < 80000; i++) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013220 vkCmdSetEvent(data->commandBuffer, data->event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013221 if (data->bailout) {
13222 break;
13223 }
13224 }
13225 return NULL;
13226}
13227
Karl Schultz6addd812016-02-02 17:17:23 -070013228TEST_F(VkLayerTest, ThreadCommandBufferCollision) {
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013229 test_platform_thread thread;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013230
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013231 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "THREADING ERROR");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013232
Mike Stroyanaccf7692015-05-12 16:00:45 -060013233 ASSERT_NO_FATAL_FAILURE(InitState());
13234 ASSERT_NO_FATAL_FAILURE(InitViewport());
13235 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13236
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013237 // Calls AllocateCommandBuffers
13238 VkCommandBufferObj commandBuffer(m_device, m_commandPool);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013239
13240 // Avoid creating RenderPass
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013241 commandBuffer.BeginCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013242
13243 VkEventCreateInfo event_info;
13244 VkEvent event;
Mike Stroyanaccf7692015-05-12 16:00:45 -060013245 VkResult err;
13246
13247 memset(&event_info, 0, sizeof(event_info));
13248 event_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
13249
Chia-I Wuf7458c52015-10-26 21:10:41 +080013250 err = vkCreateEvent(device(), &event_info, NULL, &event);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013251 ASSERT_VK_SUCCESS(err);
13252
Mike Stroyanaccf7692015-05-12 16:00:45 -060013253 err = vkResetEvent(device(), event);
13254 ASSERT_VK_SUCCESS(err);
13255
13256 struct thread_data_struct data;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013257 data.commandBuffer = commandBuffer.GetBufferHandle();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013258 data.event = event;
13259 data.bailout = false;
13260 m_errorMonitor->SetBailout(&data.bailout);
Mike Stroyana6d14942016-07-13 15:10:05 -060013261
13262 // First do some correct operations using multiple threads.
13263 // Add many entries to command buffer from another thread.
13264 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
13265 // Make non-conflicting calls from this thread at the same time.
13266 for (int i = 0; i < 80000; i++) {
Mike Stroyand6343902016-07-14 08:56:16 -060013267 uint32_t count;
13268 vkEnumeratePhysicalDevices(instance(), &count, NULL);
Mike Stroyana6d14942016-07-13 15:10:05 -060013269 }
13270 test_platform_thread_join(thread, NULL);
13271
13272 // Then do some incorrect operations using multiple threads.
Mike Stroyanaccf7692015-05-12 16:00:45 -060013273 // Add many entries to command buffer from another thread.
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013274 test_platform_thread_create(&thread, AddToCommandBuffer, (void *)&data);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013275 // Add many entries to command buffer from this thread at the same time.
13276 AddToCommandBuffer(&data);
Mark Lobodzinski5495d132015-09-30 16:19:16 -060013277
Mike Stroyan4268d1f2015-07-13 14:45:35 -060013278 test_platform_thread_join(thread, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013279 commandBuffer.EndCommandBuffer();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013280
Mike Stroyan10b8cb72016-01-22 15:22:03 -070013281 m_errorMonitor->SetBailout(NULL);
13282
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013283 m_errorMonitor->VerifyFound();
Mike Stroyanaccf7692015-05-12 16:00:45 -060013284
Chia-I Wuf7458c52015-10-26 21:10:41 +080013285 vkDestroyEvent(device(), event, NULL);
Mike Stroyanaccf7692015-05-12 16:00:45 -060013286}
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013287#endif // GTEST_IS_THREADSAFE
Mark Lobodzinski209b5292015-09-17 09:44:05 -060013288
Karl Schultz6addd812016-02-02 17:17:23 -070013289TEST_F(VkLayerTest, InvalidSPIRVCodeSize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013290 TEST_DESCRIPTION(
13291 "Test that an error is produced for a spirv module "
13292 "with an impossible code size");
Chris Forbes1cc79542016-07-20 11:13:44 +120013293
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013294 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013295
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013296 ASSERT_NO_FATAL_FAILURE(InitState());
13297 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13298
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013299 VkShaderModule module;
13300 VkShaderModuleCreateInfo moduleCreateInfo;
13301 struct icd_spv_header spv;
13302
13303 spv.magic = ICD_SPV_MAGIC;
13304 spv.version = ICD_SPV_VERSION;
13305 spv.gen_magic = 0;
13306
13307 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13308 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013309 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013310 moduleCreateInfo.codeSize = 4;
13311 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013312 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013313
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013314 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013315}
13316
Karl Schultz6addd812016-02-02 17:17:23 -070013317TEST_F(VkLayerTest, InvalidSPIRVMagic) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013318 TEST_DESCRIPTION(
13319 "Test that an error is produced for a spirv module "
13320 "with a bad magic number");
Chris Forbes1cc79542016-07-20 11:13:44 +120013321
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013322 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Invalid SPIR-V magic number");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013323
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013324 ASSERT_NO_FATAL_FAILURE(InitState());
13325 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13326
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013327 VkShaderModule module;
13328 VkShaderModuleCreateInfo moduleCreateInfo;
13329 struct icd_spv_header spv;
13330
13331 spv.magic = ~ICD_SPV_MAGIC;
13332 spv.version = ICD_SPV_VERSION;
13333 spv.gen_magic = 0;
13334
13335 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13336 moduleCreateInfo.pNext = NULL;
Karl Schultz6addd812016-02-02 17:17:23 -070013337 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013338 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13339 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013340 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013341
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013342 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013343}
13344
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013345#if 0
13346// Not currently covered by SPIRV-Tools validator
Karl Schultz6addd812016-02-02 17:17:23 -070013347TEST_F(VkLayerTest, InvalidSPIRVVersion) {
Courtney Goeltzenleuchter7415d5a2015-12-09 15:48:16 -070013348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013349 "Invalid SPIR-V header");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013350
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013351 ASSERT_NO_FATAL_FAILURE(InitState());
13352 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13353
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013354 VkShaderModule module;
13355 VkShaderModuleCreateInfo moduleCreateInfo;
13356 struct icd_spv_header spv;
13357
13358 spv.magic = ICD_SPV_MAGIC;
13359 spv.version = ~ICD_SPV_VERSION;
13360 spv.gen_magic = 0;
13361
13362 moduleCreateInfo.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
13363 moduleCreateInfo.pNext = NULL;
13364
Karl Schultz6addd812016-02-02 17:17:23 -070013365 moduleCreateInfo.pCode = (const uint32_t *)&spv;
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013366 moduleCreateInfo.codeSize = sizeof(spv) + 10;
13367 moduleCreateInfo.flags = 0;
Chia-I Wuf7458c52015-10-26 21:10:41 +080013368 vkCreateShaderModule(m_device->device(), &moduleCreateInfo, NULL, &module);
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013369
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013370 m_errorMonitor->VerifyFound();
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013371}
Chris Forbesb4afd0f2016-04-04 10:48:35 +120013372#endif
Courtney Goeltzenleuchter00c52b22015-09-16 12:58:29 -060013373
Karl Schultz6addd812016-02-02 17:17:23 -070013374TEST_F(VkLayerTest, CreatePipelineVertexOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013375 TEST_DESCRIPTION(
13376 "Test that a warning is produced for a vertex output that "
13377 "is not consumed by the fragment stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013378 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "not consumed by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013379
Chris Forbes9f7ff632015-05-25 11:13:08 +120013380 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013381 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013382
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013383 char const *vsSource =
13384 "#version 450\n"
13385 "\n"
13386 "layout(location=0) out float x;\n"
13387 "out gl_PerVertex {\n"
13388 " vec4 gl_Position;\n"
13389 "};\n"
13390 "void main(){\n"
13391 " gl_Position = vec4(1);\n"
13392 " x = 0;\n"
13393 "}\n";
13394 char const *fsSource =
13395 "#version 450\n"
13396 "\n"
13397 "layout(location=0) out vec4 color;\n"
13398 "void main(){\n"
13399 " color = vec4(1);\n"
13400 "}\n";
Chris Forbes9f7ff632015-05-25 11:13:08 +120013401
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013402 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13403 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013404
13405 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013406 pipe.AddColorAttachment();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013407 pipe.AddShader(&vs);
13408 pipe.AddShader(&fs);
13409
Chris Forbes9f7ff632015-05-25 11:13:08 +120013410 VkDescriptorSetObj descriptorSet(m_device);
13411 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013412 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes9f7ff632015-05-25 11:13:08 +120013413
Tony Barbour5781e8f2015-08-04 16:23:11 -060013414 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes9f7ff632015-05-25 11:13:08 +120013415
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013416 m_errorMonitor->VerifyFound();
Chris Forbes9f7ff632015-05-25 11:13:08 +120013417}
Chris Forbes9f7ff632015-05-25 11:13:08 +120013418
Mark Mueller098c9cb2016-09-08 09:01:57 -060013419TEST_F(VkLayerTest, CreatePipelineCheckShaderBadSpecialization) {
13420 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13421
13422 ASSERT_NO_FATAL_FAILURE(InitState());
13423 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13424
13425 const char *bad_specialization_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013426 "Specialization entry 0 (for constant id 0) references memory outside provided specialization data ";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013427
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013428 char const *vsSource =
13429 "#version 450\n"
13430 "\n"
13431 "out gl_PerVertex {\n"
13432 " vec4 gl_Position;\n"
13433 "};\n"
13434 "void main(){\n"
13435 " gl_Position = vec4(1);\n"
13436 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013437
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013438 char const *fsSource =
13439 "#version 450\n"
13440 "\n"
13441 "layout (constant_id = 0) const float r = 0.0f;\n"
13442 "layout(location = 0) out vec4 uFragColor;\n"
13443 "void main(){\n"
13444 " uFragColor = vec4(r,1,0,1);\n"
13445 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013446
13447 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13448 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13449
13450 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13451 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13452
13453 VkPipelineLayout pipeline_layout;
13454 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13455
13456 VkPipelineViewportStateCreateInfo vp_state_create_info = {};
13457 vp_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
13458 vp_state_create_info.viewportCount = 1;
13459 VkViewport viewport = {};
13460 vp_state_create_info.pViewports = &viewport;
13461 vp_state_create_info.scissorCount = 1;
13462 VkRect2D scissors = {};
13463 vp_state_create_info.pScissors = &scissors;
13464
13465 VkDynamicState scissor_state = VK_DYNAMIC_STATE_SCISSOR;
13466
13467 VkPipelineDynamicStateCreateInfo pipeline_dynamic_state_create_info = {};
13468 pipeline_dynamic_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
13469 pipeline_dynamic_state_create_info.dynamicStateCount = 1;
13470 pipeline_dynamic_state_create_info.pDynamicStates = &scissor_state;
13471
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013472 VkPipelineShaderStageCreateInfo shader_stage_create_info[2] = {vs.GetStageCreateInfo(), fs.GetStageCreateInfo()};
Mark Mueller098c9cb2016-09-08 09:01:57 -060013473
13474 VkPipelineVertexInputStateCreateInfo vertex_input_create_info = {};
13475 vertex_input_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
13476
13477 VkPipelineInputAssemblyStateCreateInfo input_assembly_create_info = {};
13478 input_assembly_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
13479 input_assembly_create_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
13480
13481 VkPipelineRasterizationStateCreateInfo rasterization_state_create_info = {};
13482 rasterization_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
13483 rasterization_state_create_info.pNext = nullptr;
13484 rasterization_state_create_info.lineWidth = 1.0f;
13485 rasterization_state_create_info.rasterizerDiscardEnable = true;
13486
13487 VkPipelineColorBlendAttachmentState color_blend_attachment_state = {};
13488 color_blend_attachment_state.blendEnable = VK_FALSE;
13489 color_blend_attachment_state.colorWriteMask = 0xf;
13490
13491 VkPipelineColorBlendStateCreateInfo color_blend_state_create_info = {};
13492 color_blend_state_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
13493 color_blend_state_create_info.attachmentCount = 1;
13494 color_blend_state_create_info.pAttachments = &color_blend_attachment_state;
13495
13496 VkGraphicsPipelineCreateInfo graphicspipe_create_info = {};
13497 graphicspipe_create_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
13498 graphicspipe_create_info.stageCount = 2;
13499 graphicspipe_create_info.pStages = shader_stage_create_info;
13500 graphicspipe_create_info.pVertexInputState = &vertex_input_create_info;
13501 graphicspipe_create_info.pInputAssemblyState = &input_assembly_create_info;
13502 graphicspipe_create_info.pViewportState = &vp_state_create_info;
13503 graphicspipe_create_info.pRasterizationState = &rasterization_state_create_info;
13504 graphicspipe_create_info.pColorBlendState = &color_blend_state_create_info;
13505 graphicspipe_create_info.pDynamicState = &pipeline_dynamic_state_create_info;
13506 graphicspipe_create_info.flags = VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT;
13507 graphicspipe_create_info.layout = pipeline_layout;
13508 graphicspipe_create_info.renderPass = renderPass();
13509
13510 VkPipelineCacheCreateInfo pipeline_cache_create_info = {};
13511 pipeline_cache_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
13512
13513 VkPipelineCache pipelineCache;
13514 ASSERT_VK_SUCCESS(vkCreatePipelineCache(m_device->device(), &pipeline_cache_create_info, nullptr, &pipelineCache));
13515
13516 // This structure maps constant ids to data locations.
13517 const VkSpecializationMapEntry entry =
13518 // id, offset, size
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013519 {0, 4, sizeof(uint32_t)}; // Challenge core validation by using a bogus offset.
Mark Mueller098c9cb2016-09-08 09:01:57 -060013520
13521 uint32_t data = 1;
13522
13523 // Set up the info describing spec map and data
13524 const VkSpecializationInfo specialization_info = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013525 1, &entry, 1 * sizeof(float), &data,
Mark Mueller098c9cb2016-09-08 09:01:57 -060013526 };
13527 shader_stage_create_info[0].pSpecializationInfo = &specialization_info;
13528
13529 VkPipeline pipeline;
13530 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_specialization_message);
13531 vkCreateGraphicsPipelines(m_device->device(), pipelineCache, 1, &graphicspipe_create_info, nullptr, &pipeline);
13532 m_errorMonitor->VerifyFound();
13533
13534 vkDestroyPipelineCache(m_device->device(), pipelineCache, nullptr);
13535 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13536}
13537
13538TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorTypeMismatch) {
13539 TEST_DESCRIPTION("Challenge core_validation with shader validation issues related to vkCreateGraphicsPipelines.");
13540
13541 ASSERT_NO_FATAL_FAILURE(InitState());
13542 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13543
13544 const char *descriptor_type_mismatch_message = "Type mismatch on descriptor slot 0.0 (used as type ";
13545
13546 VkDescriptorPoolSize descriptor_pool_type_count[2] = {};
13547 descriptor_pool_type_count[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13548 descriptor_pool_type_count[0].descriptorCount = 1;
13549 descriptor_pool_type_count[1].type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13550 descriptor_pool_type_count[1].descriptorCount = 1;
13551
13552 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13553 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13554 descriptor_pool_create_info.maxSets = 1;
13555 descriptor_pool_create_info.poolSizeCount = 2;
13556 descriptor_pool_create_info.pPoolSizes = descriptor_pool_type_count;
13557 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13558
13559 VkDescriptorPool descriptorset_pool;
13560 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13561
13562 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13563 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
13564 descriptorset_layout_binding.descriptorCount = 1;
13565 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_ALL;
Cody Northropa6484fd2017-03-10 14:13:49 -070013566 descriptorset_layout_binding.pImmutableSamplers = nullptr;
Mark Mueller098c9cb2016-09-08 09:01:57 -060013567
13568 VkDescriptorSetLayoutCreateInfo descriptorset_layout_create_info = {};
13569 descriptorset_layout_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
13570 descriptorset_layout_create_info.bindingCount = 1;
13571 descriptorset_layout_create_info.pBindings = &descriptorset_layout_binding;
13572
13573 VkDescriptorSetLayout descriptorset_layout;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013574 ASSERT_VK_SUCCESS(
13575 vkCreateDescriptorSetLayout(m_device->device(), &descriptorset_layout_create_info, nullptr, &descriptorset_layout));
Mark Mueller098c9cb2016-09-08 09:01:57 -060013576
13577 VkDescriptorSetAllocateInfo descriptorset_allocate_info = {};
13578 descriptorset_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
13579 descriptorset_allocate_info.descriptorSetCount = 1;
13580 descriptorset_allocate_info.descriptorPool = descriptorset_pool;
13581 descriptorset_allocate_info.pSetLayouts = &descriptorset_layout;
13582 VkDescriptorSet descriptorset;
13583 ASSERT_VK_SUCCESS(vkAllocateDescriptorSets(m_device->device(), &descriptorset_allocate_info, &descriptorset));
13584
13585 // Challenge core_validation with a non uniform buffer type.
13586 VkBufferTest storage_buffer_test(m_device, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT);
13587
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013588 char const *vsSource =
13589 "#version 450\n"
13590 "\n"
13591 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13592 " mat4 mvp;\n"
13593 "} ubuf;\n"
13594 "out gl_PerVertex {\n"
13595 " vec4 gl_Position;\n"
13596 "};\n"
13597 "void main(){\n"
13598 " gl_Position = ubuf.mvp * vec4(1);\n"
13599 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013600
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013601 char const *fsSource =
13602 "#version 450\n"
13603 "\n"
13604 "layout(location = 0) out vec4 uFragColor;\n"
13605 "void main(){\n"
13606 " uFragColor = vec4(0,1,0,1);\n"
13607 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013608
13609 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13610 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13611
13612 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13613 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13614 pipeline_layout_create_info.setLayoutCount = 1;
13615 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13616
13617 VkPipelineLayout pipeline_layout;
13618 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13619
13620 VkPipelineObj pipe(m_device);
13621 pipe.AddColorAttachment();
13622 pipe.AddShader(&vs);
13623 pipe.AddShader(&fs);
13624
13625 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_type_mismatch_message);
13626 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13627 m_errorMonitor->VerifyFound();
13628
13629 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13630 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13631 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13632}
13633
13634TEST_F(VkLayerTest, CreatePipelineCheckShaderDescriptorNotAccessible) {
13635 TEST_DESCRIPTION(
13636 "Create a pipeline in which a descriptor used by a shader stage does not include that stage in its stageFlags.");
13637
13638 ASSERT_NO_FATAL_FAILURE(InitState());
13639 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13640
13641 const char *descriptor_not_accessible_message = "Shader uses descriptor slot 0.0 (used as type ";
13642
13643 VkDescriptorPoolSize descriptor_pool_type_count = {};
13644 descriptor_pool_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13645 descriptor_pool_type_count.descriptorCount = 1;
13646
13647 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
13648 descriptor_pool_create_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
13649 descriptor_pool_create_info.maxSets = 1;
13650 descriptor_pool_create_info.poolSizeCount = 1;
13651 descriptor_pool_create_info.pPoolSizes = &descriptor_pool_type_count;
13652 descriptor_pool_create_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
13653
13654 VkDescriptorPool descriptorset_pool;
13655 ASSERT_VK_SUCCESS(vkCreateDescriptorPool(m_device->device(), &descriptor_pool_create_info, nullptr, &descriptorset_pool));
13656
13657 VkDescriptorSetLayoutBinding descriptorset_layout_binding = {};
13658 descriptorset_layout_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
13659 descriptorset_layout_binding.descriptorCount = 1;
13660 // Intentionally make the uniform buffer inaccessible to the vertex shader to challenge core_validation
13661 descriptorset_layout_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
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 VkBufferTest buffer_test(m_device, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
13682
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013683 char const *vsSource =
13684 "#version 450\n"
13685 "\n"
13686 "layout (std140, set = 0, binding = 0) uniform buf {\n"
13687 " mat4 mvp;\n"
13688 "} ubuf;\n"
13689 "out gl_PerVertex {\n"
13690 " vec4 gl_Position;\n"
13691 "};\n"
13692 "void main(){\n"
13693 " gl_Position = ubuf.mvp * vec4(1);\n"
13694 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013695
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013696 char const *fsSource =
13697 "#version 450\n"
13698 "\n"
13699 "layout(location = 0) out vec4 uFragColor;\n"
13700 "void main(){\n"
13701 " uFragColor = vec4(0,1,0,1);\n"
13702 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013703
13704 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13705 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13706
13707 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13708 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13709 pipeline_layout_create_info.setLayoutCount = 1;
13710 pipeline_layout_create_info.pSetLayouts = &descriptorset_layout;
13711
13712 VkPipelineLayout pipeline_layout;
13713 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13714
13715 VkPipelineObj pipe(m_device);
13716 pipe.AddColorAttachment();
13717 pipe.AddShader(&vs);
13718 pipe.AddShader(&fs);
13719
13720 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, descriptor_not_accessible_message);
13721 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13722 m_errorMonitor->VerifyFound();
13723
13724 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13725 vkDestroyDescriptorPool(m_device->device(), descriptorset_pool, nullptr);
13726 vkDestroyDescriptorSetLayout(m_device->device(), descriptorset_layout, nullptr);
13727}
13728
13729TEST_F(VkLayerTest, CreatePipelineCheckShaderPushConstantNotAccessible) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013730 TEST_DESCRIPTION(
13731 "Create a graphics pipleine in which a push constant range containing a push constant block member is not "
13732 "accessible from the current shader stage.");
Mark Mueller098c9cb2016-09-08 09:01:57 -060013733
13734 ASSERT_NO_FATAL_FAILURE(InitState());
13735 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13736
13737 const char *push_constant_not_accessible_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013738 "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 -060013739
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013740 char const *vsSource =
13741 "#version 450\n"
13742 "\n"
13743 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
13744 "out gl_PerVertex {\n"
13745 " vec4 gl_Position;\n"
13746 "};\n"
13747 "void main(){\n"
13748 " gl_Position = vec4(consts.x);\n"
13749 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013750
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013751 char const *fsSource =
13752 "#version 450\n"
13753 "\n"
13754 "layout(location = 0) out vec4 uFragColor;\n"
13755 "void main(){\n"
13756 " uFragColor = vec4(0,1,0,1);\n"
13757 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013758
13759 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13760 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13761
13762 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13763 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13764
13765 // Set up a push constant range
13766 VkPushConstantRange push_constant_ranges = {};
13767 // Set to the wrong stage to challenge core_validation
13768 push_constant_ranges.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
13769 push_constant_ranges.size = 4;
13770
13771 pipeline_layout_create_info.pPushConstantRanges = &push_constant_ranges;
13772 pipeline_layout_create_info.pushConstantRangeCount = 1;
13773
13774 VkPipelineLayout pipeline_layout;
13775 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13776
13777 VkPipelineObj pipe(m_device);
13778 pipe.AddColorAttachment();
13779 pipe.AddShader(&vs);
13780 pipe.AddShader(&fs);
13781
13782 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, push_constant_not_accessible_message);
13783 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13784 m_errorMonitor->VerifyFound();
13785
13786 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13787}
13788
13789TEST_F(VkLayerTest, CreatePipelineCheckShaderNotEnabled) {
13790 TEST_DESCRIPTION(
13791 "Create a graphics pipeline in which a capability declared by the shader requires a feature not enabled on the device.");
13792
13793 ASSERT_NO_FATAL_FAILURE(InitState());
13794 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13795
13796 const char *feature_not_enabled_message =
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070013797 "Shader requires VkPhysicalDeviceFeatures::shaderFloat64 but is not enabled on the device";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013798
13799 // Some awkward steps are required to test with custom device features.
13800 std::vector<const char *> device_extension_names;
13801 auto features = m_device->phy().features();
13802 // Disable support for 64 bit floats
13803 features.shaderFloat64 = false;
13804 // The sacrificial device object
13805 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
13806
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013807 char const *vsSource =
13808 "#version 450\n"
13809 "\n"
13810 "out gl_PerVertex {\n"
13811 " vec4 gl_Position;\n"
13812 "};\n"
13813 "void main(){\n"
13814 " gl_Position = vec4(1);\n"
13815 "}\n";
13816 char const *fsSource =
13817 "#version 450\n"
13818 "\n"
13819 "layout(location=0) out vec4 color;\n"
13820 "void main(){\n"
13821 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13822 " color = vec4(green);\n"
13823 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013824
13825 VkShaderObj vs(&test_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13826 VkShaderObj fs(&test_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13827
13828 VkRenderpassObj render_pass(&test_device);
Mark Mueller098c9cb2016-09-08 09:01:57 -060013829
13830 VkPipelineObj pipe(&test_device);
13831 pipe.AddColorAttachment();
13832 pipe.AddShader(&vs);
13833 pipe.AddShader(&fs);
13834
13835 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13836 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13837 VkPipelineLayout pipeline_layout;
13838 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(test_device.device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13839
13840 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, feature_not_enabled_message);
13841 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
13842 m_errorMonitor->VerifyFound();
13843
13844 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, nullptr);
13845}
13846
13847TEST_F(VkLayerTest, CreatePipelineCheckShaderBadCapability) {
13848 TEST_DESCRIPTION("Create a graphics pipeline in which a capability declared by the shader is not supported by Vulkan shaders.");
13849
13850 ASSERT_NO_FATAL_FAILURE(InitState());
13851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13852
13853 const char *bad_capability_message = "Shader declares capability 53, not supported in Vulkan.";
13854
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013855 char const *vsSource =
13856 "#version 450\n"
13857 "\n"
13858 "out gl_PerVertex {\n"
13859 " vec4 gl_Position;\n"
13860 "};\n"
13861 "layout(xfb_buffer = 1) out;"
13862 "void main(){\n"
13863 " gl_Position = vec4(1);\n"
13864 "}\n";
13865 char const *fsSource =
13866 "#version 450\n"
13867 "\n"
13868 "layout(location=0) out vec4 color;\n"
13869 "void main(){\n"
13870 " dvec4 green = vec4(0.0, 1.0, 0.0, 1.0);\n"
13871 " color = vec4(green);\n"
13872 "}\n";
Mark Mueller098c9cb2016-09-08 09:01:57 -060013873
13874 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13875 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13876
13877 VkPipelineObj pipe(m_device);
13878 pipe.AddColorAttachment();
13879 pipe.AddShader(&vs);
13880 pipe.AddShader(&fs);
13881
13882 VkPipelineLayoutCreateInfo pipeline_layout_create_info = {};
13883 pipeline_layout_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
13884 VkPipelineLayout pipeline_layout;
13885 ASSERT_VK_SUCCESS(vkCreatePipelineLayout(m_device->device(), &pipeline_layout_create_info, nullptr, &pipeline_layout));
13886
13887 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, bad_capability_message);
13888 pipe.CreateVKPipeline(pipeline_layout, renderPass());
13889 m_errorMonitor->VerifyFound();
13890
13891 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, nullptr);
13892}
13893
Karl Schultz6addd812016-02-02 17:17:23 -070013894TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013895 TEST_DESCRIPTION(
13896 "Test that an error is produced for a fragment shader input "
13897 "which is not present in the outputs of the previous stage");
Chris Forbes1cc79542016-07-20 11:13:44 +120013898
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013899 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060013900
Chris Forbes59cb88d2015-05-25 11:13:13 +120013901 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060013902 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013903
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013904 char const *vsSource =
13905 "#version 450\n"
13906 "\n"
13907 "out gl_PerVertex {\n"
13908 " vec4 gl_Position;\n"
13909 "};\n"
13910 "void main(){\n"
13911 " gl_Position = vec4(1);\n"
13912 "}\n";
13913 char const *fsSource =
13914 "#version 450\n"
13915 "\n"
13916 "layout(location=0) in float x;\n"
13917 "layout(location=0) out vec4 color;\n"
13918 "void main(){\n"
13919 " color = vec4(x);\n"
13920 "}\n";
Chris Forbes59cb88d2015-05-25 11:13:13 +120013921
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060013922 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13923 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013924
13925 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080013926 pipe.AddColorAttachment();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013927 pipe.AddShader(&vs);
13928 pipe.AddShader(&fs);
13929
Chris Forbes59cb88d2015-05-25 11:13:13 +120013930 VkDescriptorSetObj descriptorSet(m_device);
13931 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080013932 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes59cb88d2015-05-25 11:13:13 +120013933
Tony Barbour5781e8f2015-08-04 16:23:11 -060013934 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes59cb88d2015-05-25 11:13:13 +120013935
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013936 m_errorMonitor->VerifyFound();
Chris Forbes59cb88d2015-05-25 11:13:13 +120013937}
13938
Karl Schultz6addd812016-02-02 17:17:23 -070013939TEST_F(VkLayerTest, CreatePipelineFragmentInputNotProvidedInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013940 TEST_DESCRIPTION(
13941 "Test that an error is produced for a fragment shader input "
13942 "within an interace block, which is not present in the outputs "
13943 "of the previous stage.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060013944 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not written by vertex shader");
Chris Forbesa3e85f62016-01-15 14:53:11 +130013945
13946 ASSERT_NO_FATAL_FAILURE(InitState());
13947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13948
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013949 char const *vsSource =
13950 "#version 450\n"
13951 "\n"
13952 "out gl_PerVertex {\n"
13953 " vec4 gl_Position;\n"
13954 "};\n"
13955 "void main(){\n"
13956 " gl_Position = vec4(1);\n"
13957 "}\n";
13958 char const *fsSource =
13959 "#version 450\n"
13960 "\n"
13961 "in block { layout(location=0) float x; } ins;\n"
13962 "layout(location=0) out vec4 color;\n"
13963 "void main(){\n"
13964 " color = vec4(ins.x);\n"
13965 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130013966
13967 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
13968 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
13969
13970 VkPipelineObj pipe(m_device);
13971 pipe.AddColorAttachment();
13972 pipe.AddShader(&vs);
13973 pipe.AddShader(&fs);
13974
13975 VkDescriptorSetObj descriptorSet(m_device);
13976 descriptorSet.AppendDummy();
13977 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
13978
13979 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
13980
Chris Forbes8f36a8a2016-04-07 13:21:07 +120013981 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130013982}
13983
Karl Schultz6addd812016-02-02 17:17:23 -070013984TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchArraySize) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013985 TEST_DESCRIPTION(
13986 "Test that an error is produced for mismatched array sizes "
13987 "across the vertex->fragment shader interface");
13988 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
13989 "Type mismatch on location 0.0: 'ptr to "
13990 "output arr[2] of float32' vs 'ptr to "
13991 "input arr[1] of float32'");
Chris Forbes0036fd12016-01-26 14:19:49 +130013992
13993 ASSERT_NO_FATAL_FAILURE(InitState());
13994 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
13995
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070013996 char const *vsSource =
13997 "#version 450\n"
13998 "\n"
13999 "layout(location=0) out float x[2];\n"
14000 "out gl_PerVertex {\n"
14001 " vec4 gl_Position;\n"
14002 "};\n"
14003 "void main(){\n"
14004 " x[0] = 0; x[1] = 0;\n"
14005 " gl_Position = vec4(1);\n"
14006 "}\n";
14007 char const *fsSource =
14008 "#version 450\n"
14009 "\n"
14010 "layout(location=0) in float x[1];\n"
14011 "layout(location=0) out vec4 color;\n"
14012 "void main(){\n"
14013 " color = vec4(x[0]);\n"
14014 "}\n";
Chris Forbes0036fd12016-01-26 14:19:49 +130014015
14016 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14017 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14018
14019 VkPipelineObj pipe(m_device);
14020 pipe.AddColorAttachment();
14021 pipe.AddShader(&vs);
14022 pipe.AddShader(&fs);
14023
14024 VkDescriptorSetObj descriptorSet(m_device);
14025 descriptorSet.AppendDummy();
14026 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14027
14028 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14029
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014030 m_errorMonitor->VerifyFound();
Chris Forbes0036fd12016-01-26 14:19:49 +130014031}
14032
Karl Schultz6addd812016-02-02 17:17:23 -070014033TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014034 TEST_DESCRIPTION(
14035 "Test that an error is produced for mismatched types across "
14036 "the vertex->fragment shader interface");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014037 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014038
Chris Forbesb56af562015-05-25 11:13:17 +120014039 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014040 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesb56af562015-05-25 11:13:17 +120014041
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014042 char const *vsSource =
14043 "#version 450\n"
14044 "\n"
14045 "layout(location=0) out int x;\n"
14046 "out gl_PerVertex {\n"
14047 " vec4 gl_Position;\n"
14048 "};\n"
14049 "void main(){\n"
14050 " x = 0;\n"
14051 " gl_Position = vec4(1);\n"
14052 "}\n";
14053 char const *fsSource =
14054 "#version 450\n"
14055 "\n"
14056 "layout(location=0) in float x;\n" /* VS writes int */
14057 "layout(location=0) out vec4 color;\n"
14058 "void main(){\n"
14059 " color = vec4(x);\n"
14060 "}\n";
Chris Forbesb56af562015-05-25 11:13:17 +120014061
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014062 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14063 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesb56af562015-05-25 11:13:17 +120014064
14065 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014066 pipe.AddColorAttachment();
Chris Forbesb56af562015-05-25 11:13:17 +120014067 pipe.AddShader(&vs);
14068 pipe.AddShader(&fs);
14069
Chris Forbesb56af562015-05-25 11:13:17 +120014070 VkDescriptorSetObj descriptorSet(m_device);
14071 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014072 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesb56af562015-05-25 11:13:17 +120014073
Tony Barbour5781e8f2015-08-04 16:23:11 -060014074 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesb56af562015-05-25 11:13:17 +120014075
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014076 m_errorMonitor->VerifyFound();
Chris Forbesb56af562015-05-25 11:13:17 +120014077}
14078
Karl Schultz6addd812016-02-02 17:17:23 -070014079TEST_F(VkLayerTest, CreatePipelineVsFsTypeMismatchInBlock) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014080 TEST_DESCRIPTION(
14081 "Test that an error is produced for mismatched types across "
14082 "the vertex->fragment shader interface, when the variable is contained within "
14083 "an interface block");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014084 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Type mismatch on location 0");
Chris Forbesa3e85f62016-01-15 14:53:11 +130014085
14086 ASSERT_NO_FATAL_FAILURE(InitState());
14087 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14088
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014089 char const *vsSource =
14090 "#version 450\n"
14091 "\n"
14092 "out block { layout(location=0) int x; } outs;\n"
14093 "out gl_PerVertex {\n"
14094 " vec4 gl_Position;\n"
14095 "};\n"
14096 "void main(){\n"
14097 " outs.x = 0;\n"
14098 " gl_Position = vec4(1);\n"
14099 "}\n";
14100 char const *fsSource =
14101 "#version 450\n"
14102 "\n"
14103 "in block { layout(location=0) float x; } ins;\n" /* VS writes int */
14104 "layout(location=0) out vec4 color;\n"
14105 "void main(){\n"
14106 " color = vec4(ins.x);\n"
14107 "}\n";
Chris Forbesa3e85f62016-01-15 14:53:11 +130014108
14109 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14110 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14111
14112 VkPipelineObj pipe(m_device);
14113 pipe.AddColorAttachment();
14114 pipe.AddShader(&vs);
14115 pipe.AddShader(&fs);
14116
14117 VkDescriptorSetObj descriptorSet(m_device);
14118 descriptorSet.AppendDummy();
14119 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14120
14121 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14122
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014123 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014124}
14125
14126TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByLocation) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014127 TEST_DESCRIPTION(
14128 "Test that an error is produced for location mismatches across "
14129 "the vertex->fragment shader interface; This should manifest as a not-written/not-consumed "
14130 "pair, but flushes out broken walking of the interfaces");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014131 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 +130014132
14133 ASSERT_NO_FATAL_FAILURE(InitState());
14134 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14135
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014136 char const *vsSource =
14137 "#version 450\n"
14138 "\n"
14139 "out block { layout(location=1) float x; } outs;\n"
14140 "out gl_PerVertex {\n"
14141 " vec4 gl_Position;\n"
14142 "};\n"
14143 "void main(){\n"
14144 " outs.x = 0;\n"
14145 " gl_Position = vec4(1);\n"
14146 "}\n";
14147 char const *fsSource =
14148 "#version 450\n"
14149 "\n"
14150 "in block { layout(location=0) float x; } ins;\n"
14151 "layout(location=0) out vec4 color;\n"
14152 "void main(){\n"
14153 " color = vec4(ins.x);\n"
14154 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014155
14156 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14157 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14158
14159 VkPipelineObj pipe(m_device);
14160 pipe.AddColorAttachment();
14161 pipe.AddShader(&vs);
14162 pipe.AddShader(&fs);
14163
14164 VkDescriptorSetObj descriptorSet(m_device);
14165 descriptorSet.AppendDummy();
14166 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14167
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014168 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbese9928822016-02-17 14:44:52 +130014169 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14170
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014171 m_errorMonitor->VerifyFound();
Chris Forbese9928822016-02-17 14:44:52 +130014172}
14173
14174TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByComponent) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014175 TEST_DESCRIPTION(
14176 "Test that an error is produced for component mismatches across the "
14177 "vertex->fragment shader interface. It's not enough to have the same set of locations in "
14178 "use; matching is defined in terms of spirv variables.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014179 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 +130014180
14181 ASSERT_NO_FATAL_FAILURE(InitState());
14182 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14183
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014184 char const *vsSource =
14185 "#version 450\n"
14186 "\n"
14187 "out block { layout(location=0, component=0) float x; } outs;\n"
14188 "out gl_PerVertex {\n"
14189 " vec4 gl_Position;\n"
14190 "};\n"
14191 "void main(){\n"
14192 " outs.x = 0;\n"
14193 " gl_Position = vec4(1);\n"
14194 "}\n";
14195 char const *fsSource =
14196 "#version 450\n"
14197 "\n"
14198 "in block { layout(location=0, component=1) float x; } ins;\n"
14199 "layout(location=0) out vec4 color;\n"
14200 "void main(){\n"
14201 " color = vec4(ins.x);\n"
14202 "}\n";
Chris Forbese9928822016-02-17 14:44:52 +130014203
14204 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14205 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14206
14207 VkPipelineObj pipe(m_device);
14208 pipe.AddColorAttachment();
14209 pipe.AddShader(&vs);
14210 pipe.AddShader(&fs);
14211
14212 VkDescriptorSetObj descriptorSet(m_device);
14213 descriptorSet.AppendDummy();
14214 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14215
14216 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14217
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014218 m_errorMonitor->VerifyFound();
Chris Forbesa3e85f62016-01-15 14:53:11 +130014219}
14220
Chris Forbes1f3b0152016-11-30 12:48:40 +130014221TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecision) {
14222 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14223
14224 ASSERT_NO_FATAL_FAILURE(InitState());
14225 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14226
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014227 char const *vsSource =
14228 "#version 450\n"
14229 "layout(location=0) out mediump float x;\n"
14230 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14231 char const *fsSource =
14232 "#version 450\n"
14233 "layout(location=0) in highp float x;\n"
14234 "layout(location=0) out vec4 color;\n"
14235 "void main() { color = vec4(x); }\n";
Chris Forbes1f3b0152016-11-30 12:48:40 +130014236
14237 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14238 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14239
14240 VkPipelineObj pipe(m_device);
14241 pipe.AddColorAttachment();
14242 pipe.AddShader(&vs);
14243 pipe.AddShader(&fs);
14244
14245 VkDescriptorSetObj descriptorSet(m_device);
14246 descriptorSet.AppendDummy();
14247 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14248
14249 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14250
14251 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14252
14253 m_errorMonitor->VerifyFound();
14254}
14255
Chris Forbes870a39e2016-11-30 12:55:56 +130014256TEST_F(VkLayerTest, CreatePipelineVsFsMismatchByPrecisionBlock) {
14257 TEST_DESCRIPTION("Test that the RelaxedPrecision decoration is validated to match");
14258
14259 ASSERT_NO_FATAL_FAILURE(InitState());
14260 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14261
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014262 char const *vsSource =
14263 "#version 450\n"
14264 "out block { layout(location=0) mediump float x; };\n"
14265 "void main() { gl_Position = vec4(0); x = 1.0; }\n";
14266 char const *fsSource =
14267 "#version 450\n"
14268 "in block { layout(location=0) highp float x; };\n"
14269 "layout(location=0) out vec4 color;\n"
14270 "void main() { color = vec4(x); }\n";
Chris Forbes870a39e2016-11-30 12:55:56 +130014271
14272 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14273 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14274
14275 VkPipelineObj pipe(m_device);
14276 pipe.AddColorAttachment();
14277 pipe.AddShader(&vs);
14278 pipe.AddShader(&fs);
14279
14280 VkDescriptorSetObj descriptorSet(m_device);
14281 descriptorSet.AppendDummy();
14282 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14283
14284 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "differ in precision");
14285
14286 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14287
14288 m_errorMonitor->VerifyFound();
14289}
14290
Karl Schultz6addd812016-02-02 17:17:23 -070014291TEST_F(VkLayerTest, CreatePipelineAttribNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014292 TEST_DESCRIPTION(
14293 "Test that a warning is produced for a vertex attribute which is "
14294 "not consumed by the vertex shader");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014295 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014296
Chris Forbesde136e02015-05-25 11:13:28 +120014297 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014298 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesde136e02015-05-25 11:13:28 +120014299
14300 VkVertexInputBindingDescription input_binding;
14301 memset(&input_binding, 0, sizeof(input_binding));
14302
14303 VkVertexInputAttributeDescription input_attrib;
14304 memset(&input_attrib, 0, sizeof(input_attrib));
14305 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14306
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014307 char const *vsSource =
14308 "#version 450\n"
14309 "\n"
14310 "out gl_PerVertex {\n"
14311 " vec4 gl_Position;\n"
14312 "};\n"
14313 "void main(){\n"
14314 " gl_Position = vec4(1);\n"
14315 "}\n";
14316 char const *fsSource =
14317 "#version 450\n"
14318 "\n"
14319 "layout(location=0) out vec4 color;\n"
14320 "void main(){\n"
14321 " color = vec4(1);\n"
14322 "}\n";
Chris Forbesde136e02015-05-25 11:13:28 +120014323
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014324 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14325 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesde136e02015-05-25 11:13:28 +120014326
14327 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014328 pipe.AddColorAttachment();
Chris Forbesde136e02015-05-25 11:13:28 +120014329 pipe.AddShader(&vs);
14330 pipe.AddShader(&fs);
14331
14332 pipe.AddVertexInputBindings(&input_binding, 1);
14333 pipe.AddVertexInputAttribs(&input_attrib, 1);
14334
Chris Forbesde136e02015-05-25 11:13:28 +120014335 VkDescriptorSetObj descriptorSet(m_device);
14336 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014337 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesde136e02015-05-25 11:13:28 +120014338
Tony Barbour5781e8f2015-08-04 16:23:11 -060014339 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesde136e02015-05-25 11:13:28 +120014340
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014341 m_errorMonitor->VerifyFound();
Chris Forbesde136e02015-05-25 11:13:28 +120014342}
14343
Karl Schultz6addd812016-02-02 17:17:23 -070014344TEST_F(VkLayerTest, CreatePipelineAttribLocationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014345 TEST_DESCRIPTION(
14346 "Test that a warning is produced for a location mismatch on "
14347 "vertex attributes. This flushes out bad behavior in the interface walker");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, "location 0 not consumed by vertex shader");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014349
14350 ASSERT_NO_FATAL_FAILURE(InitState());
14351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14352
14353 VkVertexInputBindingDescription input_binding;
14354 memset(&input_binding, 0, sizeof(input_binding));
14355
14356 VkVertexInputAttributeDescription input_attrib;
14357 memset(&input_attrib, 0, sizeof(input_attrib));
14358 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14359
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014360 char const *vsSource =
14361 "#version 450\n"
14362 "\n"
14363 "layout(location=1) in float x;\n"
14364 "out gl_PerVertex {\n"
14365 " vec4 gl_Position;\n"
14366 "};\n"
14367 "void main(){\n"
14368 " gl_Position = vec4(x);\n"
14369 "}\n";
14370 char const *fsSource =
14371 "#version 450\n"
14372 "\n"
14373 "layout(location=0) out vec4 color;\n"
14374 "void main(){\n"
14375 " color = vec4(1);\n"
14376 "}\n";
Chris Forbes7d83cd52016-01-15 11:32:03 +130014377
14378 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14379 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14380
14381 VkPipelineObj pipe(m_device);
14382 pipe.AddColorAttachment();
14383 pipe.AddShader(&vs);
14384 pipe.AddShader(&fs);
14385
14386 pipe.AddVertexInputBindings(&input_binding, 1);
14387 pipe.AddVertexInputAttribs(&input_attrib, 1);
14388
14389 VkDescriptorSetObj descriptorSet(m_device);
14390 descriptorSet.AppendDummy();
14391 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14392
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070014393 m_errorMonitor->SetUnexpectedError("Vertex shader consumes input at location 1 but not provided");
Chris Forbes7d83cd52016-01-15 11:32:03 +130014394 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14395
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014396 m_errorMonitor->VerifyFound();
Chris Forbes7d83cd52016-01-15 11:32:03 +130014397}
14398
Karl Schultz6addd812016-02-02 17:17:23 -070014399TEST_F(VkLayerTest, CreatePipelineAttribNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014400 TEST_DESCRIPTION(
14401 "Test that an error is produced for a vertex shader input which is not "
14402 "provided by a vertex attribute");
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014403 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14404 "Vertex shader consumes input at location 0 but not provided");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014405
Chris Forbes62e8e502015-05-25 11:13:29 +120014406 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014407 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes62e8e502015-05-25 11:13:29 +120014408
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014409 char const *vsSource =
14410 "#version 450\n"
14411 "\n"
14412 "layout(location=0) in vec4 x;\n" /* not provided */
14413 "out gl_PerVertex {\n"
14414 " vec4 gl_Position;\n"
14415 "};\n"
14416 "void main(){\n"
14417 " gl_Position = x;\n"
14418 "}\n";
14419 char const *fsSource =
14420 "#version 450\n"
14421 "\n"
14422 "layout(location=0) out vec4 color;\n"
14423 "void main(){\n"
14424 " color = vec4(1);\n"
14425 "}\n";
Chris Forbes62e8e502015-05-25 11:13:29 +120014426
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014427 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14428 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes62e8e502015-05-25 11:13:29 +120014429
14430 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014431 pipe.AddColorAttachment();
Chris Forbes62e8e502015-05-25 11:13:29 +120014432 pipe.AddShader(&vs);
14433 pipe.AddShader(&fs);
14434
Chris Forbes62e8e502015-05-25 11:13:29 +120014435 VkDescriptorSetObj descriptorSet(m_device);
14436 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014437 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes62e8e502015-05-25 11:13:29 +120014438
Tony Barbour5781e8f2015-08-04 16:23:11 -060014439 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes62e8e502015-05-25 11:13:29 +120014440
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014441 m_errorMonitor->VerifyFound();
Chris Forbes62e8e502015-05-25 11:13:29 +120014442}
14443
Karl Schultz6addd812016-02-02 17:17:23 -070014444TEST_F(VkLayerTest, CreatePipelineAttribTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014445 TEST_DESCRIPTION(
14446 "Test that an error is produced for a mismatch between the "
14447 "fundamental type (float/int/uint) of an attribute and the "
14448 "vertex shader input that consumes it");
Mike Weiblen15bd38e2016-10-03 19:19:41 -060014449 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 -060014450
Chris Forbesc97d98e2015-05-25 11:13:31 +120014451 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014453
14454 VkVertexInputBindingDescription input_binding;
14455 memset(&input_binding, 0, sizeof(input_binding));
14456
14457 VkVertexInputAttributeDescription input_attrib;
14458 memset(&input_attrib, 0, sizeof(input_attrib));
14459 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14460
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014461 char const *vsSource =
14462 "#version 450\n"
14463 "\n"
14464 "layout(location=0) in int x;\n" /* attrib provided float */
14465 "out gl_PerVertex {\n"
14466 " vec4 gl_Position;\n"
14467 "};\n"
14468 "void main(){\n"
14469 " gl_Position = vec4(x);\n"
14470 "}\n";
14471 char const *fsSource =
14472 "#version 450\n"
14473 "\n"
14474 "layout(location=0) out vec4 color;\n"
14475 "void main(){\n"
14476 " color = vec4(1);\n"
14477 "}\n";
Chris Forbesc97d98e2015-05-25 11:13:31 +120014478
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014479 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14480 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014481
14482 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014483 pipe.AddColorAttachment();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014484 pipe.AddShader(&vs);
14485 pipe.AddShader(&fs);
14486
14487 pipe.AddVertexInputBindings(&input_binding, 1);
14488 pipe.AddVertexInputAttribs(&input_attrib, 1);
14489
Chris Forbesc97d98e2015-05-25 11:13:31 +120014490 VkDescriptorSetObj descriptorSet(m_device);
14491 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014492 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesc97d98e2015-05-25 11:13:31 +120014493
Tony Barbour5781e8f2015-08-04 16:23:11 -060014494 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesc97d98e2015-05-25 11:13:31 +120014495
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014496 m_errorMonitor->VerifyFound();
Chris Forbesc97d98e2015-05-25 11:13:31 +120014497}
14498
Chris Forbesc68b43c2016-04-06 11:18:47 +120014499TEST_F(VkLayerTest, CreatePipelineDuplicateStage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014500 TEST_DESCRIPTION(
14501 "Test that an error is produced for a pipeline containing multiple "
14502 "shaders for the same stage");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014503 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14504 "Multiple shaders provided for stage VK_SHADER_STAGE_VERTEX_BIT");
Chris Forbesc68b43c2016-04-06 11:18:47 +120014505
14506 ASSERT_NO_FATAL_FAILURE(InitState());
14507 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14508
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014509 char const *vsSource =
14510 "#version 450\n"
14511 "\n"
14512 "out gl_PerVertex {\n"
14513 " vec4 gl_Position;\n"
14514 "};\n"
14515 "void main(){\n"
14516 " gl_Position = vec4(1);\n"
14517 "}\n";
14518 char const *fsSource =
14519 "#version 450\n"
14520 "\n"
14521 "layout(location=0) out vec4 color;\n"
14522 "void main(){\n"
14523 " color = vec4(1);\n"
14524 "}\n";
Chris Forbesc68b43c2016-04-06 11:18:47 +120014525
14526 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14527 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14528
14529 VkPipelineObj pipe(m_device);
14530 pipe.AddColorAttachment();
14531 pipe.AddShader(&vs);
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014532 pipe.AddShader(&vs); // intentionally duplicate vertex shader attachment
Chris Forbesc68b43c2016-04-06 11:18:47 +120014533 pipe.AddShader(&fs);
14534
14535 VkDescriptorSetObj descriptorSet(m_device);
14536 descriptorSet.AppendDummy();
14537 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14538
14539 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14540
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014541 m_errorMonitor->VerifyFound();
Chris Forbesc68b43c2016-04-06 11:18:47 +120014542}
14543
Chris Forbes82ff92a2016-09-09 10:50:24 +120014544TEST_F(VkLayerTest, CreatePipelineMissingEntrypoint) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "No entrypoint found named `foo`");
Chris Forbes82ff92a2016-09-09 10:50:24 +120014546
14547 ASSERT_NO_FATAL_FAILURE(InitState());
14548 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14549
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014550 char const *vsSource =
14551 "#version 450\n"
14552 "out gl_PerVertex {\n"
14553 " vec4 gl_Position;\n"
14554 "};\n"
14555 "void main(){\n"
14556 " gl_Position = vec4(0);\n"
14557 "}\n";
14558 char const *fsSource =
14559 "#version 450\n"
14560 "\n"
14561 "layout(location=0) out vec4 color;\n"
14562 "void main(){\n"
14563 " color = vec4(1);\n"
14564 "}\n";
Chris Forbes82ff92a2016-09-09 10:50:24 +120014565
14566 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14567 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this, "foo");
14568
14569 VkPipelineObj pipe(m_device);
14570 pipe.AddColorAttachment();
14571 pipe.AddShader(&vs);
14572 pipe.AddShader(&fs);
14573
14574 VkDescriptorSetObj descriptorSet(m_device);
14575 descriptorSet.AppendDummy();
14576 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14577
14578 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14579
14580 m_errorMonitor->VerifyFound();
14581}
14582
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014583TEST_F(VkLayerTest, CreatePipelineDepthStencilRequired) {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014584 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14585 "pDepthStencilState is NULL when rasterization is enabled and subpass "
14586 "uses a depth/stencil attachment");
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014587
14588 ASSERT_NO_FATAL_FAILURE(InitState());
14589 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14590
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014591 char const *vsSource =
14592 "#version 450\n"
14593 "void main(){ gl_Position = vec4(0); }\n";
14594 char const *fsSource =
14595 "#version 450\n"
14596 "\n"
14597 "layout(location=0) out vec4 color;\n"
14598 "void main(){\n"
14599 " color = vec4(1);\n"
14600 "}\n";
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014601
14602 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14603 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14604
14605 VkPipelineObj pipe(m_device);
14606 pipe.AddColorAttachment();
14607 pipe.AddShader(&vs);
14608 pipe.AddShader(&fs);
14609
14610 VkDescriptorSetObj descriptorSet(m_device);
14611 descriptorSet.AppendDummy();
14612 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14613
14614 VkAttachmentDescription attachments[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014615 {
14616 0, VK_FORMAT_B8G8R8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14617 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14618 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014619 },
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014620 {
14621 0, VK_FORMAT_D16_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
14622 VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_IMAGE_LAYOUT_UNDEFINED,
14623 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014624 },
14625 };
14626 VkAttachmentReference refs[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014627 {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL}, {1, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL},
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014628 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070014629 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &refs[0], nullptr, &refs[1], 0, nullptr};
14630 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, attachments, 1, &subpass, 0, nullptr};
Chris Forbesae9d8cd2016-09-13 16:32:57 +120014631 VkRenderPass rp;
14632 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
14633 ASSERT_VK_SUCCESS(err);
14634
14635 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), rp);
14636
14637 m_errorMonitor->VerifyFound();
14638
14639 vkDestroyRenderPass(m_device->device(), rp, nullptr);
14640}
14641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014642TEST_F(VkLayerTest, CreatePipelineTessPatchDecorationMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014643 TEST_DESCRIPTION(
14644 "Test that an error is produced for a variable output from "
14645 "the TCS without the patch decoration, but consumed in the TES "
14646 "with the decoration.");
14647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14648 "is per-vertex in tessellation control shader stage "
14649 "but per-patch in tessellation evaluation shader stage");
Chris Forbesa0193bc2016-04-04 19:19:47 +120014650
14651 ASSERT_NO_FATAL_FAILURE(InitState());
14652 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14653
Chris Forbesc1e852d2016-04-04 19:26:42 +120014654 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070014655 printf(" Device does not support tessellation shaders; skipped.\n");
Chris Forbesc1e852d2016-04-04 19:26:42 +120014656 return;
14657 }
14658
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014659 char const *vsSource =
14660 "#version 450\n"
14661 "void main(){}\n";
14662 char const *tcsSource =
14663 "#version 450\n"
14664 "layout(location=0) out int x[];\n"
14665 "layout(vertices=3) out;\n"
14666 "void main(){\n"
14667 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
14668 " gl_TessLevelInner[0] = 1;\n"
14669 " x[gl_InvocationID] = gl_InvocationID;\n"
14670 "}\n";
14671 char const *tesSource =
14672 "#version 450\n"
14673 "layout(triangles, equal_spacing, cw) in;\n"
14674 "layout(location=0) patch in int x;\n"
14675 "out gl_PerVertex { vec4 gl_Position; };\n"
14676 "void main(){\n"
14677 " gl_Position.xyz = gl_TessCoord;\n"
14678 " gl_Position.w = x;\n"
14679 "}\n";
14680 char const *fsSource =
14681 "#version 450\n"
14682 "layout(location=0) out vec4 color;\n"
14683 "void main(){\n"
14684 " color = vec4(1);\n"
14685 "}\n";
Chris Forbesa0193bc2016-04-04 19:19:47 +120014686
14687 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14688 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
14689 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
14690 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14691
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014692 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
14693 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014694
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014695 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Chris Forbesa0193bc2016-04-04 19:19:47 +120014696
14697 VkPipelineObj pipe(m_device);
14698 pipe.SetInputAssembly(&iasci);
14699 pipe.SetTessellation(&tsci);
14700 pipe.AddColorAttachment();
14701 pipe.AddShader(&vs);
14702 pipe.AddShader(&tcs);
14703 pipe.AddShader(&tes);
14704 pipe.AddShader(&fs);
14705
14706 VkDescriptorSetObj descriptorSet(m_device);
14707 descriptorSet.AppendDummy();
14708 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14709
14710 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14711
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014712 m_errorMonitor->VerifyFound();
Chris Forbesa0193bc2016-04-04 19:19:47 +120014713}
14714
Karl Schultz6addd812016-02-02 17:17:23 -070014715TEST_F(VkLayerTest, CreatePipelineAttribBindingConflict) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014716 TEST_DESCRIPTION(
14717 "Test that an error is produced for a vertex attribute setup where multiple "
14718 "bindings provide the same location");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014719 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
14720 "Duplicate vertex input binding descriptions for binding 0");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014721
Chris Forbes280ba2c2015-06-12 11:16:41 +120014722 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehlisc9ac2b62015-09-11 12:57:55 -060014723 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014724
14725 /* Two binding descriptions for binding 0 */
14726 VkVertexInputBindingDescription input_bindings[2];
14727 memset(input_bindings, 0, sizeof(input_bindings));
14728
14729 VkVertexInputAttributeDescription input_attrib;
14730 memset(&input_attrib, 0, sizeof(input_attrib));
14731 input_attrib.format = VK_FORMAT_R32_SFLOAT;
14732
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014733 char const *vsSource =
14734 "#version 450\n"
14735 "\n"
14736 "layout(location=0) in float x;\n" /* attrib provided float */
14737 "out gl_PerVertex {\n"
14738 " vec4 gl_Position;\n"
14739 "};\n"
14740 "void main(){\n"
14741 " gl_Position = vec4(x);\n"
14742 "}\n";
14743 char const *fsSource =
14744 "#version 450\n"
14745 "\n"
14746 "layout(location=0) out vec4 color;\n"
14747 "void main(){\n"
14748 " color = vec4(1);\n"
14749 "}\n";
Chris Forbes280ba2c2015-06-12 11:16:41 +120014750
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014751 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14752 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014753
14754 VkPipelineObj pipe(m_device);
Chia-I Wu08accc62015-07-07 11:50:03 +080014755 pipe.AddColorAttachment();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014756 pipe.AddShader(&vs);
14757 pipe.AddShader(&fs);
14758
14759 pipe.AddVertexInputBindings(input_bindings, 2);
14760 pipe.AddVertexInputAttribs(&input_attrib, 1);
14761
Chris Forbes280ba2c2015-06-12 11:16:41 +120014762 VkDescriptorSetObj descriptorSet(m_device);
14763 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014764 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes280ba2c2015-06-12 11:16:41 +120014765
Tony Barbour5781e8f2015-08-04 16:23:11 -060014766 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes280ba2c2015-06-12 11:16:41 +120014767
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014768 m_errorMonitor->VerifyFound();
Chris Forbes280ba2c2015-06-12 11:16:41 +120014769}
Chris Forbes8f68b562015-05-25 11:13:32 +120014770
Karl Schultz6addd812016-02-02 17:17:23 -070014771TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotWritten) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014772 TEST_DESCRIPTION(
14773 "Test that an error is produced for a fragment shader which does not "
14774 "provide an output for one of the pipeline's color attachments");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014775 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Attachment 0 not written by fragment shader");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014776
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014777 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014778
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014779 char const *vsSource =
14780 "#version 450\n"
14781 "\n"
14782 "out gl_PerVertex {\n"
14783 " vec4 gl_Position;\n"
14784 "};\n"
14785 "void main(){\n"
14786 " gl_Position = vec4(1);\n"
14787 "}\n";
14788 char const *fsSource =
14789 "#version 450\n"
14790 "\n"
14791 "void main(){\n"
14792 "}\n";
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014793
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014794 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14795 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014796
14797 VkPipelineObj pipe(m_device);
14798 pipe.AddShader(&vs);
14799 pipe.AddShader(&fs);
14800
Chia-I Wu08accc62015-07-07 11:50:03 +080014801 /* set up CB 0, not written */
14802 pipe.AddColorAttachment();
14803 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014804
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014805 VkDescriptorSetObj descriptorSet(m_device);
14806 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014807 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014808
Tony Barbour5781e8f2015-08-04 16:23:11 -060014809 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014810
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014811 m_errorMonitor->VerifyFound();
Chris Forbes4d6d1e52015-05-25 11:13:40 +120014812}
14813
Karl Schultz6addd812016-02-02 17:17:23 -070014814TEST_F(VkLayerTest, CreatePipelineFragmentOutputNotConsumed) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014815 TEST_DESCRIPTION(
14816 "Test that a warning is produced for a fragment shader which provides a spurious "
14817 "output with no matching attachment");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014818 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mike Weiblencce7ec72016-10-17 19:33:05 -060014819 "fragment shader writes to output location 1 with no matching attachment");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014820
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014821 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014822
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014823 char const *vsSource =
14824 "#version 450\n"
14825 "\n"
14826 "out gl_PerVertex {\n"
14827 " vec4 gl_Position;\n"
14828 "};\n"
14829 "void main(){\n"
14830 " gl_Position = vec4(1);\n"
14831 "}\n";
14832 char const *fsSource =
14833 "#version 450\n"
14834 "\n"
14835 "layout(location=0) out vec4 x;\n"
14836 "layout(location=1) out vec4 y;\n" /* no matching attachment for this */
14837 "void main(){\n"
14838 " x = vec4(1);\n"
14839 " y = vec4(1);\n"
14840 "}\n";
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014841
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014842 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14843 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014844
14845 VkPipelineObj pipe(m_device);
14846 pipe.AddShader(&vs);
14847 pipe.AddShader(&fs);
14848
Chia-I Wu08accc62015-07-07 11:50:03 +080014849 /* set up CB 0, not written */
14850 pipe.AddColorAttachment();
14851 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014852 /* FS writes CB 1, but we don't configure it */
14853
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014854 VkDescriptorSetObj descriptorSet(m_device);
14855 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014856 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014857
Tony Barbour5781e8f2015-08-04 16:23:11 -060014858 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014859
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014860 m_errorMonitor->VerifyFound();
Chris Forbesf3fffaa2015-05-25 11:13:43 +120014861}
14862
Karl Schultz6addd812016-02-02 17:17:23 -070014863TEST_F(VkLayerTest, CreatePipelineFragmentOutputTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014864 TEST_DESCRIPTION(
14865 "Test that an error is produced for a mismatch between the fundamental "
14866 "type of an fragment shader output variable, and the format of the corresponding attachment");
Mike Weiblencce7ec72016-10-17 19:33:05 -060014867 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "does not match fragment shader output type");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014868
Chris Forbesa36d69e2015-05-25 11:13:44 +120014869 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014870
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014871 char const *vsSource =
14872 "#version 450\n"
14873 "\n"
14874 "out gl_PerVertex {\n"
14875 " vec4 gl_Position;\n"
14876 "};\n"
14877 "void main(){\n"
14878 " gl_Position = vec4(1);\n"
14879 "}\n";
14880 char const *fsSource =
14881 "#version 450\n"
14882 "\n"
14883 "layout(location=0) out ivec4 x;\n" /* not UNORM */
14884 "void main(){\n"
14885 " x = ivec4(1);\n"
14886 "}\n";
Chris Forbesa36d69e2015-05-25 11:13:44 +120014887
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014888 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14889 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014890
14891 VkPipelineObj pipe(m_device);
14892 pipe.AddShader(&vs);
14893 pipe.AddShader(&fs);
14894
Chia-I Wu08accc62015-07-07 11:50:03 +080014895 /* set up CB 0; type is UNORM by default */
14896 pipe.AddColorAttachment();
14897 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014898
Chris Forbesa36d69e2015-05-25 11:13:44 +120014899 VkDescriptorSetObj descriptorSet(m_device);
14900 descriptorSet.AppendDummy();
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014901 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbesa36d69e2015-05-25 11:13:44 +120014902
Tony Barbour5781e8f2015-08-04 16:23:11 -060014903 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
Chris Forbesa36d69e2015-05-25 11:13:44 +120014904
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014905 m_errorMonitor->VerifyFound();
Chris Forbesa36d69e2015-05-25 11:13:44 +120014906}
Chris Forbes7b1b8932015-06-05 14:43:36 +120014907
Karl Schultz6addd812016-02-02 17:17:23 -070014908TEST_F(VkLayerTest, CreatePipelineUniformBlockNotProvided) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014909 TEST_DESCRIPTION(
14910 "Test that an error is produced for a shader consuming a uniform "
14911 "block which has no corresponding binding in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in pipeline layout");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060014913
Chris Forbes556c76c2015-08-14 12:04:59 +120014914 ASSERT_NO_FATAL_FAILURE(InitState());
Chris Forbes556c76c2015-08-14 12:04:59 +120014915
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014916 char const *vsSource =
14917 "#version 450\n"
14918 "\n"
14919 "out gl_PerVertex {\n"
14920 " vec4 gl_Position;\n"
14921 "};\n"
14922 "void main(){\n"
14923 " gl_Position = vec4(1);\n"
14924 "}\n";
14925 char const *fsSource =
14926 "#version 450\n"
14927 "\n"
14928 "layout(location=0) out vec4 x;\n"
14929 "layout(set=0) layout(binding=0) uniform foo { int x; int y; } bar;\n"
14930 "void main(){\n"
14931 " x = vec4(bar.y);\n"
14932 "}\n";
Chris Forbes556c76c2015-08-14 12:04:59 +120014933
Courtney Goeltzenleuchterd2635502015-10-21 17:08:06 -060014934 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14935 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
Chris Forbes556c76c2015-08-14 12:04:59 +120014936
Chris Forbes556c76c2015-08-14 12:04:59 +120014937 VkPipelineObj pipe(m_device);
14938 pipe.AddShader(&vs);
14939 pipe.AddShader(&fs);
14940
14941 /* set up CB 0; type is UNORM by default */
14942 pipe.AddColorAttachment();
14943 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14944
14945 VkDescriptorSetObj descriptorSet(m_device);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080014946 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
Chris Forbes556c76c2015-08-14 12:04:59 +120014947
14948 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14949
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014950 m_errorMonitor->VerifyFound();
Chris Forbes556c76c2015-08-14 12:04:59 +120014951}
14952
Chris Forbes5c59e902016-02-26 16:56:09 +130014953TEST_F(VkLayerTest, CreatePipelinePushConstantsNotInLayout) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014954 TEST_DESCRIPTION(
14955 "Test that an error is produced for a shader consuming push constants "
14956 "which are not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060014957 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "not declared in layout");
Chris Forbes5c59e902016-02-26 16:56:09 +130014958
14959 ASSERT_NO_FATAL_FAILURE(InitState());
14960
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070014961 char const *vsSource =
14962 "#version 450\n"
14963 "\n"
14964 "layout(push_constant, std430) uniform foo { float x; } consts;\n"
14965 "out gl_PerVertex {\n"
14966 " vec4 gl_Position;\n"
14967 "};\n"
14968 "void main(){\n"
14969 " gl_Position = vec4(consts.x);\n"
14970 "}\n";
14971 char const *fsSource =
14972 "#version 450\n"
14973 "\n"
14974 "layout(location=0) out vec4 x;\n"
14975 "void main(){\n"
14976 " x = vec4(1);\n"
14977 "}\n";
Chris Forbes5c59e902016-02-26 16:56:09 +130014978
14979 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
14980 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
14981
14982 VkPipelineObj pipe(m_device);
14983 pipe.AddShader(&vs);
14984 pipe.AddShader(&fs);
14985
14986 /* set up CB 0; type is UNORM by default */
14987 pipe.AddColorAttachment();
14988 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
14989
14990 VkDescriptorSetObj descriptorSet(m_device);
14991 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
14992
14993 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
14994
14995 /* should have generated an error -- no push constant ranges provided! */
Chris Forbes8f36a8a2016-04-07 13:21:07 +120014996 m_errorMonitor->VerifyFound();
Chris Forbes5c59e902016-02-26 16:56:09 +130014997}
14998
Chris Forbes3fb17902016-08-22 14:57:55 +120014999TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissing) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015000 TEST_DESCRIPTION(
15001 "Test that an error is produced for a shader consuming an input attachment "
15002 "which is not included in the subpass description");
Chris Forbes3fb17902016-08-22 14:57:55 +120015003 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15004 "consumes input attachment index 0 but not provided in subpass");
15005
15006 ASSERT_NO_FATAL_FAILURE(InitState());
15007
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015008 char const *vsSource =
15009 "#version 450\n"
15010 "\n"
15011 "out gl_PerVertex {\n"
15012 " vec4 gl_Position;\n"
15013 "};\n"
15014 "void main(){\n"
15015 " gl_Position = vec4(1);\n"
15016 "}\n";
15017 char const *fsSource =
15018 "#version 450\n"
15019 "\n"
15020 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15021 "layout(location=0) out vec4 color;\n"
15022 "void main() {\n"
15023 " color = subpassLoad(x);\n"
15024 "}\n";
Chris Forbes3fb17902016-08-22 14:57:55 +120015025
15026 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15027 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15028
15029 VkPipelineObj pipe(m_device);
15030 pipe.AddShader(&vs);
15031 pipe.AddShader(&fs);
15032 pipe.AddColorAttachment();
15033 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15034
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015035 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15036 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes3fb17902016-08-22 14:57:55 +120015037 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015038 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015039 ASSERT_VK_SUCCESS(err);
15040
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015041 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes3fb17902016-08-22 14:57:55 +120015042 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015043 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes3fb17902016-08-22 14:57:55 +120015044 ASSERT_VK_SUCCESS(err);
15045
15046 // error here.
15047 pipe.CreateVKPipeline(pl, renderPass());
15048
15049 m_errorMonitor->VerifyFound();
15050
15051 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15052 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15053}
15054
Chris Forbes5a9a0472016-08-22 16:02:09 +120015055TEST_F(VkLayerTest, CreatePipelineInputAttachmentTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015056 TEST_DESCRIPTION(
15057 "Test that an error is produced for a shader consuming an input attachment "
15058 "with a format having a different fundamental type");
Chris Forbes5a9a0472016-08-22 16:02:09 +120015059 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15060 "input attachment 0 format of VK_FORMAT_R8G8B8A8_UINT does not match");
15061
15062 ASSERT_NO_FATAL_FAILURE(InitState());
15063
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015064 char const *vsSource =
15065 "#version 450\n"
15066 "\n"
15067 "out gl_PerVertex {\n"
15068 " vec4 gl_Position;\n"
15069 "};\n"
15070 "void main(){\n"
15071 " gl_Position = vec4(1);\n"
15072 "}\n";
15073 char const *fsSource =
15074 "#version 450\n"
15075 "\n"
15076 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
15077 "layout(location=0) out vec4 color;\n"
15078 "void main() {\n"
15079 " color = subpassLoad(x);\n"
15080 "}\n";
Chris Forbes5a9a0472016-08-22 16:02:09 +120015081
15082 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15083 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15084
15085 VkPipelineObj pipe(m_device);
15086 pipe.AddShader(&vs);
15087 pipe.AddShader(&fs);
15088 pipe.AddColorAttachment();
15089 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15090
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015091 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15092 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015093 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015094 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015095 ASSERT_VK_SUCCESS(err);
15096
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015097 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015098 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015099 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes5a9a0472016-08-22 16:02:09 +120015100 ASSERT_VK_SUCCESS(err);
15101
15102 VkAttachmentDescription descs[2] = {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015103 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15104 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15105 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
15106 {0, VK_FORMAT_R8G8B8A8_UINT, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
15107 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 +120015108 };
15109 VkAttachmentReference color = {
15110 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
15111 };
15112 VkAttachmentReference input = {
15113 1, VK_IMAGE_LAYOUT_GENERAL,
15114 };
15115
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015116 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015117
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015118 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Chris Forbes5a9a0472016-08-22 16:02:09 +120015119 VkRenderPass rp;
15120 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
15121 ASSERT_VK_SUCCESS(err);
15122
15123 // error here.
15124 pipe.CreateVKPipeline(pl, rp);
15125
15126 m_errorMonitor->VerifyFound();
15127
15128 vkDestroyRenderPass(m_device->device(), rp, nullptr);
15129 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15130 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15131}
15132
Chris Forbes541f7b02016-08-22 15:30:27 +120015133TEST_F(VkLayerTest, CreatePipelineInputAttachmentMissingArray) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015134 TEST_DESCRIPTION(
15135 "Test that an error is produced for a shader consuming an input attachment "
15136 "which is not included in the subpass description -- array case");
Chris Forbes541f7b02016-08-22 15:30:27 +120015137 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Rene Lindsay07b60af2017-01-10 15:57:55 -070015138 "consumes input attachment index 0 but not provided in subpass");
Chris Forbes541f7b02016-08-22 15:30:27 +120015139
15140 ASSERT_NO_FATAL_FAILURE(InitState());
15141
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015142 char const *vsSource =
15143 "#version 450\n"
15144 "\n"
15145 "out gl_PerVertex {\n"
15146 " vec4 gl_Position;\n"
15147 "};\n"
15148 "void main(){\n"
15149 " gl_Position = vec4(1);\n"
15150 "}\n";
15151 char const *fsSource =
15152 "#version 450\n"
15153 "\n"
15154 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput xs[1];\n"
15155 "layout(location=0) out vec4 color;\n"
15156 "void main() {\n"
15157 " color = subpassLoad(xs[0]);\n"
15158 "}\n";
Chris Forbes541f7b02016-08-22 15:30:27 +120015159
15160 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15161 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15162
15163 VkPipelineObj pipe(m_device);
15164 pipe.AddShader(&vs);
15165 pipe.AddShader(&fs);
15166 pipe.AddColorAttachment();
15167 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15168
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015169 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 2, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
15170 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Chris Forbes541f7b02016-08-22 15:30:27 +120015171 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015172 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015173 ASSERT_VK_SUCCESS(err);
15174
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015175 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes541f7b02016-08-22 15:30:27 +120015176 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015177 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes541f7b02016-08-22 15:30:27 +120015178 ASSERT_VK_SUCCESS(err);
15179
15180 // error here.
15181 pipe.CreateVKPipeline(pl, renderPass());
15182
15183 m_errorMonitor->VerifyFound();
15184
15185 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15186 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15187}
15188
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015189TEST_F(VkLayerTest, CreateComputePipelineMissingDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015190 TEST_DESCRIPTION(
15191 "Test that an error is produced for a compute pipeline consuming a "
15192 "descriptor which is not provided in the pipeline layout");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015193 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "Shader uses descriptor slot 0.0");
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015194
15195 ASSERT_NO_FATAL_FAILURE(InitState());
15196
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015197 char const *csSource =
15198 "#version 450\n"
15199 "\n"
15200 "layout(local_size_x=1) in;\n"
15201 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15202 "void main(){\n"
15203 " x = vec4(1);\n"
15204 "}\n";
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015205
15206 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15207
15208 VkDescriptorSetObj descriptorSet(m_device);
15209 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15210
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015211 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15212 nullptr,
15213 0,
15214 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15215 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15216 descriptorSet.GetPipelineLayout(),
15217 VK_NULL_HANDLE,
15218 -1};
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015219
15220 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015221 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes10eb9ae2016-05-31 16:09:42 +120015222
15223 m_errorMonitor->VerifyFound();
15224
15225 if (err == VK_SUCCESS) {
15226 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15227 }
15228}
15229
Chris Forbes22a9b092016-07-19 14:34:05 +120015230TEST_F(VkLayerTest, CreateComputePipelineDescriptorTypeMismatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015231 TEST_DESCRIPTION(
15232 "Test that an error is produced for a pipeline consuming a "
15233 "descriptor-backed resource of a mismatched type");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015234 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15235 "but descriptor of type VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER");
Chris Forbes22a9b092016-07-19 14:34:05 +120015236
15237 ASSERT_NO_FATAL_FAILURE(InitState());
15238
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015239 VkDescriptorSetLayoutBinding binding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr};
15240 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &binding};
Chris Forbes22a9b092016-07-19 14:34:05 +120015241 VkDescriptorSetLayout dsl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015242 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015243 ASSERT_VK_SUCCESS(err);
15244
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015245 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Chris Forbes22a9b092016-07-19 14:34:05 +120015246 VkPipelineLayout pl;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015247 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
Chris Forbes22a9b092016-07-19 14:34:05 +120015248 ASSERT_VK_SUCCESS(err);
15249
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015250 char const *csSource =
15251 "#version 450\n"
15252 "\n"
15253 "layout(local_size_x=1) in;\n"
15254 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
15255 "void main() {\n"
15256 " x.x = 1.0f;\n"
15257 "}\n";
Chris Forbes22a9b092016-07-19 14:34:05 +120015258 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
15259
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015260 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
15261 nullptr,
15262 0,
15263 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
15264 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
15265 pl,
15266 VK_NULL_HANDLE,
15267 -1};
Chris Forbes22a9b092016-07-19 14:34:05 +120015268
15269 VkPipeline pipe;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015270 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
Chris Forbes22a9b092016-07-19 14:34:05 +120015271
15272 m_errorMonitor->VerifyFound();
15273
15274 if (err == VK_SUCCESS) {
15275 vkDestroyPipeline(m_device->device(), pipe, nullptr);
15276 }
15277
15278 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
15279 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
15280}
15281
Chris Forbes50020592016-07-27 13:52:41 +120015282TEST_F(VkLayerTest, DrawTimeImageViewTypeMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015283 TEST_DESCRIPTION(
15284 "Test that an error is produced when an image view type "
15285 "does not match the dimensionality declared in the shader");
Chris Forbes50020592016-07-27 13:52:41 +120015286
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015287 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 +120015288
15289 ASSERT_NO_FATAL_FAILURE(InitState());
15290 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15291
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015292 char const *vsSource =
15293 "#version 450\n"
15294 "\n"
15295 "out gl_PerVertex { vec4 gl_Position; };\n"
15296 "void main() { gl_Position = vec4(0); }\n";
15297 char const *fsSource =
15298 "#version 450\n"
15299 "\n"
15300 "layout(set=0, binding=0) uniform sampler3D s;\n"
15301 "layout(location=0) out vec4 color;\n"
15302 "void main() {\n"
15303 " color = texture(s, vec3(0));\n"
15304 "}\n";
Chris Forbes50020592016-07-27 13:52:41 +120015305 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15306 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15307
15308 VkPipelineObj pipe(m_device);
15309 pipe.AddShader(&vs);
15310 pipe.AddShader(&fs);
15311 pipe.AddColorAttachment();
15312
15313 VkTextureObj texture(m_device, nullptr);
15314 VkSamplerObj sampler(m_device);
15315
15316 VkDescriptorSetObj descriptorSet(m_device);
15317 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15318 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15319
15320 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15321 ASSERT_VK_SUCCESS(err);
15322
Tony Barbour552f6c02016-12-21 14:34:07 -070015323 m_commandBuffer->BeginCommandBuffer();
15324 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes50020592016-07-27 13:52:41 +120015325
15326 m_commandBuffer->BindPipeline(pipe);
15327 m_commandBuffer->BindDescriptorSet(descriptorSet);
15328
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015329 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes50020592016-07-27 13:52:41 +120015330 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015331 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes50020592016-07-27 13:52:41 +120015332 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15333
15334 // error produced here.
15335 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15336
15337 m_errorMonitor->VerifyFound();
15338
Tony Barbour552f6c02016-12-21 14:34:07 -070015339 m_commandBuffer->EndRenderPass();
15340 m_commandBuffer->EndCommandBuffer();
Chris Forbes50020592016-07-27 13:52:41 +120015341}
15342
Chris Forbes5533bfc2016-07-27 14:12:34 +120015343TEST_F(VkLayerTest, DrawTimeImageMultisampleMismatchWithPipeline) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015344 TEST_DESCRIPTION(
15345 "Test that an error is produced when a multisampled images "
15346 "are consumed via singlesample images types in the shader, or vice versa.");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015347
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015348 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "requires bound image to have multiple samples");
Chris Forbes5533bfc2016-07-27 14:12:34 +120015349
15350 ASSERT_NO_FATAL_FAILURE(InitState());
15351 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15352
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015353 char const *vsSource =
15354 "#version 450\n"
15355 "\n"
15356 "out gl_PerVertex { vec4 gl_Position; };\n"
15357 "void main() { gl_Position = vec4(0); }\n";
15358 char const *fsSource =
15359 "#version 450\n"
15360 "\n"
15361 "layout(set=0, binding=0) uniform sampler2DMS s;\n"
15362 "layout(location=0) out vec4 color;\n"
15363 "void main() {\n"
15364 " color = texelFetch(s, ivec2(0), 0);\n"
15365 "}\n";
Chris Forbes5533bfc2016-07-27 14:12:34 +120015366 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
15367 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
15368
15369 VkPipelineObj pipe(m_device);
15370 pipe.AddShader(&vs);
15371 pipe.AddShader(&fs);
15372 pipe.AddColorAttachment();
15373
15374 VkTextureObj texture(m_device, nullptr);
15375 VkSamplerObj sampler(m_device);
15376
15377 VkDescriptorSetObj descriptorSet(m_device);
15378 descriptorSet.AppendSamplerTexture(&sampler, &texture);
15379 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
15380
15381 VkResult err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
15382 ASSERT_VK_SUCCESS(err);
15383
Tony Barbour552f6c02016-12-21 14:34:07 -070015384 m_commandBuffer->BeginCommandBuffer();
15385 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Chris Forbes5533bfc2016-07-27 14:12:34 +120015386
15387 m_commandBuffer->BindPipeline(pipe);
15388 m_commandBuffer->BindDescriptorSet(descriptorSet);
15389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015390 VkViewport viewport = {0, 0, 16, 16, 0, 1};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015391 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015392 VkRect2D scissor = {{0, 0}, {16, 16}};
Chris Forbes5533bfc2016-07-27 14:12:34 +120015393 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
15394
15395 // error produced here.
15396 vkCmdDraw(m_commandBuffer->handle(), 3, 1, 0, 0);
15397
15398 m_errorMonitor->VerifyFound();
15399
Tony Barbour552f6c02016-12-21 14:34:07 -070015400 m_commandBuffer->EndRenderPass();
15401 m_commandBuffer->EndCommandBuffer();
Chris Forbes5533bfc2016-07-27 14:12:34 +120015402}
15403
Mark Youngc48c4c12016-04-11 14:26:49 -060015404TEST_F(VkLayerTest, CreateImageLimitsViolationMaxWidth) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015405 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015406
15407 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015408
15409 // Create an image
15410 VkImage image;
15411
Karl Schultz6addd812016-02-02 17:17:23 -070015412 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15413 const int32_t tex_width = 32;
15414 const int32_t tex_height = 32;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015415
15416 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015417 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15418 image_create_info.pNext = NULL;
15419 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15420 image_create_info.format = tex_format;
15421 image_create_info.extent.width = tex_width;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015422 image_create_info.extent.height = tex_height;
Karl Schultz6addd812016-02-02 17:17:23 -070015423 image_create_info.extent.depth = 1;
15424 image_create_info.mipLevels = 1;
15425 image_create_info.arrayLayers = 1;
15426 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15427 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15428 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15429 image_create_info.flags = 0;
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015430
15431 // Introduce error by sending down a bogus width extent
15432 image_create_info.extent.width = 65536;
Chia-I Wuf7458c52015-10-26 21:10:41 +080015433 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015434
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015435 m_errorMonitor->VerifyFound();
Mark Lobodzinski6f2274e2015-09-22 09:33:21 -060015436}
15437
Mark Youngc48c4c12016-04-11 14:26:49 -060015438TEST_F(VkLayerTest, CreateImageLimitsViolationMinWidth) {
Mark Lobodzinski688ed322017-01-27 11:13:21 -070015439 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00716);
Mark Youngc48c4c12016-04-11 14:26:49 -060015440
15441 ASSERT_NO_FATAL_FAILURE(InitState());
15442
15443 // Create an image
15444 VkImage image;
15445
15446 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15447 const int32_t tex_width = 32;
15448 const int32_t tex_height = 32;
15449
15450 VkImageCreateInfo image_create_info = {};
15451 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15452 image_create_info.pNext = NULL;
15453 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15454 image_create_info.format = tex_format;
15455 image_create_info.extent.width = tex_width;
15456 image_create_info.extent.height = tex_height;
15457 image_create_info.extent.depth = 1;
15458 image_create_info.mipLevels = 1;
15459 image_create_info.arrayLayers = 1;
15460 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15461 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15462 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15463 image_create_info.flags = 0;
15464
15465 // Introduce error by sending down a bogus width extent
15466 image_create_info.extent.width = 0;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015467 m_errorMonitor->SetUnexpectedError("parameter pCreateInfo->extent.width must be greater than 0");
Mark Youngc48c4c12016-04-11 14:26:49 -060015468 vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15469
15470 m_errorMonitor->VerifyFound();
15471}
Mark Lobodzinski66e5eab2016-11-15 13:30:38 -070015472
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015473TEST_F(VkLayerTest, AttachmentDescriptionUndefinedFormat) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015474 TEST_DESCRIPTION(
15475 "Create a render pass with an attachment description "
15476 "format set to VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015477
15478 ASSERT_NO_FATAL_FAILURE(InitState());
15479 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15480
Jeremy Hayes632e0ab2017-02-09 13:32:28 -070015481 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "format is VK_FORMAT_UNDEFINED");
Mark Lobodzinskidf4c57d2016-08-05 11:47:16 -060015482
15483 VkAttachmentReference color_attach = {};
15484 color_attach.layout = VK_IMAGE_LAYOUT_GENERAL;
15485 color_attach.attachment = 0;
15486 VkSubpassDescription subpass = {};
15487 subpass.colorAttachmentCount = 1;
15488 subpass.pColorAttachments = &color_attach;
15489
15490 VkRenderPassCreateInfo rpci = {};
15491 rpci.subpassCount = 1;
15492 rpci.pSubpasses = &subpass;
15493 rpci.attachmentCount = 1;
15494 VkAttachmentDescription attach_desc = {};
15495 attach_desc.format = VK_FORMAT_UNDEFINED;
15496 rpci.pAttachments = &attach_desc;
15497 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
15498 VkRenderPass rp;
15499 VkResult result = vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
15500
15501 m_errorMonitor->VerifyFound();
15502
15503 if (result == VK_SUCCESS) {
15504 vkDestroyRenderPass(m_device->device(), rp, NULL);
15505 }
15506}
15507
Karl Schultz6addd812016-02-02 17:17:23 -070015508TEST_F(VkLayerTest, InvalidImageView) {
15509 VkResult err;
Tobin Ehliscde08892015-09-22 10:11:37 -060015510
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015511 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015512
Tobin Ehliscde08892015-09-22 10:11:37 -060015513 ASSERT_NO_FATAL_FAILURE(InitState());
Tobin Ehliscde08892015-09-22 10:11:37 -060015514
Mike Stroyana3082432015-09-25 13:39:21 -060015515 // Create an image and try to create a view with bad baseMipLevel
Karl Schultz6addd812016-02-02 17:17:23 -070015516 VkImage image;
Tobin Ehliscde08892015-09-22 10:11:37 -060015517
Karl Schultz6addd812016-02-02 17:17:23 -070015518 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15519 const int32_t tex_width = 32;
15520 const int32_t tex_height = 32;
Tobin Ehliscde08892015-09-22 10:11:37 -060015521
15522 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015523 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15524 image_create_info.pNext = NULL;
15525 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15526 image_create_info.format = tex_format;
15527 image_create_info.extent.width = tex_width;
15528 image_create_info.extent.height = tex_height;
15529 image_create_info.extent.depth = 1;
15530 image_create_info.mipLevels = 1;
15531 image_create_info.arrayLayers = 1;
15532 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15533 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15534 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15535 image_create_info.flags = 0;
Tobin Ehliscde08892015-09-22 10:11:37 -060015536
Chia-I Wuf7458c52015-10-26 21:10:41 +080015537 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
Tobin Ehliscde08892015-09-22 10:11:37 -060015538 ASSERT_VK_SUCCESS(err);
15539
15540 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015541 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070015542 image_view_create_info.image = image;
15543 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15544 image_view_create_info.format = tex_format;
15545 image_view_create_info.subresourceRange.layerCount = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015546 image_view_create_info.subresourceRange.baseMipLevel = 10; // cause an error
Karl Schultz6addd812016-02-02 17:17:23 -070015547 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015548 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Tobin Ehliscde08892015-09-22 10:11:37 -060015549
15550 VkImageView view;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015551 m_errorMonitor->SetUnexpectedError(
15552 "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 -060015553 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Tobin Ehliscde08892015-09-22 10:11:37 -060015554
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015555 m_errorMonitor->VerifyFound();
Tony Barbourdf4c0042016-06-01 15:55:43 -060015556 vkDestroyImage(m_device->device(), image, NULL);
Tobin Ehliscde08892015-09-22 10:11:37 -060015557}
Mike Stroyana3082432015-09-25 13:39:21 -060015558
Mark Youngd339ba32016-05-30 13:28:35 -060015559TEST_F(VkLayerTest, CreateImageViewNoMemoryBoundToImage) {
15560 VkResult err;
Tobin Ehlisfed999f2016-09-21 15:09:45 -060015561 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
Tobin Ehlis4ff58172016-09-22 10:52:00 -060015562 " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Mark Youngd339ba32016-05-30 13:28:35 -060015563
15564 ASSERT_NO_FATAL_FAILURE(InitState());
15565
15566 // Create an image and try to create a view with no memory backing the image
15567 VkImage image;
15568
15569 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
15570 const int32_t tex_width = 32;
15571 const int32_t tex_height = 32;
15572
15573 VkImageCreateInfo image_create_info = {};
15574 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15575 image_create_info.pNext = NULL;
15576 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15577 image_create_info.format = tex_format;
15578 image_create_info.extent.width = tex_width;
15579 image_create_info.extent.height = tex_height;
15580 image_create_info.extent.depth = 1;
15581 image_create_info.mipLevels = 1;
15582 image_create_info.arrayLayers = 1;
15583 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15584 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
15585 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
15586 image_create_info.flags = 0;
15587
15588 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
15589 ASSERT_VK_SUCCESS(err);
15590
15591 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130015592 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Mark Youngd339ba32016-05-30 13:28:35 -060015593 image_view_create_info.image = image;
15594 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15595 image_view_create_info.format = tex_format;
15596 image_view_create_info.subresourceRange.layerCount = 1;
15597 image_view_create_info.subresourceRange.baseMipLevel = 0;
15598 image_view_create_info.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015599 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mark Youngd339ba32016-05-30 13:28:35 -060015600
15601 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015602 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Youngd339ba32016-05-30 13:28:35 -060015603
15604 m_errorMonitor->VerifyFound();
15605 vkDestroyImage(m_device->device(), image, NULL);
15606 // If last error is success, it still created the view, so delete it.
15607 if (err == VK_SUCCESS) {
15608 vkDestroyImageView(m_device->device(), view, NULL);
15609 }
Mark Youngd339ba32016-05-30 13:28:35 -060015610}
15611
Karl Schultz6addd812016-02-02 17:17:23 -070015612TEST_F(VkLayerTest, InvalidImageViewAspect) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015613 TEST_DESCRIPTION("Create an image and try to create a view with an invalid aspectMask");
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015614 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015615
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015616 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015617
Karl Schultz6addd812016-02-02 17:17:23 -070015618 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015619 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015620 image.init(32, 32, tex_format, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_TILING_LINEAR, 0);
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015621 ASSERT_TRUE(image.initialized());
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015622
15623 VkImageViewCreateInfo image_view_create_info = {};
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015624 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015625 image_view_create_info.image = image.handle();
Karl Schultz6addd812016-02-02 17:17:23 -070015626 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
15627 image_view_create_info.format = tex_format;
15628 image_view_create_info.subresourceRange.baseMipLevel = 0;
15629 image_view_create_info.subresourceRange.levelCount = 1;
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015630 image_view_create_info.subresourceRange.layerCount = 1;
Karl Schultz6addd812016-02-02 17:17:23 -070015631 // Cause an error by setting an invalid image aspect
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015632 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_METADATA_BIT;
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015633
15634 VkImageView view;
Tobin Ehlis1f567a22016-05-25 16:15:18 -060015635 vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015636
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015637 m_errorMonitor->VerifyFound();
Mark Lobodzinskidc86b852015-10-23 14:20:31 -060015638}
15639
Mike Weiblena1e13f42017-02-09 21:25:59 -070015640TEST_F(VkLayerTest, ExerciseGetImageSubresourceLayout) {
15641 TEST_DESCRIPTION("Test vkGetImageSubresourceLayout() valid usages");
15642
15643 ASSERT_NO_FATAL_FAILURE(InitState());
15644 VkSubresourceLayout subres_layout = {};
15645
15646 // VU 00732: image must have been created with tiling equal to VK_IMAGE_TILING_LINEAR
15647 {
15648 const VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; // ERROR: violates VU 00732
15649 VkImageObj img(m_device);
15650 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, tiling);
15651 ASSERT_TRUE(img.initialized());
15652
15653 VkImageSubresource subres = {};
15654 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15655 subres.mipLevel = 0;
15656 subres.arrayLayer = 0;
15657
15658 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00732);
15659 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15660 m_errorMonitor->VerifyFound();
15661 }
15662
15663 // VU 00733: The aspectMask member of pSubresource must only have a single bit set
15664 {
15665 VkImageObj img(m_device);
15666 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15667 ASSERT_TRUE(img.initialized());
15668
15669 VkImageSubresource subres = {};
15670 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_METADATA_BIT; // ERROR: triggers VU 00733
15671 subres.mipLevel = 0;
15672 subres.arrayLayer = 0;
15673
15674 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00733);
15675 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00741);
15676 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15677 m_errorMonitor->VerifyFound();
15678 }
15679
15680 // 00739 mipLevel must be less than the mipLevels specified in VkImageCreateInfo when the image was created
15681 {
15682 VkImageObj img(m_device);
15683 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15684 ASSERT_TRUE(img.initialized());
15685
15686 VkImageSubresource subres = {};
15687 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15688 subres.mipLevel = 1; // ERROR: triggers VU 00739
15689 subres.arrayLayer = 0;
15690
15691 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00739);
15692 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15693 m_errorMonitor->VerifyFound();
15694 }
15695
15696 // 00740 arrayLayer must be less than the arrayLayers specified in VkImageCreateInfo when the image was created
15697 {
15698 VkImageObj img(m_device);
15699 img.init_no_layout(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
15700 ASSERT_TRUE(img.initialized());
15701
15702 VkImageSubresource subres = {};
15703 subres.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15704 subres.mipLevel = 0;
15705 subres.arrayLayer = 1; // ERROR: triggers VU 00740
15706
15707 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00740);
15708 vkGetImageSubresourceLayout(m_device->device(), img.image(), &subres, &subres_layout);
15709 m_errorMonitor->VerifyFound();
15710 }
15711}
15712
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015713TEST_F(VkLayerTest, CopyImageLayerCountMismatch) {
Karl Schultz6addd812016-02-02 17:17:23 -070015714 VkResult err;
15715 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060015716
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015717 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01198);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060015718
Mike Stroyana3082432015-09-25 13:39:21 -060015719 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060015720
15721 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070015722 VkImage srcImage;
15723 VkImage dstImage;
15724 VkDeviceMemory srcMem;
15725 VkDeviceMemory destMem;
15726 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060015727
15728 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015729 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15730 image_create_info.pNext = NULL;
15731 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15732 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
15733 image_create_info.extent.width = 32;
15734 image_create_info.extent.height = 32;
15735 image_create_info.extent.depth = 1;
15736 image_create_info.mipLevels = 1;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015737 image_create_info.arrayLayers = 4;
Karl Schultz6addd812016-02-02 17:17:23 -070015738 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15739 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15740 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
15741 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015742
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015743 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015744 ASSERT_VK_SUCCESS(err);
15745
Mark Lobodzinski867787a2016-10-14 11:49:55 -060015746 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015747 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060015748 ASSERT_VK_SUCCESS(err);
15749
15750 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015751 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070015752 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
15753 memAlloc.pNext = NULL;
15754 memAlloc.allocationSize = 0;
15755 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015756
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060015757 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015758 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015759 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060015760 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015761 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015762 ASSERT_VK_SUCCESS(err);
15763
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015764 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060015765 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015766 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015767 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015768 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060015769 ASSERT_VK_SUCCESS(err);
15770
15771 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
15772 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015773 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060015774 ASSERT_VK_SUCCESS(err);
15775
Tony Barbour552f6c02016-12-21 14:34:07 -070015776 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015777 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015778 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060015779 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060015780 copyRegion.srcSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015781 copyRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060015782 copyRegion.srcOffset.x = 0;
15783 copyRegion.srcOffset.y = 0;
15784 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080015785 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015786 copyRegion.dstSubresource.mipLevel = 0;
15787 copyRegion.dstSubresource.baseArrayLayer = 0;
Mark Lobodzinskidb117632016-03-31 10:45:56 -060015788 // Introduce failure by forcing the dst layerCount to differ from src
15789 copyRegion.dstSubresource.layerCount = 3;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015790 copyRegion.dstOffset.x = 0;
15791 copyRegion.dstOffset.y = 0;
15792 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060015793 copyRegion.extent.width = 1;
15794 copyRegion.extent.height = 1;
15795 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015796 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070015797 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060015798
Chris Forbes8f36a8a2016-04-07 13:21:07 +120015799 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060015800
Chia-I Wuf7458c52015-10-26 21:10:41 +080015801 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080015802 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080015803 vkFreeMemory(m_device->device(), srcMem, NULL);
15804 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060015805}
15806
Tony Barbourd6673642016-05-05 14:46:39 -060015807TEST_F(VkLayerTest, ImageLayerUnsupportedFormat) {
Tony Barbourd6673642016-05-05 14:46:39 -060015808 TEST_DESCRIPTION("Creating images with unsuported formats ");
15809
15810 ASSERT_NO_FATAL_FAILURE(InitState());
15811 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
15812 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015813 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 -060015814 VK_IMAGE_TILING_OPTIMAL, 0);
15815 ASSERT_TRUE(image.initialized());
15816
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015817 // Create image with unsupported format - Expect FORMAT_UNSUPPORTED
Chris Forbesf4d8e332016-11-28 17:51:10 +130015818 VkImageCreateInfo image_create_info = {};
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015819 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015820 image_create_info.imageType = VK_IMAGE_TYPE_2D;
15821 image_create_info.format = VK_FORMAT_UNDEFINED;
15822 image_create_info.extent.width = 32;
15823 image_create_info.extent.height = 32;
15824 image_create_info.extent.depth = 1;
15825 image_create_info.mipLevels = 1;
15826 image_create_info.arrayLayers = 1;
15827 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
15828 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
15829 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015830
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015831 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15832 "vkCreateImage: VkFormat for image must not be VK_FORMAT_UNDEFINED");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015833
15834 VkImage localImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015835 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15836 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15837 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15838 m_errorMonitor->SetUnexpectedError("samples must be a bit value that is set in VkImageFormatProperties::sampleCounts");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015839 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
15840 m_errorMonitor->VerifyFound();
15841
Tony Barbourd6673642016-05-05 14:46:39 -060015842 VkFormat unsupported = VK_FORMAT_UNDEFINED;
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015843 // Look for a format that is COMPLETELY unsupported with this hardware
Tony Barbourd6673642016-05-05 14:46:39 -060015844 for (int f = VK_FORMAT_BEGIN_RANGE; f <= VK_FORMAT_END_RANGE; f++) {
15845 VkFormat format = static_cast<VkFormat>(f);
15846 VkFormatProperties fProps = m_device->format_properties(format);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015847 if (format != VK_FORMAT_UNDEFINED && fProps.linearTilingFeatures == 0 && fProps.optimalTilingFeatures == 0) {
Tony Barbourd6673642016-05-05 14:46:39 -060015848 unsupported = format;
15849 break;
15850 }
15851 }
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015852
Tony Barbourd6673642016-05-05 14:46:39 -060015853 if (unsupported != VK_FORMAT_UNDEFINED) {
Tony Barbourd6673642016-05-05 14:46:39 -060015854 image_create_info.format = unsupported;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015855 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is an unsupported format");
Tony Barbourd6673642016-05-05 14:46:39 -060015856
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015857 m_errorMonitor->SetUnexpectedError("CreateImage extents exceed allowable limits for format");
15858 m_errorMonitor->SetUnexpectedError("CreateImage resource size exceeds allowable maximum Image resource size");
15859 m_errorMonitor->SetUnexpectedError("CreateImage mipLevels=1 exceeds allowable maximum supported by format of 0");
15860 m_errorMonitor->SetUnexpectedError("arrayLayers must be less than or equal to VkImageFormatProperties::maxArrayLayers");
15861 m_errorMonitor->SetUnexpectedError(
15862 "samples must be a bit value that is set in VkImageFormatProperties::sampleCounts returned by "
15863 "vkGetPhysicalDeviceImageFormatProperties with format, type, tiling, usage, and flags equal to those in this "
15864 "structure");
Mark Lobodzinskiba5c6862016-05-17 08:14:00 -060015865 vkCreateImage(m_device->handle(), &image_create_info, NULL, &localImage);
Tony Barbourd6673642016-05-05 14:46:39 -060015866 m_errorMonitor->VerifyFound();
15867 }
15868}
15869
15870TEST_F(VkLayerTest, ImageLayerViewTests) {
15871 VkResult ret;
15872 TEST_DESCRIPTION("Passing bad parameters to CreateImageView");
15873
15874 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070015875 auto depth_format = find_depth_stencil_format(m_device);
15876 if (!depth_format) {
15877 return;
15878 }
Tony Barbourd6673642016-05-05 14:46:39 -060015879
15880 VkImageObj image(m_device);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015881 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 -060015882 VK_IMAGE_TILING_OPTIMAL, 0);
15883 ASSERT_TRUE(image.initialized());
15884
15885 VkImageView imgView;
15886 VkImageViewCreateInfo imgViewInfo = {};
15887 imgViewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
15888 imgViewInfo.image = image.handle();
15889 imgViewInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
15890 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15891 imgViewInfo.subresourceRange.layerCount = 1;
15892 imgViewInfo.subresourceRange.baseMipLevel = 0;
15893 imgViewInfo.subresourceRange.levelCount = 1;
15894 imgViewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
15895
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015896 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015897 // View can't have baseMipLevel >= image's mipLevels - Expect
15898 // VIEW_CREATE_ERROR
15899 imgViewInfo.subresourceRange.baseMipLevel = 1;
15900 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15901 m_errorMonitor->VerifyFound();
15902 imgViewInfo.subresourceRange.baseMipLevel = 0;
15903
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015904 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060015905 // View can't have baseArrayLayer >= image's arraySize - Expect
15906 // VIEW_CREATE_ERROR
15907 imgViewInfo.subresourceRange.baseArrayLayer = 1;
15908 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15909 m_errorMonitor->VerifyFound();
15910 imgViewInfo.subresourceRange.baseArrayLayer = 0;
15911
Mike Weiblenc16b2aa2017-01-25 13:02:44 -070015912 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00768);
Tony Barbourd6673642016-05-05 14:46:39 -060015913 // View's levelCount can't be 0 - Expect VIEW_CREATE_ERROR
15914 imgViewInfo.subresourceRange.levelCount = 0;
15915 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15916 m_errorMonitor->VerifyFound();
15917 imgViewInfo.subresourceRange.levelCount = 1;
15918
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015919 m_errorMonitor->SetDesiredFailureMsg(
15920 VK_DEBUG_REPORT_ERROR_BIT_EXT,
15921 "if pCreateInfo->viewType is VK_IMAGE_TYPE_2D, pCreateInfo->subresourceRange.layerCount must be 1");
Tony Barbourd6673642016-05-05 14:46:39 -060015922 // View's layerCount can't be 0 - Expect VIEW_CREATE_ERROR
15923 imgViewInfo.subresourceRange.layerCount = 0;
15924 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15925 m_errorMonitor->VerifyFound();
15926 imgViewInfo.subresourceRange.layerCount = 1;
15927
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070015928 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15929 "Formats MUST be IDENTICAL unless "
15930 "VK_IMAGE_CREATE_MUTABLE_FORMAT BIT "
15931 "was set on image creation.");
Tony Barbourd6673642016-05-05 14:46:39 -060015932 // Can't use depth format for view into color image - Expect INVALID_FORMAT
Tony Barbourf887b162017-03-09 10:06:46 -070015933 imgViewInfo.format = depth_format;
Tony Barbourd6673642016-05-05 14:46:39 -060015934 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15935 m_errorMonitor->VerifyFound();
15936 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15937
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015938 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02172);
Tony Barbourd6673642016-05-05 14:46:39 -060015939 // Same compatibility class but no MUTABLE_FORMAT bit - Expect
15940 // VIEW_CREATE_ERROR
15941 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UINT;
15942 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15943 m_errorMonitor->VerifyFound();
15944 imgViewInfo.format = VK_FORMAT_B8G8R8A8_UNORM;
15945
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070015946 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02171);
Tobin Ehlis8d79b2e2016-10-26 14:13:46 -060015947 // TODO: Update framework to easily passing mutable flag into ImageObj init
15948 // For now just allowing image for this one test to not have memory bound
Jeremy Hayes5a7cf2e2017-01-06 15:23:27 -070015949 // TODO: The following line is preventing the intended validation from occurring because of the way the error monitor works.
15950 // m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
15951 // " used with no memory bound. Memory should be bound by calling vkBindImageMemory().");
Tony Barbourd6673642016-05-05 14:46:39 -060015952 // Have MUTABLE_FORMAT bit but not in same compatibility class - Expect
15953 // VIEW_CREATE_ERROR
15954 VkImageCreateInfo mutImgInfo = image.create_info();
15955 VkImage mutImage;
15956 mutImgInfo.format = VK_FORMAT_R8_UINT;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060015957 assert(m_device->format_properties(VK_FORMAT_R8_UINT).optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT);
Tony Barbourd6673642016-05-05 14:46:39 -060015958 mutImgInfo.flags = VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
15959 mutImgInfo.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
15960 ret = vkCreateImage(m_device->handle(), &mutImgInfo, NULL, &mutImage);
15961 ASSERT_VK_SUCCESS(ret);
15962 imgViewInfo.image = mutImage;
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070015963 m_errorMonitor->SetUnexpectedError(
15964 "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 -060015965 vkCreateImageView(m_device->handle(), &imgViewInfo, NULL, &imgView);
15966 m_errorMonitor->VerifyFound();
15967 imgViewInfo.image = image.handle();
15968 vkDestroyImage(m_device->handle(), mutImage, NULL);
15969}
15970
Dave Houlton75967fc2017-03-06 17:21:16 -070015971TEST_F(VkLayerTest, CompressedImageMipCopyTests) {
15972 TEST_DESCRIPTION("Image/Buffer copies for higher mip levels");
15973
15974 ASSERT_NO_FATAL_FAILURE(InitState());
15975
15976 VkPhysicalDeviceFeatures device_features;
15977 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
15978 VkFormat compressed_format = VK_FORMAT_UNDEFINED;
15979 if (device_features.textureCompressionBC) {
15980 compressed_format = VK_FORMAT_BC3_SRGB_BLOCK;
15981 } else if (device_features.textureCompressionETC2) {
15982 compressed_format = VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
15983 } else if (device_features.textureCompressionASTC_LDR) {
15984 compressed_format = VK_FORMAT_ASTC_4x4_UNORM_BLOCK;
15985 } else {
15986 printf(" No compressed formats supported - CompressedImageMipCopyTests skipped.\n");
15987 return;
15988 }
15989
15990 VkImageCreateInfo ci;
15991 ci.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
15992 ci.pNext = NULL;
15993 ci.flags = 0;
15994 ci.imageType = VK_IMAGE_TYPE_2D;
15995 ci.format = compressed_format;
15996 ci.extent = {32, 32, 1};
15997 ci.mipLevels = 6;
15998 ci.arrayLayers = 1;
15999 ci.samples = VK_SAMPLE_COUNT_1_BIT;
16000 ci.tiling = VK_IMAGE_TILING_OPTIMAL;
16001 ci.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16002 ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
16003 ci.queueFamilyIndexCount = 0;
16004 ci.pQueueFamilyIndices = NULL;
16005 ci.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16006
16007 VkImageObj image(m_device);
16008 image.init(&ci);
16009 ASSERT_TRUE(image.initialized());
16010
16011 VkImageObj odd_image(m_device);
16012 ci.extent = {31, 32, 1}; // Mips are [31,32] [15,16] [7,8] [3,4], [1,2] [1,1]
16013 odd_image.init(&ci);
16014 ASSERT_TRUE(odd_image.initialized());
16015
16016 // Allocate buffers
16017 VkMemoryPropertyFlags reqs = 0;
16018 vk_testing::Buffer buffer_1024, buffer_64, buffer_16, buffer_8;
16019 buffer_1024.init_as_src_and_dst(*m_device, 1024, reqs);
16020 buffer_64.init_as_src_and_dst(*m_device, 64, reqs);
16021 buffer_16.init_as_src_and_dst(*m_device, 16, reqs);
16022 buffer_8.init_as_src_and_dst(*m_device, 8, reqs);
16023
16024 VkBufferImageCopy region = {};
16025 region.bufferRowLength = 0;
16026 region.bufferImageHeight = 0;
16027 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16028 region.imageSubresource.layerCount = 1;
16029 region.imageOffset = {0, 0, 0};
16030 region.bufferOffset = 0;
16031
16032 // start recording
16033 m_commandBuffer->BeginCommandBuffer();
16034
16035 // Mip level copies that work - 5 levels
16036 m_errorMonitor->ExpectSuccess();
16037
16038 // Mip 0 should fit in 1k buffer - 1k texels @ 1b each
16039 region.imageExtent = {32, 32, 1};
16040 region.imageSubresource.mipLevel = 0;
16041 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_1024.handle(), 1,
16042 &region);
16043 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_1024.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16044 &region);
16045
16046 // Mip 2 should fit in 64b buffer - 64 texels @ 1b each
16047 region.imageExtent = {8, 8, 1};
16048 region.imageSubresource.mipLevel = 2;
16049 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64.handle(), 1,
16050 &region);
16051 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16052 &region);
16053
16054 // Mip 3 should fit in 16b buffer - 16 texels @ 1b each
16055 region.imageExtent = {4, 4, 1};
16056 region.imageSubresource.mipLevel = 3;
16057 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16058 &region);
16059 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16060 &region);
16061
16062 // Mip 4&5 should fit in 16b buffer with no complaint - 4 & 1 texels @ 1b each
16063 region.imageExtent = {2, 2, 1};
16064 region.imageSubresource.mipLevel = 4;
16065 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16066 &region);
16067 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16068 &region);
16069
16070 region.imageExtent = {1, 1, 1};
16071 region.imageSubresource.mipLevel = 5;
16072 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16073 &region);
16074 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16075 &region);
16076 m_errorMonitor->VerifyNotFound();
16077
16078 // Buffer must accomodate a full compressed block, regardless of texel count
16079 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16080 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_8.handle(), 1,
16081 &region);
16082 m_errorMonitor->VerifyFound();
16083 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227);
16084 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_8.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16085 &region);
16086 m_errorMonitor->VerifyFound();
16087
16088 // Copy width < compressed block size, but not the full mip width
16089 region.imageExtent = {1, 2, 1};
16090 region.imageSubresource.mipLevel = 4;
16091 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16092 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16093 &region);
16094 m_errorMonitor->VerifyFound();
16095 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16096 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16097 &region);
16098 m_errorMonitor->VerifyFound();
16099
16100 // Copy height < compressed block size but not the full mip height
16101 region.imageExtent = {2, 1, 1};
16102 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16103 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16104 &region);
16105 m_errorMonitor->VerifyFound();
16106 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16107 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16108 &region);
16109 m_errorMonitor->VerifyFound();
16110
16111 // Offsets must be multiple of compressed block size
16112 region.imageOffset = {1, 1, 0};
16113 region.imageExtent = {1, 1, 1};
16114 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16115 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16116 &region);
16117 m_errorMonitor->VerifyFound();
16118 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01273);
16119 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16120 &region);
16121 m_errorMonitor->VerifyFound();
16122
16123 // Offset + extent width = mip width - should succeed
16124 region.imageOffset = {4, 4, 0};
16125 region.imageExtent = {3, 4, 1};
16126 region.imageSubresource.mipLevel = 2;
16127 m_errorMonitor->ExpectSuccess();
16128 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16129 &region);
16130 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16131 &region);
16132 m_errorMonitor->VerifyNotFound();
16133
16134 // Offset + extent width > mip width, but still within the final compressed block - should succeed
16135 region.imageExtent = {4, 4, 1};
16136 m_errorMonitor->ExpectSuccess();
16137 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16138 &region);
16139 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16140 &region);
16141 m_errorMonitor->VerifyNotFound();
16142
16143 // Offset + extent width < mip width and not a multiple of block width - should fail
16144 region.imageExtent = {3, 3, 1};
16145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16146 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16.handle(), 1,
16147 &region);
16148 m_errorMonitor->VerifyFound();
16149 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
16150 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16.handle(), odd_image.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16151 &region);
16152 m_errorMonitor->VerifyFound();
16153}
16154
Dave Houlton59a20702017-02-02 17:26:23 -070016155TEST_F(VkLayerTest, ImageBufferCopyTests) {
16156 TEST_DESCRIPTION("Image to buffer and buffer to image tests");
16157
16158 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016159 VkFormatProperties format_props = m_device->format_properties(VK_FORMAT_D24_UNORM_S8_UINT);
16160 if (!(format_props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) {
16161 printf(" VK_FORMAT_D24_UNORM_S8_UINT not supported. Skipped.\n");
16162 return;
16163 }
Dave Houlton584d51e2017-02-16 12:52:54 -070016164
16165 // Bail if any dimension of transfer granularity is 0.
16166 auto index = m_device->graphics_queue_node_index_;
16167 auto queue_family_properties = m_device->phy().queue_properties();
16168 if ((queue_family_properties[index].minImageTransferGranularity.depth == 0) ||
16169 (queue_family_properties[index].minImageTransferGranularity.width == 0) ||
16170 (queue_family_properties[index].minImageTransferGranularity.height == 0)) {
16171 printf(" Subresource copies are disallowed when xfer granularity (x|y|z) is 0. Skipped.\n");
16172 return;
16173 }
16174
Dave Houlton59a20702017-02-02 17:26:23 -070016175 VkImageObj image_64k(m_device); // 128^2 texels, 64k
16176 VkImageObj image_16k(m_device); // 64^2 texels, 16k
16177 VkImageObj image_16k_depth(m_device); // 64^2 texels, depth, 16k
Dave Houltonf3229d52017-02-21 15:59:08 -070016178 VkImageObj ds_image_4D_1S(m_device); // 256^2 texels, 512kb (256k depth, 64k stencil, 192k pack)
16179 VkImageObj ds_image_3D_1S(m_device); // 256^2 texels, 256kb (192k depth, 64k stencil)
16180 VkImageObj ds_image_2D(m_device); // 256^2 texels, 128k (128k depth)
16181 VkImageObj ds_image_1S(m_device); // 256^2 texels, 64k (64k stencil)
16182
Dave Houlton59a20702017-02-02 17:26:23 -070016183 image_64k.init(128, 128, VK_FORMAT_R8G8B8A8_UINT,
16184 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16185 VK_IMAGE_TILING_OPTIMAL, 0);
16186 image_16k.init(64, 64, VK_FORMAT_R8G8B8A8_UINT,
16187 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16188 VK_IMAGE_TILING_OPTIMAL, 0);
16189 image_16k_depth.init(64, 64, VK_FORMAT_D24_UNORM_S8_UINT, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16190 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton59a20702017-02-02 17:26:23 -070016191 ASSERT_TRUE(image_64k.initialized());
16192 ASSERT_TRUE(image_16k.initialized());
16193 ASSERT_TRUE(image_16k_depth.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016194
Dave Houltonf3229d52017-02-21 15:59:08 -070016195 // Verify all needed Depth/Stencil formats are supported
16196 bool missing_ds_support = false;
16197 VkFormatProperties props = {0, 0, 0};
16198 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D32_SFLOAT_S8_UINT, &props);
16199 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16200 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D24_UNORM_S8_UINT, &props);
16201 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16202 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_D16_UNORM, &props);
16203 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16204 vkGetPhysicalDeviceFormatProperties(m_device->phy().handle(), VK_FORMAT_S8_UINT, &props);
16205 missing_ds_support |= (props.bufferFeatures == 0 && props.linearTilingFeatures == 0 && props.optimalTilingFeatures == 0);
16206
16207 if (!missing_ds_support) {
16208 ds_image_4D_1S.init(
16209 256, 256, VK_FORMAT_D32_SFLOAT_S8_UINT,
16210 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16211 VK_IMAGE_TILING_OPTIMAL, 0);
16212 ASSERT_TRUE(ds_image_4D_1S.initialized());
16213
16214 ds_image_3D_1S.init(
16215 256, 256, VK_FORMAT_D24_UNORM_S8_UINT,
16216 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16217 VK_IMAGE_TILING_OPTIMAL, 0);
16218 ASSERT_TRUE(ds_image_3D_1S.initialized());
16219
16220 ds_image_2D.init(
16221 256, 256, VK_FORMAT_D16_UNORM,
16222 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16223 VK_IMAGE_TILING_OPTIMAL, 0);
16224 ASSERT_TRUE(ds_image_2D.initialized());
16225
16226 ds_image_1S.init(
16227 256, 256, VK_FORMAT_S8_UINT,
16228 VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
16229 VK_IMAGE_TILING_OPTIMAL, 0);
16230 ASSERT_TRUE(ds_image_1S.initialized());
16231 }
16232
16233 // Allocate buffers
16234 vk_testing::Buffer buffer_256k, buffer_128k, buffer_64k, buffer_16k;
Dave Houlton59a20702017-02-02 17:26:23 -070016235 VkMemoryPropertyFlags reqs = 0;
Dave Houltonf3229d52017-02-21 15:59:08 -070016236 buffer_256k.init_as_src_and_dst(*m_device, 262144, reqs); // 256k
16237 buffer_128k.init_as_src_and_dst(*m_device, 131072, reqs); // 128k
16238 buffer_64k.init_as_src_and_dst(*m_device, 65536, reqs); // 64k
16239 buffer_16k.init_as_src_and_dst(*m_device, 16384, reqs); // 16k
Dave Houlton59a20702017-02-02 17:26:23 -070016240
16241 VkBufferImageCopy region = {};
16242 region.bufferRowLength = 0;
16243 region.bufferImageHeight = 0;
16244 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16245 region.imageSubresource.layerCount = 1;
16246 region.imageOffset = {0, 0, 0};
16247 region.imageExtent = {64, 64, 1};
16248 region.bufferOffset = 0;
16249
16250 // attempt copies before putting command buffer in recording state
16251 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01240);
16252 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16253 &region);
16254 m_errorMonitor->VerifyFound();
16255
16256 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01258);
16257 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16258 &region);
16259 m_errorMonitor->VerifyFound();
16260
16261 // start recording
16262 m_commandBuffer->BeginCommandBuffer();
16263
16264 // successful copies
16265 m_errorMonitor->ExpectSuccess();
16266 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16267 &region);
16268 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16269 &region);
16270 region.imageOffset.x = 16; // 16k copy, offset requires larger image
16271 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16272 &region);
16273 region.imageExtent.height = 78; // > 16k copy requires larger buffer & image
16274 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16275 &region);
16276 region.imageOffset.x = 0;
16277 region.imageExtent.height = 64;
16278 region.bufferOffset = 256; // 16k copy with buffer offset, requires larger buffer
16279 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16280 &region);
16281 m_errorMonitor->VerifyNotFound();
16282
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016283 // image/buffer too small (extent too large) on copy to image
Dave Houlton59a20702017-02-02 17:26:23 -070016284 region.imageExtent = {65, 64, 1};
16285 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16286 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16287 &region);
16288 m_errorMonitor->VerifyFound();
16289
16290 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16291 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16292 &region);
16293 m_errorMonitor->VerifyFound();
16294
16295 // image/buffer too small (offset) on copy to image
16296 region.imageExtent = {64, 64, 1};
16297 region.imageOffset = {0, 4, 0};
16298 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01227); // buffer too small
16299 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_16k.handle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16300 &region);
16301 m_errorMonitor->VerifyFound();
16302
16303 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228); // image too small
16304 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer_64k.handle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, 1,
16305 &region);
16306 m_errorMonitor->VerifyFound();
16307
16308 // image/buffer too small on copy to buffer
16309 region.imageExtent = {64, 64, 1};
16310 region.imageOffset = {0, 0, 0};
Mark Lobodzinski80871462017-02-16 10:37:27 -070016311 region.bufferOffset = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016312 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246); // buffer too small
16313 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_64k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16314 &region);
16315 m_errorMonitor->VerifyFound();
16316
16317 region.imageExtent = {64, 65, 1};
16318 region.bufferOffset = 0;
16319 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01245); // image too small
16320 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_64k.handle(), 1,
16321 &region);
16322 m_errorMonitor->VerifyFound();
16323
16324 // buffer size ok but rowlength causes loose packing
16325 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16326 region.imageExtent = {64, 64, 1};
16327 region.bufferRowLength = 68;
16328 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16329 &region);
16330 m_errorMonitor->VerifyFound();
16331
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016332 // An extent with zero area should produce a warning, but no error
16333 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_ERROR_BIT_EXT, "} has zero area");
16334 region.imageExtent.width = 0;
16335 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16336 &region);
16337 m_errorMonitor->VerifyFound();
16338
Dave Houlton59a20702017-02-02 17:26:23 -070016339 // aspect bits
16340 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01280); // more than 1 aspect bit set
16341 region.imageExtent = {64, 64, 1};
16342 region.bufferRowLength = 0;
16343 region.bufferImageHeight = 0;
16344 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
16345 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16346 buffer_16k.handle(), 1, &region);
16347 m_errorMonitor->VerifyFound();
16348
16349 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // mis-matched aspect
16350 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16351 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k.handle(), VK_IMAGE_LAYOUT_GENERAL, buffer_16k.handle(), 1,
16352 &region);
16353 m_errorMonitor->VerifyFound();
16354
16355 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01279); // different mis-matched aspect
16356 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16357 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_depth.handle(), VK_IMAGE_LAYOUT_GENERAL,
16358 buffer_16k.handle(), 1, &region);
16359 m_errorMonitor->VerifyFound();
16360
Dave Houltonf3229d52017-02-21 15:59:08 -070016361 // Test Depth/Stencil copies
16362 if (missing_ds_support) {
16363 printf(" Depth / Stencil formats unsupported - skipping D/S tests.\n");
16364 } else {
16365 VkBufferImageCopy ds_region = {};
16366 ds_region.bufferOffset = 0;
16367 ds_region.bufferRowLength = 0;
16368 ds_region.bufferImageHeight = 0;
16369 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
16370 ds_region.imageSubresource.mipLevel = 0;
16371 ds_region.imageSubresource.baseArrayLayer = 0;
16372 ds_region.imageSubresource.layerCount = 1;
16373 ds_region.imageOffset = {0, 0, 0};
16374 ds_region.imageExtent = {256, 256, 1};
16375
16376 // Depth copies that should succeed
16377 m_errorMonitor->ExpectSuccess(); // Extract 4b depth per texel, pack into 256k buffer
16378 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16379 buffer_256k.handle(), 1, &ds_region);
16380 m_errorMonitor->VerifyNotFound();
16381
16382 m_errorMonitor->ExpectSuccess(); // Extract 3b depth per texel, pack (loose) into 256k buffer
16383 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16384 buffer_256k.handle(), 1, &ds_region);
16385 m_errorMonitor->VerifyNotFound();
16386
16387 m_errorMonitor->ExpectSuccess(); // Copy 2b depth per texel, into 128k buffer
16388 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16389 buffer_128k.handle(), 1, &ds_region);
16390 m_errorMonitor->VerifyNotFound();
16391
16392 // Depth copies that should fail
16393 ds_region.bufferOffset = 4;
16394 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16395 VALIDATION_ERROR_01246); // Extract 4b depth per texel, pack into 256k buffer
16396 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16397 buffer_256k.handle(), 1, &ds_region);
16398 m_errorMonitor->VerifyFound();
16399
16400 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16401 VALIDATION_ERROR_01246); // Extract 3b depth per texel, pack (loose) into 256k buffer
16402 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16403 buffer_256k.handle(), 1, &ds_region);
16404 m_errorMonitor->VerifyFound();
16405
16406 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16407 VALIDATION_ERROR_01246); // Copy 2b depth per texel, into 128k buffer
16408 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_2D.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16409 buffer_128k.handle(), 1, &ds_region);
16410 m_errorMonitor->VerifyFound();
16411
16412 // Stencil copies that should succeed
16413 ds_region.bufferOffset = 0;
16414 ds_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
16415 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16416 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16417 buffer_64k.handle(), 1, &ds_region);
16418 m_errorMonitor->VerifyNotFound();
16419
16420 m_errorMonitor->ExpectSuccess(); // Extract 1b stencil per texel, pack into 64k buffer
16421 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16422 buffer_64k.handle(), 1, &ds_region);
16423 m_errorMonitor->VerifyNotFound();
16424
16425 m_errorMonitor->ExpectSuccess(); // Copy 1b depth per texel, into 64k buffer
16426 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16427 buffer_64k.handle(), 1, &ds_region);
16428 m_errorMonitor->VerifyNotFound();
16429
16430 // Stencil copies that should fail
16431 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16432 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16433 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_4D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16434 buffer_16k.handle(), 1, &ds_region);
16435 m_errorMonitor->VerifyFound();
16436
16437 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16438 VALIDATION_ERROR_01246); // Extract 1b stencil per texel, pack into 64k buffer
16439 ds_region.bufferRowLength = 260;
16440 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_3D_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16441 buffer_64k.handle(), 1, &ds_region);
16442 m_errorMonitor->VerifyFound();
16443
16444 ds_region.bufferRowLength = 0;
16445 ds_region.bufferOffset = 4;
16446 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16447 VALIDATION_ERROR_01246); // Copy 1b depth per texel, into 64k buffer
16448 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), ds_image_1S.handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
16449 buffer_64k.handle(), 1, &ds_region);
16450 m_errorMonitor->VerifyFound();
16451 }
16452
Dave Houlton584d51e2017-02-16 12:52:54 -070016453 // Test compressed formats, if supported
16454 VkPhysicalDeviceFeatures device_features;
16455 ASSERT_NO_FATAL_FAILURE(GetPhysicalDeviceFeatures(&device_features));
Dave Houltonf3229d52017-02-21 15:59:08 -070016456 if (!(device_features.textureCompressionBC || device_features.textureCompressionETC2 ||
16457 device_features.textureCompressionASTC_LDR)) {
16458 printf(" No compressed formats supported - block compression tests skipped.\n");
16459 } else {
Dave Houlton67e9b532017-03-02 17:00:10 -070016460 VkImageObj image_16k_4x4comp(m_device); // 128^2 texels as 32^2 compressed (4x4) blocks, 16k
16461 VkImageObj image_NPOT_4x4comp(m_device); // 130^2 texels as 33^2 compressed (4x4) blocks
Dave Houlton584d51e2017-02-16 12:52:54 -070016462 if (device_features.textureCompressionBC) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016463 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 -070016464 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_BC3_SRGB_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_OPTIMAL,
16465 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016466 } else if (device_features.textureCompressionETC2) {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016467 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 -070016468 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016469 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16470 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016471 } else {
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016472 image_16k_4x4comp.init(128, 128, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16473 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton67e9b532017-03-02 17:00:10 -070016474 image_NPOT_4x4comp.init(130, 130, VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16475 VK_IMAGE_TILING_OPTIMAL, 0);
Dave Houlton584d51e2017-02-16 12:52:54 -070016476 }
16477 ASSERT_TRUE(image_16k_4x4comp.initialized());
Dave Houlton59a20702017-02-02 17:26:23 -070016478
Dave Houlton584d51e2017-02-16 12:52:54 -070016479 // Just fits
16480 m_errorMonitor->ExpectSuccess();
16481 region.imageExtent = {128, 128, 1};
16482 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16483 buffer_16k.handle(), 1, &region);
16484 m_errorMonitor->VerifyNotFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016485
Dave Houlton584d51e2017-02-16 12:52:54 -070016486 // with offset, too big for buffer
16487 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01246);
16488 region.bufferOffset = 16;
16489 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16490 buffer_16k.handle(), 1, &region);
16491 m_errorMonitor->VerifyFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016492 region.bufferOffset = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016493
Dave Houlton67e9b532017-03-02 17:00:10 -070016494 // extents that are not a multiple of compressed block size
16495 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01275);
16496 region.imageExtent.width = 66;
16497 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16498 buffer_16k.handle(), 1, &region);
16499 m_errorMonitor->VerifyFound();
16500 region.imageExtent.width = 128;
16501
16502 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01276);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016503 region.imageExtent.height = 2;
Dave Houlton67e9b532017-03-02 17:00:10 -070016504 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16505 buffer_16k.handle(), 1, &region);
16506 m_errorMonitor->VerifyFound();
16507 region.imageExtent.height = 128;
16508
16509 // TODO: All available compressed formats are 2D, with block depth of 1. Unable to provoke VU_01277.
16510
16511 // non-multiple extents are allowed if at the far edge of a non-block-multiple image - these should pass
16512 m_errorMonitor->ExpectSuccess();
16513 region.imageExtent.width = 66;
16514 region.imageOffset.x = 64;
16515 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16516 buffer_16k.handle(), 1, &region);
16517 region.imageExtent.width = 16;
16518 region.imageOffset.x = 0;
16519 region.imageExtent.height = 2;
16520 region.imageOffset.y = 128;
16521 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_NPOT_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016522 buffer_16k.handle(), 1, &region);
16523 m_errorMonitor->VerifyNotFound();
Dave Houlton67e9b532017-03-02 17:00:10 -070016524 region.imageOffset = {0, 0, 0};
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016525
Dave Houlton584d51e2017-02-16 12:52:54 -070016526 // buffer offset must be a multiple of texel block size (16)
16527 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01274);
16528 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
16529 region.imageExtent = {64, 64, 1};
16530 region.bufferOffset = 24;
16531 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16532 buffer_16k.handle(), 1, &region);
16533 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016534
Dave Houlton584d51e2017-02-16 12:52:54 -070016535 // rowlength not a multiple of block width (4)
16536 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01271);
16537 region.bufferOffset = 0;
16538 region.bufferRowLength = 130;
16539 region.bufferImageHeight = 0;
16540 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16541 buffer_64k.handle(), 1, &region);
16542 m_errorMonitor->VerifyFound();
Dave Houlton59a20702017-02-02 17:26:23 -070016543
Dave Houlton584d51e2017-02-16 12:52:54 -070016544 // imageheight not a multiple of block height (4)
16545 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01272);
16546 region.bufferRowLength = 0;
16547 region.bufferImageHeight = 130;
16548 vkCmdCopyImageToBuffer(m_commandBuffer->GetBufferHandle(), image_16k_4x4comp.handle(), VK_IMAGE_LAYOUT_GENERAL,
16549 buffer_64k.handle(), 1, &region);
16550 m_errorMonitor->VerifyFound();
Dave Houlton584d51e2017-02-16 12:52:54 -070016551 }
Dave Houlton59a20702017-02-02 17:26:23 -070016552}
16553
Tony Barbourd6673642016-05-05 14:46:39 -060016554TEST_F(VkLayerTest, MiscImageLayerTests) {
Mark Lobodzinskie6911292017-02-15 14:38:51 -070016555 TEST_DESCRIPTION("Image-related tests that don't belong elsewhare");
Tony Barbourd6673642016-05-05 14:46:39 -060016556
16557 ASSERT_NO_FATAL_FAILURE(InitState());
16558
Rene Lindsay135204f2016-12-22 17:11:09 -070016559 // TODO: Ideally we should check if a format is supported, before using it.
Tony Barbourd6673642016-05-05 14:46:39 -060016560 VkImageObj image(m_device);
Rene Lindsay135204f2016-12-22 17:11:09 -070016561 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 -070016562 VK_IMAGE_TILING_OPTIMAL, 0); // 64bpp
Tony Barbourd6673642016-05-05 14:46:39 -060016563 ASSERT_TRUE(image.initialized());
Tony Barbourd6673642016-05-05 14:46:39 -060016564 vk_testing::Buffer buffer;
16565 VkMemoryPropertyFlags reqs = 0;
Rene Lindsay135204f2016-12-22 17:11:09 -070016566 buffer.init_as_src(*m_device, 128 * 128 * 8, reqs);
Tony Barbourd6673642016-05-05 14:46:39 -060016567 VkBufferImageCopy region = {};
16568 region.bufferRowLength = 128;
16569 region.bufferImageHeight = 128;
16570 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16571 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
Mark Lobodzinski3702e932016-11-22 11:40:48 -070016572 region.imageSubresource.layerCount = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016573 region.imageExtent.height = 4;
16574 region.imageExtent.width = 4;
16575 region.imageExtent.depth = 1;
Rene Lindsay135204f2016-12-22 17:11:09 -070016576
16577 VkImageObj image2(m_device);
16578 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 -070016579 VK_IMAGE_TILING_OPTIMAL, 0); // 16bpp
Rene Lindsay135204f2016-12-22 17:11:09 -070016580 ASSERT_TRUE(image2.initialized());
16581 vk_testing::Buffer buffer2;
16582 VkMemoryPropertyFlags reqs2 = 0;
16583 buffer2.init_as_src(*m_device, 128 * 128 * 2, reqs2);
16584 VkBufferImageCopy region2 = {};
16585 region2.bufferRowLength = 128;
16586 region2.bufferImageHeight = 128;
16587 region2.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16588 // layerCount can't be 0 - Expect MISMATCHED_IMAGE_ASPECT
16589 region2.imageSubresource.layerCount = 1;
16590 region2.imageExtent.height = 4;
16591 region2.imageExtent.width = 4;
16592 region2.imageExtent.depth = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016593 m_commandBuffer->BeginCommandBuffer();
Tony Barbourd6673642016-05-05 14:46:39 -060016594
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016595 // Image must have offset.z of 0 and extent.depth of 1
16596 // Introduce failure by setting imageExtent.depth to 0
16597 region.imageExtent.depth = 0;
Dave Houlton59a20702017-02-02 17:26:23 -070016598 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016599 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016600 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016601 m_errorMonitor->VerifyFound();
16602
16603 region.imageExtent.depth = 1;
16604
16605 // Image must have offset.z of 0 and extent.depth of 1
16606 // Introduce failure by setting imageOffset.z to 4
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016607 // Note: Also (unavoidably) triggers 'region exceeds image' #1228
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016608 region.imageOffset.z = 4;
Dave Houlton59a20702017-02-02 17:26:23 -070016609 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01747);
Dave Houlton9dae7ec2017-03-01 16:23:25 -070016610 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01228);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016611 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070016612 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinskic71cb932016-11-22 14:48:36 -070016613 m_errorMonitor->VerifyFound();
16614
16615 region.imageOffset.z = 0;
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016616 // BufferOffset must be a multiple of the calling command's VkImage parameter's texel size
16617 // Introduce failure by setting bufferOffset to 1 and 1/2 texels
Rene Lindsay135204f2016-12-22 17:11:09 -070016618 region.bufferOffset = 4;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016619 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01263);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016620 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16621 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016622 m_errorMonitor->VerifyFound();
16623
16624 // BufferOffset must be a multiple of 4
16625 // Introduce failure by setting bufferOffset to a value not divisible by 4
Rene Lindsay135204f2016-12-22 17:11:09 -070016626 region2.bufferOffset = 6;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016627 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01264);
Rene Lindsay135204f2016-12-22 17:11:09 -070016628 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer2.handle(), image2.handle(),
16629 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region2);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016630 m_errorMonitor->VerifyFound();
16631
16632 // BufferRowLength must be 0, or greater than or equal to the width member of imageExtent
16633 region.bufferOffset = 0;
16634 region.imageExtent.height = 128;
16635 region.imageExtent.width = 128;
16636 // Introduce failure by setting bufferRowLength > 0 but less than width
16637 region.bufferRowLength = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016638 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01265);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016639 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16640 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016641 m_errorMonitor->VerifyFound();
16642
16643 // BufferImageHeight must be 0, or greater than or equal to the height member of imageExtent
16644 region.bufferRowLength = 128;
16645 // Introduce failure by setting bufferRowHeight > 0 but less than height
16646 region.bufferImageHeight = 64;
Mark Lobodzinskided46f32016-11-22 14:54:44 -070016647 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01266);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016648 vkCmdCopyBufferToImage(m_commandBuffer->GetBufferHandle(), buffer.handle(), image.handle(),
16649 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
Mark Lobodzinski7d8cf142016-08-19 10:53:26 -060016650 m_errorMonitor->VerifyFound();
16651
16652 region.bufferImageHeight = 128;
Tony Barbourd6673642016-05-05 14:46:39 -060016653 VkImageObj intImage1(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016654 intImage1.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
16655 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016656 VkImageObj intImage2(m_device);
Rene Lindsaya35e1cb2016-12-26 10:30:05 -070016657 intImage2.init(128, 128, VK_FORMAT_R8_UINT, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT,
16658 VK_IMAGE_TILING_OPTIMAL, 0);
Tony Barbourd6673642016-05-05 14:46:39 -060016659 VkImageBlit blitRegion = {};
16660 blitRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16661 blitRegion.srcSubresource.baseArrayLayer = 0;
16662 blitRegion.srcSubresource.layerCount = 1;
16663 blitRegion.srcSubresource.mipLevel = 0;
16664 blitRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16665 blitRegion.dstSubresource.baseArrayLayer = 0;
16666 blitRegion.dstSubresource.layerCount = 1;
16667 blitRegion.dstSubresource.mipLevel = 0;
16668
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016669 // Look for NULL-blit warning
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016670 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "Offsets specify a zero-volume area.");
Jeremy Hayes1b5f7562017-02-09 11:20:58 -070016671 m_errorMonitor->SetUnexpectedError("vkCmdBlitImage: pRegions[0].dstOffsets specify a zero-volume area.");
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016672 vkCmdBlitImage(m_commandBuffer->GetBufferHandle(), intImage1.handle(), intImage1.layout(), intImage2.handle(),
16673 intImage2.layout(), 1, &blitRegion, VK_FILTER_LINEAR);
Mark Lobodzinskib02ea642016-08-17 13:03:57 -060016674 m_errorMonitor->VerifyFound();
16675
Mark Lobodzinskic386ecb2017-02-02 16:12:37 -070016676 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_00769);
Tony Barbourd6673642016-05-05 14:46:39 -060016677 VkImageMemoryBarrier img_barrier;
16678 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
16679 img_barrier.pNext = NULL;
16680 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
16681 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
16682 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16683 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16684 img_barrier.image = image.handle();
16685 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16686 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
16687 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16688 img_barrier.subresourceRange.baseArrayLayer = 0;
16689 img_barrier.subresourceRange.baseMipLevel = 0;
Tony Barbourd6673642016-05-05 14:46:39 -060016690 img_barrier.subresourceRange.layerCount = 0;
16691 img_barrier.subresourceRange.levelCount = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016692 vkCmdPipelineBarrier(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0,
16693 nullptr, 0, nullptr, 1, &img_barrier);
Tony Barbourd6673642016-05-05 14:46:39 -060016694 m_errorMonitor->VerifyFound();
16695 img_barrier.subresourceRange.layerCount = 1;
16696}
16697
16698TEST_F(VkLayerTest, ImageFormatLimits) {
Tony Barbourd6673642016-05-05 14:46:39 -060016699 TEST_DESCRIPTION("Exceed the limits of image format ");
16700
Cody Northropc31a84f2016-08-22 10:41:47 -060016701 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016702 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "CreateImage extents exceed allowable limits for format");
Tony Barbourd6673642016-05-05 14:46:39 -060016703 VkImageCreateInfo image_create_info = {};
16704 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16705 image_create_info.pNext = NULL;
16706 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16707 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16708 image_create_info.extent.width = 32;
16709 image_create_info.extent.height = 32;
16710 image_create_info.extent.depth = 1;
16711 image_create_info.mipLevels = 1;
16712 image_create_info.arrayLayers = 1;
16713 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16714 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16715 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16716 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16717 image_create_info.flags = 0;
16718
16719 VkImage nullImg;
16720 VkImageFormatProperties imgFmtProps;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016721 vkGetPhysicalDeviceImageFormatProperties(gpu(), image_create_info.format, image_create_info.imageType, image_create_info.tiling,
16722 image_create_info.usage, image_create_info.flags, &imgFmtProps);
Rene Lindsayef5bc012017-01-06 15:38:00 -070016723 image_create_info.extent.width = imgFmtProps.maxExtent.width + 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016724 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16725 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16726 m_errorMonitor->VerifyFound();
Rene Lindsayef5bc012017-01-06 15:38:00 -070016727 image_create_info.extent.width = 1;
Tony Barbourd6673642016-05-05 14:46:39 -060016728
Tony Barbour0907e362017-03-09 15:05:30 -070016729 uint32_t maxDim =
16730 std::max(std::max(image_create_info.extent.width, image_create_info.extent.height), image_create_info.extent.depth);
16731 // If max mip levels exceeds image extents, skip the max mip levels test
16732 if ((imgFmtProps.maxMipLevels + 1) <= (floor(log2(maxDim)) + 1)) {
16733 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
16734 image_create_info.mipLevels = imgFmtProps.maxMipLevels + 1;
16735 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16736 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16737 m_errorMonitor->VerifyFound();
16738 image_create_info.mipLevels = 1;
16739 }
Tony Barbourd6673642016-05-05 14:46:39 -060016740
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016741 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "exceeds allowable maximum supported by format of");
Tony Barbourd6673642016-05-05 14:46:39 -060016742 image_create_info.arrayLayers = imgFmtProps.maxArrayLayers + 1;
16743 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16744 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16745 m_errorMonitor->VerifyFound();
16746 image_create_info.arrayLayers = 1;
16747
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016748 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "is not supported by format");
Tony Barbourd6673642016-05-05 14:46:39 -060016749 int samples = imgFmtProps.sampleCounts >> 1;
16750 image_create_info.samples = (VkSampleCountFlagBits)samples;
16751 // Expect INVALID_FORMAT_LIMITS_VIOLATION
16752 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16753 m_errorMonitor->VerifyFound();
16754 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16755
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070016756 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16757 "pCreateInfo->initialLayout, must be "
16758 "VK_IMAGE_LAYOUT_UNDEFINED or "
16759 "VK_IMAGE_LAYOUT_PREINITIALIZED");
Tony Barbourd6673642016-05-05 14:46:39 -060016760 image_create_info.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
16761 // Expect INVALID_LAYOUT
16762 vkCreateImage(m_device->handle(), &image_create_info, NULL, &nullImg);
16763 m_errorMonitor->VerifyFound();
16764 image_create_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
16765}
16766
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016767TEST_F(VkLayerTest, CopyImageSrcSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016768 // Image copy with source region specified greater than src image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016769 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01175);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016770
16771 ASSERT_NO_FATAL_FAILURE(InitState());
16772
16773 VkImageObj src_image(m_device);
16774 src_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16775 VkImageObj dst_image(m_device);
16776 dst_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16777
Tony Barbour552f6c02016-12-21 14:34:07 -070016778 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016779 VkImageCopy copy_region;
16780 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16781 copy_region.srcSubresource.mipLevel = 0;
16782 copy_region.srcSubresource.baseArrayLayer = 0;
16783 copy_region.srcSubresource.layerCount = 0;
16784 copy_region.srcOffset.x = 0;
16785 copy_region.srcOffset.y = 0;
16786 copy_region.srcOffset.z = 0;
16787 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16788 copy_region.dstSubresource.mipLevel = 0;
16789 copy_region.dstSubresource.baseArrayLayer = 0;
16790 copy_region.dstSubresource.layerCount = 0;
16791 copy_region.dstOffset.x = 0;
16792 copy_region.dstOffset.y = 0;
16793 copy_region.dstOffset.z = 0;
16794 copy_region.extent.width = 64;
16795 copy_region.extent.height = 64;
16796 copy_region.extent.depth = 1;
16797 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16798 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016799 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016800
16801 m_errorMonitor->VerifyFound();
16802}
16803
16804TEST_F(VkLayerTest, CopyImageDstSizeExceeded) {
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016805 // Image copy with dest region specified greater than dest image size
Mark Lobodzinski629d47b2016-10-18 13:34:58 -060016806 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01176);
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016807
16808 ASSERT_NO_FATAL_FAILURE(InitState());
16809
16810 VkImageObj src_image(m_device);
16811 src_image.init(64, 64, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_IMAGE_TILING_LINEAR, 0);
16812 VkImageObj dst_image(m_device);
16813 dst_image.init(32, 32, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_TRANSFER_DST_BIT, VK_IMAGE_TILING_LINEAR, 0);
16814
Tony Barbour552f6c02016-12-21 14:34:07 -070016815 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016816 VkImageCopy copy_region;
16817 copy_region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16818 copy_region.srcSubresource.mipLevel = 0;
16819 copy_region.srcSubresource.baseArrayLayer = 0;
16820 copy_region.srcSubresource.layerCount = 0;
16821 copy_region.srcOffset.x = 0;
16822 copy_region.srcOffset.y = 0;
16823 copy_region.srcOffset.z = 0;
16824 copy_region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16825 copy_region.dstSubresource.mipLevel = 0;
16826 copy_region.dstSubresource.baseArrayLayer = 0;
16827 copy_region.dstSubresource.layerCount = 0;
16828 copy_region.dstOffset.x = 0;
16829 copy_region.dstOffset.y = 0;
16830 copy_region.dstOffset.z = 0;
16831 copy_region.extent.width = 64;
16832 copy_region.extent.height = 64;
16833 copy_region.extent.depth = 1;
16834 m_commandBuffer->CopyImage(src_image.image(), VK_IMAGE_LAYOUT_GENERAL, dst_image.image(), VK_IMAGE_LAYOUT_GENERAL, 1,
16835 &copy_region);
Tony Barbour552f6c02016-12-21 14:34:07 -070016836 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinskicea14992016-10-14 10:59:42 -060016837
16838 m_errorMonitor->VerifyFound();
16839}
16840
Karl Schultz6addd812016-02-02 17:17:23 -070016841TEST_F(VkLayerTest, CopyImageFormatSizeMismatch) {
Karl Schultzbdb75952016-04-19 11:36:49 -060016842 VkResult err;
16843 bool pass;
16844
16845 // Create color images with different format sizes and try to copy between them
Tobin Ehlis56e1bc32017-01-02 10:09:07 -070016846 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01184);
Karl Schultzbdb75952016-04-19 11:36:49 -060016847
16848 ASSERT_NO_FATAL_FAILURE(InitState());
16849
16850 // Create two images of different types and try to copy between them
16851 VkImage srcImage;
16852 VkImage dstImage;
16853 VkDeviceMemory srcMem;
16854 VkDeviceMemory destMem;
16855 VkMemoryRequirements memReqs;
16856
16857 VkImageCreateInfo image_create_info = {};
16858 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16859 image_create_info.pNext = NULL;
16860 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16861 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16862 image_create_info.extent.width = 32;
16863 image_create_info.extent.height = 32;
16864 image_create_info.extent.depth = 1;
16865 image_create_info.mipLevels = 1;
16866 image_create_info.arrayLayers = 1;
16867 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16868 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16869 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16870 image_create_info.flags = 0;
16871
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016872 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016873 ASSERT_VK_SUCCESS(err);
16874
16875 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16876 // Introduce failure by creating second image with a different-sized format.
16877 image_create_info.format = VK_FORMAT_R5G5B5A1_UNORM_PACK16;
16878
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016879 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Karl Schultzbdb75952016-04-19 11:36:49 -060016880 ASSERT_VK_SUCCESS(err);
16881
16882 // Allocate memory
16883 VkMemoryAllocateInfo memAlloc = {};
16884 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16885 memAlloc.pNext = NULL;
16886 memAlloc.allocationSize = 0;
16887 memAlloc.memoryTypeIndex = 0;
16888
16889 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
16890 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016891 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016892 ASSERT_TRUE(pass);
16893 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
16894 ASSERT_VK_SUCCESS(err);
16895
16896 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
16897 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016898 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Karl Schultzbdb75952016-04-19 11:36:49 -060016899 ASSERT_TRUE(pass);
16900 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
16901 ASSERT_VK_SUCCESS(err);
16902
16903 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
16904 ASSERT_VK_SUCCESS(err);
16905 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
16906 ASSERT_VK_SUCCESS(err);
16907
Tony Barbour552f6c02016-12-21 14:34:07 -070016908 m_commandBuffer->BeginCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016909 VkImageCopy copyRegion;
16910 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16911 copyRegion.srcSubresource.mipLevel = 0;
16912 copyRegion.srcSubresource.baseArrayLayer = 0;
16913 copyRegion.srcSubresource.layerCount = 0;
16914 copyRegion.srcOffset.x = 0;
16915 copyRegion.srcOffset.y = 0;
16916 copyRegion.srcOffset.z = 0;
16917 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
16918 copyRegion.dstSubresource.mipLevel = 0;
16919 copyRegion.dstSubresource.baseArrayLayer = 0;
16920 copyRegion.dstSubresource.layerCount = 0;
16921 copyRegion.dstOffset.x = 0;
16922 copyRegion.dstOffset.y = 0;
16923 copyRegion.dstOffset.z = 0;
16924 copyRegion.extent.width = 1;
16925 copyRegion.extent.height = 1;
16926 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016927 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070016928 m_commandBuffer->EndCommandBuffer();
Karl Schultzbdb75952016-04-19 11:36:49 -060016929
16930 m_errorMonitor->VerifyFound();
16931
16932 vkDestroyImage(m_device->device(), srcImage, NULL);
16933 vkDestroyImage(m_device->device(), dstImage, NULL);
16934 vkFreeMemory(m_device->device(), srcMem, NULL);
16935 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060016936}
16937
Karl Schultz6addd812016-02-02 17:17:23 -070016938TEST_F(VkLayerTest, CopyImageDepthStencilFormatMismatch) {
16939 VkResult err;
16940 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060016941
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016942 // Create a color image and a depth/stencil image and try to copy between them
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
16944 "vkCmdCopyImage called with unmatched source and dest image depth");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060016945
Mike Stroyana3082432015-09-25 13:39:21 -060016946 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070016947 auto depth_format = find_depth_stencil_format(m_device);
16948 if (!depth_format) {
16949 return;
16950 }
Mike Stroyana3082432015-09-25 13:39:21 -060016951
16952 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070016953 VkImage srcImage;
16954 VkImage dstImage;
16955 VkDeviceMemory srcMem;
16956 VkDeviceMemory destMem;
16957 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060016958
16959 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016960 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
16961 image_create_info.pNext = NULL;
16962 image_create_info.imageType = VK_IMAGE_TYPE_2D;
16963 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
16964 image_create_info.extent.width = 32;
16965 image_create_info.extent.height = 32;
16966 image_create_info.extent.depth = 1;
16967 image_create_info.mipLevels = 1;
16968 image_create_info.arrayLayers = 1;
16969 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
16970 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
16971 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
16972 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016973
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016974 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016975 ASSERT_VK_SUCCESS(err);
16976
Karl Schultzbdb75952016-04-19 11:36:49 -060016977 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
16978
Mark Lobodzinskidb117632016-03-31 10:45:56 -060016979 // Introduce failure by creating second image with a depth/stencil format
Karl Schultz6addd812016-02-02 17:17:23 -070016980 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Tony Barbourf887b162017-03-09 10:06:46 -070016981 image_create_info.format = depth_format;
Mark Lobodzinski867787a2016-10-14 11:49:55 -060016982 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060016983
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016984 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060016985 ASSERT_VK_SUCCESS(err);
16986
16987 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016988 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070016989 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
16990 memAlloc.pNext = NULL;
16991 memAlloc.allocationSize = 0;
16992 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060016993
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060016994 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060016995 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060016996 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060016997 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080016998 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060016999 ASSERT_VK_SUCCESS(err);
17000
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017001 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017002 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017003 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017004 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017005 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017006 ASSERT_VK_SUCCESS(err);
17007
17008 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17009 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017010 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017011 ASSERT_VK_SUCCESS(err);
17012
Tony Barbour552f6c02016-12-21 14:34:07 -070017013 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017014 VkImageCopy copyRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017015 copyRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017016 copyRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017017 copyRegion.srcSubresource.baseArrayLayer = 0;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017018 copyRegion.srcSubresource.layerCount = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017019 copyRegion.srcOffset.x = 0;
17020 copyRegion.srcOffset.y = 0;
17021 copyRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017022 copyRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017023 copyRegion.dstSubresource.mipLevel = 0;
17024 copyRegion.dstSubresource.baseArrayLayer = 0;
17025 copyRegion.dstSubresource.layerCount = 0;
17026 copyRegion.dstOffset.x = 0;
17027 copyRegion.dstOffset.y = 0;
17028 copyRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017029 copyRegion.extent.width = 1;
17030 copyRegion.extent.height = 1;
17031 copyRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017032 m_commandBuffer->CopyImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &copyRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017033 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017034
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017035 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017036
Chia-I Wuf7458c52015-10-26 21:10:41 +080017037 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017038 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017039 vkFreeMemory(m_device->device(), srcMem, NULL);
17040 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017041}
17042
Karl Schultz6addd812016-02-02 17:17:23 -070017043TEST_F(VkLayerTest, ResolveImageLowSampleCount) {
17044 VkResult err;
17045 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017046
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017047 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17048 "vkCmdResolveImage called with source sample count less than 2.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017049
Mike Stroyana3082432015-09-25 13:39:21 -060017050 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017051
17052 // Create two images of sample count 1 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017053 VkImage srcImage;
17054 VkImage dstImage;
17055 VkDeviceMemory srcMem;
17056 VkDeviceMemory destMem;
17057 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017058
17059 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017060 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17061 image_create_info.pNext = NULL;
17062 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17063 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17064 image_create_info.extent.width = 32;
17065 image_create_info.extent.height = 1;
17066 image_create_info.extent.depth = 1;
17067 image_create_info.mipLevels = 1;
17068 image_create_info.arrayLayers = 1;
17069 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17070 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17071 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
17072 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017073
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017074 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017075 ASSERT_VK_SUCCESS(err);
17076
Karl Schultz6addd812016-02-02 17:17:23 -070017077 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017078
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017079 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017080 ASSERT_VK_SUCCESS(err);
17081
17082 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017083 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017084 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17085 memAlloc.pNext = NULL;
17086 memAlloc.allocationSize = 0;
17087 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017088
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017089 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017090 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017091 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017092 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017093 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017094 ASSERT_VK_SUCCESS(err);
17095
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017096 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017097 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017098 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017099 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017100 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017101 ASSERT_VK_SUCCESS(err);
17102
17103 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17104 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017105 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017106 ASSERT_VK_SUCCESS(err);
17107
Tony Barbour552f6c02016-12-21 14:34:07 -070017108 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017109 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017110 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17111 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017112 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017113 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017114 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017115 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017116 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017117 resolveRegion.srcOffset.x = 0;
17118 resolveRegion.srcOffset.y = 0;
17119 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017120 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017121 resolveRegion.dstSubresource.mipLevel = 0;
17122 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017123 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017124 resolveRegion.dstOffset.x = 0;
17125 resolveRegion.dstOffset.y = 0;
17126 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017127 resolveRegion.extent.width = 1;
17128 resolveRegion.extent.height = 1;
17129 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017130 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017131 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017132
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017133 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017134
Chia-I Wuf7458c52015-10-26 21:10:41 +080017135 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017136 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017137 vkFreeMemory(m_device->device(), srcMem, NULL);
17138 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017139}
17140
Karl Schultz6addd812016-02-02 17:17:23 -070017141TEST_F(VkLayerTest, ResolveImageHighSampleCount) {
17142 VkResult err;
17143 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017144
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017145 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17146 "vkCmdResolveImage called with dest sample count greater than 1.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017147
Mike Stroyana3082432015-09-25 13:39:21 -060017148 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017149
Chris Forbesa7530692016-05-08 12:35:39 +120017150 // Create two images of sample count 4 and try to Resolve between them
Karl Schultz6addd812016-02-02 17:17:23 -070017151 VkImage srcImage;
17152 VkImage dstImage;
17153 VkDeviceMemory srcMem;
17154 VkDeviceMemory destMem;
17155 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017156
17157 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017158 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17159 image_create_info.pNext = NULL;
17160 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17161 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17162 image_create_info.extent.width = 32;
17163 image_create_info.extent.height = 1;
17164 image_create_info.extent.depth = 1;
17165 image_create_info.mipLevels = 1;
17166 image_create_info.arrayLayers = 1;
Chris Forbesa7530692016-05-08 12:35:39 +120017167 image_create_info.samples = VK_SAMPLE_COUNT_4_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017168 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17169 // Note: Some implementations expect color attachment usage for any
17170 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017171 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017172 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017173
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017174 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017175 ASSERT_VK_SUCCESS(err);
17176
Karl Schultz6addd812016-02-02 17:17:23 -070017177 // Note: Some implementations expect color attachment usage for any
17178 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017179 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017180
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017181 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017182 ASSERT_VK_SUCCESS(err);
17183
17184 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017185 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017186 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17187 memAlloc.pNext = NULL;
17188 memAlloc.allocationSize = 0;
17189 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017190
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017191 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017192 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017193 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017194 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017195 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017196 ASSERT_VK_SUCCESS(err);
17197
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017198 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017199 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017200 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017201 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017202 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017203 ASSERT_VK_SUCCESS(err);
17204
17205 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17206 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017207 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017208 ASSERT_VK_SUCCESS(err);
17209
Tony Barbour552f6c02016-12-21 14:34:07 -070017210 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017211 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017212 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17213 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017214 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017215 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017216 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017217 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017218 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017219 resolveRegion.srcOffset.x = 0;
17220 resolveRegion.srcOffset.y = 0;
17221 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017222 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017223 resolveRegion.dstSubresource.mipLevel = 0;
17224 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017225 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017226 resolveRegion.dstOffset.x = 0;
17227 resolveRegion.dstOffset.y = 0;
17228 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017229 resolveRegion.extent.width = 1;
17230 resolveRegion.extent.height = 1;
17231 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017232 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017233 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017234
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017235 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017236
Chia-I Wuf7458c52015-10-26 21:10:41 +080017237 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017238 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017239 vkFreeMemory(m_device->device(), srcMem, NULL);
17240 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017241}
17242
Karl Schultz6addd812016-02-02 17:17:23 -070017243TEST_F(VkLayerTest, ResolveImageFormatMismatch) {
17244 VkResult err;
17245 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017246
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017247 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017248 "vkCmdResolveImage called with unmatched source and dest formats.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017249
Mike Stroyana3082432015-09-25 13:39:21 -060017250 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017251
17252 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017253 VkImage srcImage;
17254 VkImage dstImage;
17255 VkDeviceMemory srcMem;
17256 VkDeviceMemory destMem;
17257 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017258
17259 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017260 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17261 image_create_info.pNext = NULL;
17262 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17263 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17264 image_create_info.extent.width = 32;
17265 image_create_info.extent.height = 1;
17266 image_create_info.extent.depth = 1;
17267 image_create_info.mipLevels = 1;
17268 image_create_info.arrayLayers = 1;
17269 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17270 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17271 // Note: Some implementations expect color attachment usage for any
17272 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017273 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017274 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017275
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017276 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017277 ASSERT_VK_SUCCESS(err);
17278
Karl Schultz6addd812016-02-02 17:17:23 -070017279 // Set format to something other than source image
17280 image_create_info.format = VK_FORMAT_R32_SFLOAT;
17281 // Note: Some implementations expect color attachment usage for any
17282 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017283 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017284 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017285
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017286 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017287 ASSERT_VK_SUCCESS(err);
17288
17289 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017290 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017291 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17292 memAlloc.pNext = NULL;
17293 memAlloc.allocationSize = 0;
17294 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017295
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017296 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017297 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017298 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017299 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017300 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017301 ASSERT_VK_SUCCESS(err);
17302
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017303 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017304 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017305 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017306 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017307 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017308 ASSERT_VK_SUCCESS(err);
17309
17310 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17311 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017312 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017313 ASSERT_VK_SUCCESS(err);
17314
Tony Barbour552f6c02016-12-21 14:34:07 -070017315 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017316 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017317 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17318 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017319 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017320 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017321 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017322 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017323 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017324 resolveRegion.srcOffset.x = 0;
17325 resolveRegion.srcOffset.y = 0;
17326 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017327 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017328 resolveRegion.dstSubresource.mipLevel = 0;
17329 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017330 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017331 resolveRegion.dstOffset.x = 0;
17332 resolveRegion.dstOffset.y = 0;
17333 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017334 resolveRegion.extent.width = 1;
17335 resolveRegion.extent.height = 1;
17336 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017337 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017338 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017339
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017340 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017341
Chia-I Wuf7458c52015-10-26 21:10:41 +080017342 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017343 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017344 vkFreeMemory(m_device->device(), srcMem, NULL);
17345 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017346}
17347
Karl Schultz6addd812016-02-02 17:17:23 -070017348TEST_F(VkLayerTest, ResolveImageTypeMismatch) {
17349 VkResult err;
17350 bool pass;
Mike Stroyana3082432015-09-25 13:39:21 -060017351
Mark Lobodzinski50fbef12017-02-06 15:31:33 -070017352 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT,
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017353 "vkCmdResolveImage called with unmatched source and dest image types.");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017354
Mike Stroyana3082432015-09-25 13:39:21 -060017355 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Stroyana3082432015-09-25 13:39:21 -060017356
17357 // Create two images of different types and try to copy between them
Karl Schultz6addd812016-02-02 17:17:23 -070017358 VkImage srcImage;
17359 VkImage dstImage;
17360 VkDeviceMemory srcMem;
17361 VkDeviceMemory destMem;
17362 VkMemoryRequirements memReqs;
Mike Stroyana3082432015-09-25 13:39:21 -060017363
17364 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017365 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17366 image_create_info.pNext = NULL;
17367 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17368 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
17369 image_create_info.extent.width = 32;
17370 image_create_info.extent.height = 1;
17371 image_create_info.extent.depth = 1;
17372 image_create_info.mipLevels = 1;
17373 image_create_info.arrayLayers = 1;
17374 image_create_info.samples = VK_SAMPLE_COUNT_2_BIT;
17375 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
17376 // Note: Some implementations expect color attachment usage for any
17377 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017378 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017379 image_create_info.flags = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017380
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017381 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &srcImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017382 ASSERT_VK_SUCCESS(err);
17383
Karl Schultz6addd812016-02-02 17:17:23 -070017384 image_create_info.imageType = VK_IMAGE_TYPE_1D;
17385 // Note: Some implementations expect color attachment usage for any
17386 // multisample surface
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017387 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017388 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017389
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017390 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &dstImage);
Mike Stroyana3082432015-09-25 13:39:21 -060017391 ASSERT_VK_SUCCESS(err);
17392
17393 // Allocate memory
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017394 VkMemoryAllocateInfo memAlloc = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017395 memAlloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17396 memAlloc.pNext = NULL;
17397 memAlloc.allocationSize = 0;
17398 memAlloc.memoryTypeIndex = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017399
Courtney Goeltzenleuchter06d89472015-10-20 16:40:38 -060017400 vkGetImageMemoryRequirements(m_device->device(), srcImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017401 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017402 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017403 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017404 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &srcMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017405 ASSERT_VK_SUCCESS(err);
17406
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017407 vkGetImageMemoryRequirements(m_device->device(), dstImage, &memReqs);
Mike Stroyana3082432015-09-25 13:39:21 -060017408 memAlloc.allocationSize = memReqs.size;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017409 pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &memAlloc, 0);
Courtney Goeltzenleuchter1d2f0dd2015-10-22 11:03:31 -060017410 ASSERT_TRUE(pass);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017411 err = vkAllocateMemory(m_device->device(), &memAlloc, NULL, &destMem);
Mike Stroyana3082432015-09-25 13:39:21 -060017412 ASSERT_VK_SUCCESS(err);
17413
17414 err = vkBindImageMemory(m_device->device(), srcImage, srcMem, 0);
17415 ASSERT_VK_SUCCESS(err);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017416 err = vkBindImageMemory(m_device->device(), dstImage, destMem, 0);
Mike Stroyana3082432015-09-25 13:39:21 -060017417 ASSERT_VK_SUCCESS(err);
17418
Tony Barbour552f6c02016-12-21 14:34:07 -070017419 m_commandBuffer->BeginCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017420 // Need memory barrier to VK_IMAGE_LAYOUT_GENERAL for source and dest?
Karl Schultz6addd812016-02-02 17:17:23 -070017421 // VK_IMAGE_LAYOUT_UNDEFINED = 0,
17422 // VK_IMAGE_LAYOUT_GENERAL = 1,
Mike Stroyana3082432015-09-25 13:39:21 -060017423 VkImageResolve resolveRegion;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017424 resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Mike Stroyana3082432015-09-25 13:39:21 -060017425 resolveRegion.srcSubresource.mipLevel = 0;
Courtney Goeltzenleuchter8367ce02015-10-16 09:46:00 -060017426 resolveRegion.srcSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017427 resolveRegion.srcSubresource.layerCount = 1;
Mike Stroyana3082432015-09-25 13:39:21 -060017428 resolveRegion.srcOffset.x = 0;
17429 resolveRegion.srcOffset.y = 0;
17430 resolveRegion.srcOffset.z = 0;
Chia-I Wuab83a0e2015-10-27 19:00:15 +080017431 resolveRegion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017432 resolveRegion.dstSubresource.mipLevel = 0;
17433 resolveRegion.dstSubresource.baseArrayLayer = 0;
Chris Forbes496c5982016-10-03 14:16:36 +130017434 resolveRegion.dstSubresource.layerCount = 1;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017435 resolveRegion.dstOffset.x = 0;
17436 resolveRegion.dstOffset.y = 0;
17437 resolveRegion.dstOffset.z = 0;
Mike Stroyana3082432015-09-25 13:39:21 -060017438 resolveRegion.extent.width = 1;
17439 resolveRegion.extent.height = 1;
17440 resolveRegion.extent.depth = 1;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017441 m_commandBuffer->ResolveImage(srcImage, VK_IMAGE_LAYOUT_GENERAL, dstImage, VK_IMAGE_LAYOUT_GENERAL, 1, &resolveRegion);
Tony Barbour552f6c02016-12-21 14:34:07 -070017442 m_commandBuffer->EndCommandBuffer();
Mike Stroyana3082432015-09-25 13:39:21 -060017443
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017444 m_errorMonitor->VerifyFound();
Mike Stroyana3082432015-09-25 13:39:21 -060017445
Chia-I Wuf7458c52015-10-26 21:10:41 +080017446 vkDestroyImage(m_device->device(), srcImage, NULL);
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017447 vkDestroyImage(m_device->device(), dstImage, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017448 vkFreeMemory(m_device->device(), srcMem, NULL);
17449 vkFreeMemory(m_device->device(), destMem, NULL);
Mike Stroyana3082432015-09-25 13:39:21 -060017450}
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017451
Karl Schultz6addd812016-02-02 17:17:23 -070017452TEST_F(VkLayerTest, DepthStencilImageViewWithColorAspectBitError) {
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017453 // Create a single Image descriptor and cause it to first hit an error due
Karl Schultz6addd812016-02-02 17:17:23 -070017454 // to using a DS format, then cause it to hit error due to COLOR_BIT not
17455 // set in aspect
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017456 // The image format check comes 2nd in validation so we trigger it first,
17457 // then when we cause aspect fail next, bad format check will be preempted
Karl Schultz6addd812016-02-02 17:17:23 -070017458 VkResult err;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017459
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017460 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17461 "Combination depth/stencil image formats can have only the ");
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017462
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017463 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017464 auto depth_format = find_depth_stencil_format(m_device);
17465 if (!depth_format) {
17466 return;
17467 }
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017468
Chia-I Wu1b99bb22015-10-27 19:25:11 +080017469 VkDescriptorPoolSize ds_type_count = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017470 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17471 ds_type_count.descriptorCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017472
17473 VkDescriptorPoolCreateInfo ds_pool_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017474 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
17475 ds_pool_ci.pNext = NULL;
17476 ds_pool_ci.maxSets = 1;
17477 ds_pool_ci.poolSizeCount = 1;
17478 ds_pool_ci.pPoolSizes = &ds_type_count;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017479
17480 VkDescriptorPool ds_pool;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017481 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017482 ASSERT_VK_SUCCESS(err);
17483
17484 VkDescriptorSetLayoutBinding dsl_binding = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017485 dsl_binding.binding = 0;
17486 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
17487 dsl_binding.descriptorCount = 1;
17488 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
17489 dsl_binding.pImmutableSamplers = NULL;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017490
17491 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017492 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
17493 ds_layout_ci.pNext = NULL;
17494 ds_layout_ci.bindingCount = 1;
17495 ds_layout_ci.pBindings = &dsl_binding;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017496 VkDescriptorSetLayout ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017497 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017498 ASSERT_VK_SUCCESS(err);
17499
17500 VkDescriptorSet descriptorSet;
Chia-I Wu3432a0c2015-10-27 18:04:07 +080017501 VkDescriptorSetAllocateInfo alloc_info = {};
Chia-I Wu00ce5402015-11-10 16:21:09 +080017502 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
Jon Ashburnf19916e2016-01-11 13:12:43 -070017503 alloc_info.descriptorSetCount = 1;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017504 alloc_info.descriptorPool = ds_pool;
17505 alloc_info.pSetLayouts = &ds_layout;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017506 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptorSet);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017507 ASSERT_VK_SUCCESS(err);
17508
Karl Schultz6addd812016-02-02 17:17:23 -070017509 VkImage image_bad;
17510 VkImage image_good;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017511 // One bad format and one good format for Color attachment
Tony Barbourf887b162017-03-09 10:06:46 -070017512 const VkFormat tex_format_bad = depth_format;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017513 const VkFormat tex_format_good = VK_FORMAT_B8G8R8A8_UNORM;
Karl Schultz6addd812016-02-02 17:17:23 -070017514 const int32_t tex_width = 32;
17515 const int32_t tex_height = 32;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017516
17517 VkImageCreateInfo image_create_info = {};
Karl Schultz6addd812016-02-02 17:17:23 -070017518 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17519 image_create_info.pNext = NULL;
17520 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17521 image_create_info.format = tex_format_bad;
17522 image_create_info.extent.width = tex_width;
17523 image_create_info.extent.height = tex_height;
17524 image_create_info.extent.depth = 1;
17525 image_create_info.mipLevels = 1;
17526 image_create_info.arrayLayers = 1;
17527 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17528 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017529 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
Karl Schultz6addd812016-02-02 17:17:23 -070017530 image_create_info.flags = 0;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017531
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017532 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_bad);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017533 ASSERT_VK_SUCCESS(err);
17534 image_create_info.format = tex_format_good;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017535 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17536 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image_good);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017537 ASSERT_VK_SUCCESS(err);
17538
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017539 // ---Bind image memory---
17540 VkMemoryRequirements img_mem_reqs;
17541 vkGetImageMemoryRequirements(m_device->device(), image_bad, &img_mem_reqs);
17542 VkMemoryAllocateInfo image_alloc_info = {};
17543 image_alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
17544 image_alloc_info.pNext = NULL;
17545 image_alloc_info.memoryTypeIndex = 0;
17546 image_alloc_info.allocationSize = img_mem_reqs.size;
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017547 bool pass =
17548 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 -070017549 ASSERT_TRUE(pass);
17550 VkDeviceMemory mem;
17551 err = vkAllocateMemory(m_device->device(), &image_alloc_info, NULL, &mem);
17552 ASSERT_VK_SUCCESS(err);
17553 err = vkBindImageMemory(m_device->device(), image_bad, mem, 0);
17554 ASSERT_VK_SUCCESS(err);
17555 // -----------------------
17556
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017557 VkImageViewCreateInfo image_view_create_info = {};
Chris Forbes53bef902016-11-28 17:53:04 +130017558 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
Karl Schultz6addd812016-02-02 17:17:23 -070017559 image_view_create_info.image = image_bad;
17560 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
17561 image_view_create_info.format = tex_format_bad;
17562 image_view_create_info.subresourceRange.baseArrayLayer = 0;
17563 image_view_create_info.subresourceRange.baseMipLevel = 0;
17564 image_view_create_info.subresourceRange.layerCount = 1;
17565 image_view_create_info.subresourceRange.levelCount = 1;
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017566 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT;
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017567
17568 VkImageView view;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017569 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
Mark Lobodzinski8507f2f2015-10-29 09:02:49 -060017570
Chris Forbes8f36a8a2016-04-07 13:21:07 +120017571 m_errorMonitor->VerifyFound();
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017572
Chia-I Wuf7458c52015-10-26 21:10:41 +080017573 vkDestroyImage(m_device->device(), image_bad, NULL);
17574 vkDestroyImage(m_device->device(), image_good, NULL);
Chia-I Wuf7458c52015-10-26 21:10:41 +080017575 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
17576 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
Rene Lindsayf1e89c82016-12-28 13:18:31 -070017577
17578 vkFreeMemory(m_device->device(), mem, NULL);
Tobin Ehlisa1c28562015-10-23 16:00:08 -060017579}
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017580
17581TEST_F(VkLayerTest, ClearImageErrors) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017582 TEST_DESCRIPTION(
17583 "Call ClearColorImage w/ a depth|stencil image and "
17584 "ClearDepthStencilImage with a color image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017585
17586 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070017587 auto depth_format = find_depth_stencil_format(m_device);
17588 if (!depth_format) {
17589 return;
17590 }
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017591 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
17592
Tony Barbour552f6c02016-12-21 14:34:07 -070017593 m_commandBuffer->BeginCommandBuffer();
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017594
17595 // Color image
17596 VkClearColorValue clear_color;
17597 memset(clear_color.uint32, 0, sizeof(uint32_t) * 4);
17598 VkMemoryPropertyFlags reqs = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
17599 const VkFormat color_format = VK_FORMAT_B8G8R8A8_UNORM;
17600 const int32_t img_width = 32;
17601 const int32_t img_height = 32;
17602 VkImageCreateInfo image_create_info = {};
17603 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
17604 image_create_info.pNext = NULL;
17605 image_create_info.imageType = VK_IMAGE_TYPE_2D;
17606 image_create_info.format = color_format;
17607 image_create_info.extent.width = img_width;
17608 image_create_info.extent.height = img_height;
17609 image_create_info.extent.depth = 1;
17610 image_create_info.mipLevels = 1;
17611 image_create_info.arrayLayers = 1;
17612 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
17613 image_create_info.tiling = VK_IMAGE_TILING_LINEAR;
17614 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
17615
17616 vk_testing::Image color_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017617 color_image.init(*m_device, (const VkImageCreateInfo &)image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017618
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017619 const VkImageSubresourceRange color_range = vk_testing::Image::subresource_range(image_create_info, VK_IMAGE_ASPECT_COLOR_BIT);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017620
17621 // Depth/Stencil image
17622 VkClearDepthStencilValue clear_value = {0};
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017623 reqs = 0; // don't need HOST_VISIBLE DS image
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017624 VkImageCreateInfo ds_image_create_info = vk_testing::Image::create_info();
17625 ds_image_create_info.imageType = VK_IMAGE_TYPE_2D;
Tony Barbourf887b162017-03-09 10:06:46 -070017626 ds_image_create_info.format = depth_format;
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017627 ds_image_create_info.extent.width = 64;
17628 ds_image_create_info.extent.height = 64;
17629 ds_image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017630 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 -060017631
17632 vk_testing::Image ds_image;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017633 ds_image.init(*m_device, (const VkImageCreateInfo &)ds_image_create_info, reqs);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017634
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017635 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 -060017636
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017637 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "vkCmdClearColorImage called with depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017638
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017639 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), ds_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017640 &color_range);
17641
17642 m_errorMonitor->VerifyFound();
17643
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017644 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17645 "vkCmdClearColorImage called with "
17646 "image created without "
17647 "VK_IMAGE_USAGE_TRANSFER_DST_BIT");
Tony Barbour26434b92016-06-02 09:43:50 -060017648
Rene Lindsaya1fc64a2016-12-27 15:18:54 -070017649 vkCmdClearColorImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_GENERAL, &clear_color, 1,
Tony Barbour26434b92016-06-02 09:43:50 -060017650 &color_range);
17651
17652 m_errorMonitor->VerifyFound();
17653
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017654 // Call CmdClearDepthStencilImage with color image
Mark Lobodzinskice751c62016-09-08 10:45:35 -060017655 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17656 "vkCmdClearDepthStencilImage called without a depth/stencil image.");
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017657
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070017658 vkCmdClearDepthStencilImage(m_commandBuffer->GetBufferHandle(), color_image.handle(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
17659 &clear_value, 1, &ds_range);
Tobin Ehlis6e23d772016-05-19 11:08:34 -060017660
17661 m_errorMonitor->VerifyFound();
17662}
Tobin Ehliscde08892015-09-22 10:11:37 -060017663
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017664// WSI Enabled Tests
17665//
Chris Forbes09368e42016-10-13 11:59:22 +130017666#if 0
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017667TEST_F(VkWsiEnabledLayerTest, TestEnabledWsi) {
17668
17669#if defined(VK_USE_PLATFORM_XCB_KHR)
17670 VkSurfaceKHR surface = VK_NULL_HANDLE;
17671
17672 VkResult err;
17673 bool pass;
17674 VkSwapchainKHR swapchain = VK_NULL_HANDLE;
17675 VkSwapchainCreateInfoKHR swapchain_create_info = {};
17676 // uint32_t swapchain_image_count = 0;
17677 // VkImage swapchain_images[1] = {VK_NULL_HANDLE};
17678 // uint32_t image_index = 0;
17679 // VkPresentInfoKHR present_info = {};
17680
17681 ASSERT_NO_FATAL_FAILURE(InitState());
17682
17683 // Use the create function from one of the VK_KHR_*_surface extension in
17684 // order to create a surface, testing all known errors in the process,
17685 // before successfully creating a surface:
17686 // First, try to create a surface without a VkXcbSurfaceCreateInfoKHR:
17687 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo specified as NULL");
17688 err = vkCreateXcbSurfaceKHR(instance(), NULL, NULL, &surface);
17689 pass = (err != VK_SUCCESS);
17690 ASSERT_TRUE(pass);
17691 m_errorMonitor->VerifyFound();
17692
17693 // Next, try to create a surface with the wrong
17694 // VkXcbSurfaceCreateInfoKHR::sType:
17695 VkXcbSurfaceCreateInfoKHR xcb_create_info = {};
17696 xcb_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17697 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17698 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17699 pass = (err != VK_SUCCESS);
17700 ASSERT_TRUE(pass);
17701 m_errorMonitor->VerifyFound();
17702
17703 // Create a native window, and then correctly create a surface:
17704 xcb_connection_t *connection;
17705 xcb_screen_t *screen;
17706 xcb_window_t xcb_window;
17707 xcb_intern_atom_reply_t *atom_wm_delete_window;
17708
17709 const xcb_setup_t *setup;
17710 xcb_screen_iterator_t iter;
17711 int scr;
17712 uint32_t value_mask, value_list[32];
17713 int width = 1;
17714 int height = 1;
17715
17716 connection = xcb_connect(NULL, &scr);
17717 ASSERT_TRUE(connection != NULL);
17718 setup = xcb_get_setup(connection);
17719 iter = xcb_setup_roots_iterator(setup);
17720 while (scr-- > 0)
17721 xcb_screen_next(&iter);
17722 screen = iter.data;
17723
17724 xcb_window = xcb_generate_id(connection);
17725
17726 value_mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;
17727 value_list[0] = screen->black_pixel;
17728 value_list[1] = XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
17729
17730 xcb_create_window(connection, XCB_COPY_FROM_PARENT, xcb_window, screen->root, 0, 0, width, height, 0,
17731 XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, value_mask, value_list);
17732
17733 /* Magic code that will send notification when window is destroyed */
17734 xcb_intern_atom_cookie_t cookie = xcb_intern_atom(connection, 1, 12, "WM_PROTOCOLS");
17735 xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(connection, cookie, 0);
17736
17737 xcb_intern_atom_cookie_t cookie2 = xcb_intern_atom(connection, 0, 16, "WM_DELETE_WINDOW");
17738 atom_wm_delete_window = xcb_intern_atom_reply(connection, cookie2, 0);
17739 xcb_change_property(connection, XCB_PROP_MODE_REPLACE, xcb_window, (*reply).atom, 4, 32, 1, &(*atom_wm_delete_window).atom);
17740 free(reply);
17741
17742 xcb_map_window(connection, xcb_window);
17743
17744 // Force the x/y coordinates to 100,100 results are identical in consecutive
17745 // runs
17746 const uint32_t coords[] = { 100, 100 };
17747 xcb_configure_window(connection, xcb_window, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, coords);
17748
17749 // Finally, try to correctly create a surface:
17750 xcb_create_info.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
17751 xcb_create_info.pNext = NULL;
17752 xcb_create_info.flags = 0;
17753 xcb_create_info.connection = connection;
17754 xcb_create_info.window = xcb_window;
17755 err = vkCreateXcbSurfaceKHR(instance(), &xcb_create_info, NULL, &surface);
17756 pass = (err == VK_SUCCESS);
17757 ASSERT_TRUE(pass);
17758
17759 // Check if surface supports presentation:
17760
17761 // 1st, do so without having queried the queue families:
17762 VkBool32 supported = false;
17763 // TODO: Get the following error to come out:
17764 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17765 "called before calling the vkGetPhysicalDeviceQueueFamilyProperties "
17766 "function");
17767 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17768 pass = (err != VK_SUCCESS);
17769 // ASSERT_TRUE(pass);
17770 // m_errorMonitor->VerifyFound();
17771
17772 // Next, query a queue family index that's too large:
17773 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17774 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 100000, surface, &supported);
17775 pass = (err != VK_SUCCESS);
17776 ASSERT_TRUE(pass);
17777 m_errorMonitor->VerifyFound();
17778
17779 // Finally, do so correctly:
17780 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17781 // SUPPORTED
17782 err = vkGetPhysicalDeviceSurfaceSupportKHR(gpu(), 0, surface, &supported);
17783 pass = (err == VK_SUCCESS);
17784 ASSERT_TRUE(pass);
17785
17786 // Before proceeding, try to create a swapchain without having called
17787 // vkGetPhysicalDeviceSurfaceCapabilitiesKHR():
17788 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17789 swapchain_create_info.pNext = NULL;
17790 swapchain_create_info.flags = 0;
17791 swapchain_create_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
17792 swapchain_create_info.surface = surface;
17793 swapchain_create_info.imageArrayLayers = 1;
17794 swapchain_create_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
17795 swapchain_create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
17796 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17797 "called before calling vkGetPhysicalDeviceSurfaceCapabilitiesKHR().");
17798 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17799 pass = (err != VK_SUCCESS);
17800 ASSERT_TRUE(pass);
17801 m_errorMonitor->VerifyFound();
17802
17803 // Get the surface capabilities:
17804 VkSurfaceCapabilitiesKHR surface_capabilities;
17805
17806 // Do so correctly (only error logged by this entrypoint is if the
17807 // extension isn't enabled):
17808 err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu(), surface, &surface_capabilities);
17809 pass = (err == VK_SUCCESS);
17810 ASSERT_TRUE(pass);
17811
17812 // Get the surface formats:
17813 uint32_t surface_format_count;
17814
17815 // First, try without a pointer to surface_format_count:
17816 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSurfaceFormatCount "
17817 "specified as NULL");
17818 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, NULL, NULL);
17819 pass = (err == VK_SUCCESS);
17820 ASSERT_TRUE(pass);
17821 m_errorMonitor->VerifyFound();
17822
17823 // Next, call with a non-NULL pSurfaceFormats, even though we haven't
17824 // correctly done a 1st try (to get the count):
17825 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17826 surface_format_count = 0;
17827 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, (VkSurfaceFormatKHR *)&surface_format_count);
17828 pass = (err == VK_SUCCESS);
17829 ASSERT_TRUE(pass);
17830 m_errorMonitor->VerifyFound();
17831
17832 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17833 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17834 pass = (err == VK_SUCCESS);
17835 ASSERT_TRUE(pass);
17836
17837 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17838 VkSurfaceFormatKHR *surface_formats = (VkSurfaceFormatKHR *)malloc(surface_format_count * sizeof(VkSurfaceFormatKHR));
17839
17840 // Next, do a 2nd try with surface_format_count being set too high:
17841 surface_format_count += 5;
17842 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17843 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17844 pass = (err == VK_SUCCESS);
17845 ASSERT_TRUE(pass);
17846 m_errorMonitor->VerifyFound();
17847
17848 // Finally, do a correct 1st and 2nd try:
17849 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, NULL);
17850 pass = (err == VK_SUCCESS);
17851 ASSERT_TRUE(pass);
17852 vkGetPhysicalDeviceSurfaceFormatsKHR(gpu(), surface, &surface_format_count, surface_formats);
17853 pass = (err == VK_SUCCESS);
17854 ASSERT_TRUE(pass);
17855
17856 // Get the surface present modes:
17857 uint32_t surface_present_mode_count;
17858
17859 // First, try without a pointer to surface_format_count:
17860 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pPresentModeCount "
17861 "specified as NULL");
17862
17863 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, NULL, NULL);
17864 pass = (err == VK_SUCCESS);
17865 ASSERT_TRUE(pass);
17866 m_errorMonitor->VerifyFound();
17867
17868 // Next, call with a non-NULL VkPresentModeKHR, even though we haven't
17869 // correctly done a 1st try (to get the count):
17870 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_WARNING_BIT_EXT, "but no prior positive value has been seen for");
17871 surface_present_mode_count = 0;
17872 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count,
17873 (VkPresentModeKHR *)&surface_present_mode_count);
17874 pass = (err == VK_SUCCESS);
17875 ASSERT_TRUE(pass);
17876 m_errorMonitor->VerifyFound();
17877
17878 // Next, correctly do a 1st try (with a NULL pointer to surface_formats):
17879 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17880 pass = (err == VK_SUCCESS);
17881 ASSERT_TRUE(pass);
17882
17883 // Allocate memory for the correct number of VkSurfaceFormatKHR's:
17884 VkPresentModeKHR *surface_present_modes = (VkPresentModeKHR *)malloc(surface_present_mode_count * sizeof(VkPresentModeKHR));
17885
17886 // Next, do a 2nd try with surface_format_count being set too high:
17887 surface_present_mode_count += 5;
17888 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "that is greater than the value");
17889 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17890 pass = (err == VK_SUCCESS);
17891 ASSERT_TRUE(pass);
17892 m_errorMonitor->VerifyFound();
17893
17894 // Finally, do a correct 1st and 2nd try:
17895 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, NULL);
17896 pass = (err == VK_SUCCESS);
17897 ASSERT_TRUE(pass);
17898 vkGetPhysicalDeviceSurfacePresentModesKHR(gpu(), surface, &surface_present_mode_count, surface_present_modes);
17899 pass = (err == VK_SUCCESS);
17900 ASSERT_TRUE(pass);
17901
17902 // Create a swapchain:
17903
17904 // First, try without a pointer to swapchain_create_info:
17905 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pCreateInfo "
17906 "specified as NULL");
17907
17908 err = vkCreateSwapchainKHR(m_device->device(), NULL, NULL, &swapchain);
17909 pass = (err != VK_SUCCESS);
17910 ASSERT_TRUE(pass);
17911 m_errorMonitor->VerifyFound();
17912
17913 // Next, call with a non-NULL swapchain_create_info, that has the wrong
17914 // sType:
17915 swapchain_create_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
17916 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "parameter pCreateInfo->sType must be");
17917
17918 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17919 pass = (err != VK_SUCCESS);
17920 ASSERT_TRUE(pass);
17921 m_errorMonitor->VerifyFound();
17922
17923 // Next, call with a NULL swapchain pointer:
17924 swapchain_create_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
17925 swapchain_create_info.pNext = NULL;
17926 swapchain_create_info.flags = 0;
17927 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "required parameter pSwapchain "
17928 "specified as NULL");
17929
17930 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, NULL);
17931 pass = (err != VK_SUCCESS);
17932 ASSERT_TRUE(pass);
17933 m_errorMonitor->VerifyFound();
17934
17935 // TODO: Enhance swapchain layer so that
17936 // swapchain_create_info.queueFamilyIndexCount is checked against something?
17937
17938 // Next, call with a queue family index that's too large:
17939 uint32_t queueFamilyIndex[2] = { 100000, 0 };
17940 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17941 swapchain_create_info.queueFamilyIndexCount = 2;
17942 swapchain_create_info.pQueueFamilyIndices = queueFamilyIndex;
17943 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, "called with a queueFamilyIndex that is too large");
17944 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17945 pass = (err != VK_SUCCESS);
17946 ASSERT_TRUE(pass);
17947 m_errorMonitor->VerifyFound();
17948
17949 // Next, call a queueFamilyIndexCount that's too small for CONCURRENT:
17950 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
17951 swapchain_create_info.queueFamilyIndexCount = 1;
17952 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17953 "but with a bad value(s) for pCreateInfo->queueFamilyIndexCount or "
17954 "pCreateInfo->pQueueFamilyIndices).");
17955 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17956 pass = (err != VK_SUCCESS);
17957 ASSERT_TRUE(pass);
17958 m_errorMonitor->VerifyFound();
17959
17960 // Next, call with an invalid imageSharingMode:
17961 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_MAX_ENUM;
17962 swapchain_create_info.queueFamilyIndexCount = 1;
17963 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
17964 "called with a non-supported pCreateInfo->imageSharingMode (i.e.");
17965 err = vkCreateSwapchainKHR(m_device->device(), &swapchain_create_info, NULL, &swapchain);
17966 pass = (err != VK_SUCCESS);
17967 ASSERT_TRUE(pass);
17968 m_errorMonitor->VerifyFound();
17969 // Fix for the future:
17970 // FIXME: THIS ISN'T CORRECT--MUST QUERY UNTIL WE FIND A QUEUE FAMILY THAT'S
17971 // SUPPORTED
17972 swapchain_create_info.queueFamilyIndexCount = 0;
17973 queueFamilyIndex[0] = 0;
17974 swapchain_create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
17975
17976 // TODO: CONTINUE TESTING VALIDATION OF vkCreateSwapchainKHR() ...
17977 // Get the images from a swapchain:
17978 // Acquire an image from a swapchain:
17979 // Present an image to a swapchain:
17980 // Destroy the swapchain:
17981
17982 // TODOs:
17983 //
17984 // - Try destroying the device without first destroying the swapchain
17985 //
17986 // - Try destroying the device without first destroying the surface
17987 //
17988 // - Try destroying the surface without first destroying the swapchain
17989
17990 // Destroy the surface:
17991 vkDestroySurfaceKHR(instance(), surface, NULL);
17992
17993 // Tear down the window:
17994 xcb_destroy_window(connection, xcb_window);
17995 xcb_disconnect(connection);
17996
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017997#else // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060017998 return;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070017999#endif // VK_USE_PLATFORM_XCB_KHR
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018000}
Chris Forbes09368e42016-10-13 11:59:22 +130018001#endif
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018002
18003//
18004// POSITIVE VALIDATION TESTS
18005//
18006// These tests do not expect to encounter ANY validation errors pass only if this is true
18007
Mark Lobodzinski781aeb52017-02-22 10:57:53 -070018008TEST_F(VkPositiveLayerTest, SecondaryCommandBufferClearColorAttachments) {
18009 TEST_DESCRIPTION("Create a secondary command buffer and record a CmdClearAttachments call into it");
18010 ASSERT_NO_FATAL_FAILURE(InitState());
18011 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18012
18013 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18014 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18015 command_buffer_allocate_info.commandPool = m_commandPool;
18016 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18017 command_buffer_allocate_info.commandBufferCount = 1;
18018
18019 VkCommandBuffer secondary_command_buffer;
18020 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18021 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18022 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18023 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18024 command_buffer_inheritance_info.renderPass = m_renderPass;
18025 command_buffer_inheritance_info.framebuffer = m_framebuffer;
18026
18027 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18028 command_buffer_begin_info.flags =
18029 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
18030 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18031
18032 vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18033 VkClearAttachment color_attachment;
18034 color_attachment.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18035 color_attachment.clearValue.color.float32[0] = 0;
18036 color_attachment.clearValue.color.float32[1] = 0;
18037 color_attachment.clearValue.color.float32[2] = 0;
18038 color_attachment.clearValue.color.float32[3] = 0;
18039 color_attachment.colorAttachment = 0;
18040 VkClearRect clear_rect = {{{0, 0}, {32, 32}}};
18041 vkCmdClearAttachments(secondary_command_buffer, 1, &color_attachment, 1, &clear_rect);
18042}
18043
Tobin Ehlise0006882016-11-03 10:14:28 -060018044TEST_F(VkPositiveLayerTest, SecondaryCommandBufferImageLayoutTransitions) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018045 TEST_DESCRIPTION(
18046 "Perform an image layout transition in a secondary command buffer followed "
18047 "by a transition in the primary.");
Tobin Ehlise0006882016-11-03 10:14:28 -060018048 VkResult err;
18049 m_errorMonitor->ExpectSuccess();
18050 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070018051 auto depth_format = find_depth_stencil_format(m_device);
18052 if (!depth_format) {
18053 return;
18054 }
Tobin Ehlise0006882016-11-03 10:14:28 -060018055 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
18056 // Allocate a secondary and primary cmd buffer
18057 VkCommandBufferAllocateInfo command_buffer_allocate_info = {};
18058 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18059 command_buffer_allocate_info.commandPool = m_commandPool;
18060 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
18061 command_buffer_allocate_info.commandBufferCount = 1;
18062
18063 VkCommandBuffer secondary_command_buffer;
18064 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer));
18065 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18066 VkCommandBuffer primary_command_buffer;
18067 ASSERT_VK_SUCCESS(vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &primary_command_buffer));
18068 VkCommandBufferBeginInfo command_buffer_begin_info = {};
18069 VkCommandBufferInheritanceInfo command_buffer_inheritance_info = {};
18070 command_buffer_inheritance_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
18071 command_buffer_begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18072 command_buffer_begin_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
18073 command_buffer_begin_info.pInheritanceInfo = &command_buffer_inheritance_info;
18074
18075 err = vkBeginCommandBuffer(secondary_command_buffer, &command_buffer_begin_info);
18076 ASSERT_VK_SUCCESS(err);
18077 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070018078 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 -060018079 ASSERT_TRUE(image.initialized());
18080 VkImageMemoryBarrier img_barrier = {};
18081 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18082 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18083 img_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18084 img_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
18085 img_barrier.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18086 img_barrier.image = image.handle();
18087 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18088 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18089 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18090 img_barrier.subresourceRange.baseArrayLayer = 0;
18091 img_barrier.subresourceRange.baseMipLevel = 0;
18092 img_barrier.subresourceRange.layerCount = 1;
18093 img_barrier.subresourceRange.levelCount = 1;
18094 vkCmdPipelineBarrier(secondary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr,
18095 0, nullptr, 1, &img_barrier);
18096 err = vkEndCommandBuffer(secondary_command_buffer);
18097 ASSERT_VK_SUCCESS(err);
18098
18099 // Now update primary cmd buffer to execute secondary and transitions image
18100 command_buffer_begin_info.pInheritanceInfo = nullptr;
18101 err = vkBeginCommandBuffer(primary_command_buffer, &command_buffer_begin_info);
18102 ASSERT_VK_SUCCESS(err);
18103 vkCmdExecuteCommands(primary_command_buffer, 1, &secondary_command_buffer);
18104 VkImageMemoryBarrier img_barrier2 = {};
18105 img_barrier2.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18106 img_barrier2.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18107 img_barrier2.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
18108 img_barrier2.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18109 img_barrier2.newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
18110 img_barrier2.image = image.handle();
18111 img_barrier2.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18112 img_barrier2.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18113 img_barrier2.subresourceRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
18114 img_barrier2.subresourceRange.baseArrayLayer = 0;
18115 img_barrier2.subresourceRange.baseMipLevel = 0;
18116 img_barrier2.subresourceRange.layerCount = 1;
18117 img_barrier2.subresourceRange.levelCount = 1;
18118 vkCmdPipelineBarrier(primary_command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, 0, 0, nullptr, 0,
18119 nullptr, 1, &img_barrier2);
18120 err = vkEndCommandBuffer(primary_command_buffer);
18121 ASSERT_VK_SUCCESS(err);
18122 VkSubmitInfo submit_info = {};
18123 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
18124 submit_info.commandBufferCount = 1;
18125 submit_info.pCommandBuffers = &primary_command_buffer;
18126 err = vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
18127 ASSERT_VK_SUCCESS(err);
18128 m_errorMonitor->VerifyNotFound();
18129 err = vkDeviceWaitIdle(m_device->device());
18130 ASSERT_VK_SUCCESS(err);
18131 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &secondary_command_buffer);
18132 vkFreeCommandBuffers(m_device->device(), m_commandPool, 1, &primary_command_buffer);
18133}
18134
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018135// This is a positive test. No failures are expected.
18136TEST_F(VkPositiveLayerTest, IgnoreUnrelatedDescriptor) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018137 TEST_DESCRIPTION(
18138 "Ensure that the vkUpdateDescriptorSets validation code "
18139 "is ignoring VkWriteDescriptorSet members that are not "
18140 "related to the descriptor type specified by "
18141 "VkWriteDescriptorSet::descriptorType. Correct "
18142 "validation behavior will result in the test running to "
18143 "completion without validation errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018144
18145 const uintptr_t invalid_ptr = 0xcdcdcdcd;
18146
18147 ASSERT_NO_FATAL_FAILURE(InitState());
18148
18149 // Image Case
18150 {
18151 m_errorMonitor->ExpectSuccess();
18152
18153 VkImage image;
18154 const VkFormat tex_format = VK_FORMAT_B8G8R8A8_UNORM;
18155 const int32_t tex_width = 32;
18156 const int32_t tex_height = 32;
18157 VkImageCreateInfo image_create_info = {};
18158 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18159 image_create_info.pNext = NULL;
18160 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18161 image_create_info.format = tex_format;
18162 image_create_info.extent.width = tex_width;
18163 image_create_info.extent.height = tex_height;
18164 image_create_info.extent.depth = 1;
18165 image_create_info.mipLevels = 1;
18166 image_create_info.arrayLayers = 1;
18167 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
18168 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
18169 image_create_info.usage = VK_IMAGE_USAGE_SAMPLED_BIT;
18170 image_create_info.flags = 0;
18171 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18172 ASSERT_VK_SUCCESS(err);
18173
18174 VkMemoryRequirements memory_reqs;
18175 VkDeviceMemory image_memory;
18176 bool pass;
18177 VkMemoryAllocateInfo memory_info = {};
18178 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18179 memory_info.pNext = NULL;
18180 memory_info.allocationSize = 0;
18181 memory_info.memoryTypeIndex = 0;
18182 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
18183 memory_info.allocationSize = memory_reqs.size;
18184 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18185 ASSERT_TRUE(pass);
18186 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &image_memory);
18187 ASSERT_VK_SUCCESS(err);
18188 err = vkBindImageMemory(m_device->device(), image, image_memory, 0);
18189 ASSERT_VK_SUCCESS(err);
18190
18191 VkImageViewCreateInfo image_view_create_info = {};
18192 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
18193 image_view_create_info.image = image;
18194 image_view_create_info.viewType = VK_IMAGE_VIEW_TYPE_2D;
18195 image_view_create_info.format = tex_format;
18196 image_view_create_info.subresourceRange.layerCount = 1;
18197 image_view_create_info.subresourceRange.baseMipLevel = 0;
18198 image_view_create_info.subresourceRange.levelCount = 1;
18199 image_view_create_info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18200
18201 VkImageView view;
18202 err = vkCreateImageView(m_device->device(), &image_view_create_info, NULL, &view);
18203 ASSERT_VK_SUCCESS(err);
18204
18205 VkDescriptorPoolSize ds_type_count = {};
18206 ds_type_count.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18207 ds_type_count.descriptorCount = 1;
18208
18209 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18210 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18211 ds_pool_ci.pNext = NULL;
18212 ds_pool_ci.maxSets = 1;
18213 ds_pool_ci.poolSizeCount = 1;
18214 ds_pool_ci.pPoolSizes = &ds_type_count;
18215
18216 VkDescriptorPool ds_pool;
18217 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18218 ASSERT_VK_SUCCESS(err);
18219
18220 VkDescriptorSetLayoutBinding dsl_binding = {};
18221 dsl_binding.binding = 0;
18222 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18223 dsl_binding.descriptorCount = 1;
18224 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18225 dsl_binding.pImmutableSamplers = NULL;
18226
18227 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18228 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18229 ds_layout_ci.pNext = NULL;
18230 ds_layout_ci.bindingCount = 1;
18231 ds_layout_ci.pBindings = &dsl_binding;
18232 VkDescriptorSetLayout ds_layout;
18233 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18234 ASSERT_VK_SUCCESS(err);
18235
18236 VkDescriptorSet descriptor_set;
18237 VkDescriptorSetAllocateInfo alloc_info = {};
18238 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18239 alloc_info.descriptorSetCount = 1;
18240 alloc_info.descriptorPool = ds_pool;
18241 alloc_info.pSetLayouts = &ds_layout;
18242 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18243 ASSERT_VK_SUCCESS(err);
18244
18245 VkDescriptorImageInfo image_info = {};
18246 image_info.imageView = view;
18247 image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
18248
18249 VkWriteDescriptorSet descriptor_write;
18250 memset(&descriptor_write, 0, sizeof(descriptor_write));
18251 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18252 descriptor_write.dstSet = descriptor_set;
18253 descriptor_write.dstBinding = 0;
18254 descriptor_write.descriptorCount = 1;
18255 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE;
18256 descriptor_write.pImageInfo = &image_info;
18257
18258 // Set pBufferInfo and pTexelBufferView to invalid values, which should
18259 // be
18260 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE.
18261 // This will most likely produce a crash if the parameter_validation
18262 // layer
18263 // does not correctly ignore pBufferInfo.
18264 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18265 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18266
18267 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18268
18269 m_errorMonitor->VerifyNotFound();
18270
18271 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18272 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18273 vkDestroyImageView(m_device->device(), view, NULL);
18274 vkDestroyImage(m_device->device(), image, NULL);
18275 vkFreeMemory(m_device->device(), image_memory, NULL);
18276 }
18277
18278 // Buffer Case
18279 {
18280 m_errorMonitor->ExpectSuccess();
18281
18282 VkBuffer buffer;
18283 uint32_t queue_family_index = 0;
18284 VkBufferCreateInfo buffer_create_info = {};
18285 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18286 buffer_create_info.size = 1024;
18287 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18288 buffer_create_info.queueFamilyIndexCount = 1;
18289 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18290
18291 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18292 ASSERT_VK_SUCCESS(err);
18293
18294 VkMemoryRequirements memory_reqs;
18295 VkDeviceMemory buffer_memory;
18296 bool pass;
18297 VkMemoryAllocateInfo memory_info = {};
18298 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18299 memory_info.pNext = NULL;
18300 memory_info.allocationSize = 0;
18301 memory_info.memoryTypeIndex = 0;
18302
18303 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18304 memory_info.allocationSize = memory_reqs.size;
18305 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18306 ASSERT_TRUE(pass);
18307
18308 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18309 ASSERT_VK_SUCCESS(err);
18310 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18311 ASSERT_VK_SUCCESS(err);
18312
18313 VkDescriptorPoolSize ds_type_count = {};
18314 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18315 ds_type_count.descriptorCount = 1;
18316
18317 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18318 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18319 ds_pool_ci.pNext = NULL;
18320 ds_pool_ci.maxSets = 1;
18321 ds_pool_ci.poolSizeCount = 1;
18322 ds_pool_ci.pPoolSizes = &ds_type_count;
18323
18324 VkDescriptorPool ds_pool;
18325 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18326 ASSERT_VK_SUCCESS(err);
18327
18328 VkDescriptorSetLayoutBinding dsl_binding = {};
18329 dsl_binding.binding = 0;
18330 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18331 dsl_binding.descriptorCount = 1;
18332 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18333 dsl_binding.pImmutableSamplers = NULL;
18334
18335 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18336 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18337 ds_layout_ci.pNext = NULL;
18338 ds_layout_ci.bindingCount = 1;
18339 ds_layout_ci.pBindings = &dsl_binding;
18340 VkDescriptorSetLayout ds_layout;
18341 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18342 ASSERT_VK_SUCCESS(err);
18343
18344 VkDescriptorSet descriptor_set;
18345 VkDescriptorSetAllocateInfo alloc_info = {};
18346 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18347 alloc_info.descriptorSetCount = 1;
18348 alloc_info.descriptorPool = ds_pool;
18349 alloc_info.pSetLayouts = &ds_layout;
18350 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18351 ASSERT_VK_SUCCESS(err);
18352
18353 VkDescriptorBufferInfo buffer_info = {};
18354 buffer_info.buffer = buffer;
18355 buffer_info.offset = 0;
18356 buffer_info.range = 1024;
18357
18358 VkWriteDescriptorSet descriptor_write;
18359 memset(&descriptor_write, 0, sizeof(descriptor_write));
18360 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18361 descriptor_write.dstSet = descriptor_set;
18362 descriptor_write.dstBinding = 0;
18363 descriptor_write.descriptorCount = 1;
18364 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18365 descriptor_write.pBufferInfo = &buffer_info;
18366
18367 // Set pImageInfo and pTexelBufferView to invalid values, which should
18368 // be
18369 // ignored for descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER.
18370 // This will most likely produce a crash if the parameter_validation
18371 // layer
18372 // does not correctly ignore pImageInfo.
18373 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18374 descriptor_write.pTexelBufferView = reinterpret_cast<const VkBufferView *>(invalid_ptr);
18375
18376 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18377
18378 m_errorMonitor->VerifyNotFound();
18379
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018380 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18381 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18382 vkDestroyBuffer(m_device->device(), buffer, NULL);
18383 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18384 }
18385
18386 // Texel Buffer Case
18387 {
18388 m_errorMonitor->ExpectSuccess();
18389
18390 VkBuffer buffer;
18391 uint32_t queue_family_index = 0;
18392 VkBufferCreateInfo buffer_create_info = {};
18393 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18394 buffer_create_info.size = 1024;
18395 buffer_create_info.usage = VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT;
18396 buffer_create_info.queueFamilyIndexCount = 1;
18397 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
18398
18399 VkResult err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
18400 ASSERT_VK_SUCCESS(err);
18401
18402 VkMemoryRequirements memory_reqs;
18403 VkDeviceMemory buffer_memory;
18404 bool pass;
18405 VkMemoryAllocateInfo memory_info = {};
18406 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18407 memory_info.pNext = NULL;
18408 memory_info.allocationSize = 0;
18409 memory_info.memoryTypeIndex = 0;
18410
18411 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
18412 memory_info.allocationSize = memory_reqs.size;
18413 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
18414 ASSERT_TRUE(pass);
18415
18416 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
18417 ASSERT_VK_SUCCESS(err);
18418 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
18419 ASSERT_VK_SUCCESS(err);
18420
18421 VkBufferViewCreateInfo buff_view_ci = {};
18422 buff_view_ci.sType = VK_STRUCTURE_TYPE_BUFFER_VIEW_CREATE_INFO;
18423 buff_view_ci.buffer = buffer;
18424 buff_view_ci.format = VK_FORMAT_R8_UNORM;
18425 buff_view_ci.range = VK_WHOLE_SIZE;
18426 VkBufferView buffer_view;
18427 err = vkCreateBufferView(m_device->device(), &buff_view_ci, NULL, &buffer_view);
18428
18429 VkDescriptorPoolSize ds_type_count = {};
18430 ds_type_count.type = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18431 ds_type_count.descriptorCount = 1;
18432
18433 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18434 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18435 ds_pool_ci.pNext = NULL;
18436 ds_pool_ci.maxSets = 1;
18437 ds_pool_ci.poolSizeCount = 1;
18438 ds_pool_ci.pPoolSizes = &ds_type_count;
18439
18440 VkDescriptorPool ds_pool;
18441 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18442 ASSERT_VK_SUCCESS(err);
18443
18444 VkDescriptorSetLayoutBinding dsl_binding = {};
18445 dsl_binding.binding = 0;
18446 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18447 dsl_binding.descriptorCount = 1;
18448 dsl_binding.stageFlags = VK_SHADER_STAGE_ALL;
18449 dsl_binding.pImmutableSamplers = NULL;
18450
18451 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18452 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18453 ds_layout_ci.pNext = NULL;
18454 ds_layout_ci.bindingCount = 1;
18455 ds_layout_ci.pBindings = &dsl_binding;
18456 VkDescriptorSetLayout ds_layout;
18457 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18458 ASSERT_VK_SUCCESS(err);
18459
18460 VkDescriptorSet descriptor_set;
18461 VkDescriptorSetAllocateInfo alloc_info = {};
18462 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18463 alloc_info.descriptorSetCount = 1;
18464 alloc_info.descriptorPool = ds_pool;
18465 alloc_info.pSetLayouts = &ds_layout;
18466 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18467 ASSERT_VK_SUCCESS(err);
18468
18469 VkWriteDescriptorSet descriptor_write;
18470 memset(&descriptor_write, 0, sizeof(descriptor_write));
18471 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18472 descriptor_write.dstSet = descriptor_set;
18473 descriptor_write.dstBinding = 0;
18474 descriptor_write.descriptorCount = 1;
18475 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
18476 descriptor_write.pTexelBufferView = &buffer_view;
18477
18478 // Set pImageInfo and pBufferInfo to invalid values, which should be
18479 // ignored for descriptorType ==
18480 // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER.
18481 // This will most likely produce a crash if the parameter_validation
18482 // layer
18483 // does not correctly ignore pImageInfo and pBufferInfo.
18484 descriptor_write.pImageInfo = reinterpret_cast<const VkDescriptorImageInfo *>(invalid_ptr);
18485 descriptor_write.pBufferInfo = reinterpret_cast<const VkDescriptorBufferInfo *>(invalid_ptr);
18486
18487 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18488
18489 m_errorMonitor->VerifyNotFound();
18490
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018491 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18492 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18493 vkDestroyBufferView(m_device->device(), buffer_view, NULL);
18494 vkDestroyBuffer(m_device->device(), buffer, NULL);
18495 vkFreeMemory(m_device->device(), buffer_memory, NULL);
18496 }
18497}
18498
Tobin Ehlisf7428442016-10-25 07:58:24 -060018499TEST_F(VkLayerTest, DuplicateDescriptorBinding) {
18500 TEST_DESCRIPTION("Create a descriptor set layout with a duplicate binding number.");
18501
18502 ASSERT_NO_FATAL_FAILURE(InitState());
18503 // Create layout where two binding #s are "1"
18504 static const uint32_t NUM_BINDINGS = 3;
18505 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18506 dsl_binding[0].binding = 1;
18507 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18508 dsl_binding[0].descriptorCount = 1;
18509 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18510 dsl_binding[0].pImmutableSamplers = NULL;
18511 dsl_binding[1].binding = 0;
18512 dsl_binding[1].descriptorCount = 1;
18513 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18514 dsl_binding[1].descriptorCount = 1;
18515 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18516 dsl_binding[1].pImmutableSamplers = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018517 dsl_binding[2].binding = 1; // Duplicate binding should cause error
Tobin Ehlisf7428442016-10-25 07:58:24 -060018518 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18519 dsl_binding[2].descriptorCount = 1;
18520 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18521 dsl_binding[2].pImmutableSamplers = NULL;
18522
18523 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18524 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18525 ds_layout_ci.pNext = NULL;
18526 ds_layout_ci.bindingCount = NUM_BINDINGS;
18527 ds_layout_ci.pBindings = dsl_binding;
18528 VkDescriptorSetLayout ds_layout;
18529 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_02345);
18530 vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18531 m_errorMonitor->VerifyFound();
18532}
18533
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018534TEST_F(VkLayerTest, ViewportAndScissorBoundsChecking) {
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018535 TEST_DESCRIPTION("Verify errors are detected on misuse of SetViewport and SetScissor.");
18536
18537 ASSERT_NO_FATAL_FAILURE(InitState());
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018538
Tony Barbour552f6c02016-12-21 14:34:07 -070018539 m_commandBuffer->BeginCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018540
Mike Weiblen9a0f55d2016-10-31 22:35:00 -060018541 const VkPhysicalDeviceLimits &limits = m_device->props.limits;
18542
18543 {
18544 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01448);
18545 VkViewport viewport = {0, 0, static_cast<float>(limits.maxViewportDimensions[0] + 1), 16, 0, 1};
18546 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18547 m_errorMonitor->VerifyFound();
18548 }
18549
18550 {
18551 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01449);
18552 VkViewport viewport = {0, 0, 16, static_cast<float>(limits.maxViewportDimensions[1] + 1), 0, 1};
18553 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18554 m_errorMonitor->VerifyFound();
18555 }
18556
18557 {
18558 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18559 VkViewport viewport = {limits.viewportBoundsRange[0] - 1, 0, 16, 16, 0, 1};
18560 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18561 m_errorMonitor->VerifyFound();
18562 }
18563
18564 {
18565 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01450);
18566 VkViewport viewport = {0, limits.viewportBoundsRange[0] - 1, 16, 16, 0, 1};
18567 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18568 m_errorMonitor->VerifyFound();
18569 }
18570
18571 {
18572 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01451);
18573 VkViewport viewport = {limits.viewportBoundsRange[1], 0, 16, 16, 0, 1};
18574 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18575 m_errorMonitor->VerifyFound();
18576 }
18577
18578 {
18579 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01452);
18580 VkViewport viewport = {0, limits.viewportBoundsRange[1], 16, 16, 0, 1};
18581 vkCmdSetViewport(m_commandBuffer->handle(), 0, 1, &viewport);
18582 m_errorMonitor->VerifyFound();
18583 }
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018584
18585 {
18586 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18587 VkRect2D scissor = {{-1, 0}, {16, 16}};
18588 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18589 m_errorMonitor->VerifyFound();
18590 }
18591
18592 {
18593 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01489);
18594 VkRect2D scissor = {{0, -2}, {16, 16}};
18595 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18596 m_errorMonitor->VerifyFound();
18597 }
18598
18599 {
18600 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01490);
18601 VkRect2D scissor = {{100, 100}, {INT_MAX, 16}};
18602 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18603 m_errorMonitor->VerifyFound();
18604 }
18605
18606 {
18607 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT, VALIDATION_ERROR_01491);
18608 VkRect2D scissor = {{100, 100}, {16, INT_MAX}};
18609 vkCmdSetScissor(m_commandBuffer->handle(), 0, 1, &scissor);
18610 m_errorMonitor->VerifyFound();
18611 }
18612
Tony Barbour552f6c02016-12-21 14:34:07 -070018613 m_commandBuffer->EndCommandBuffer();
Mike Weiblen4e5d39b2016-10-31 14:42:01 -060018614}
18615
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018616// This is a positive test. No failures are expected.
18617TEST_F(VkPositiveLayerTest, EmptyDescriptorUpdateTest) {
18618 TEST_DESCRIPTION("Update last descriptor in a set that includes an empty binding");
18619 VkResult err;
18620
18621 ASSERT_NO_FATAL_FAILURE(InitState());
18622 m_errorMonitor->ExpectSuccess();
18623 VkDescriptorPoolSize ds_type_count = {};
18624 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18625 ds_type_count.descriptorCount = 2;
18626
18627 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18628 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18629 ds_pool_ci.pNext = NULL;
18630 ds_pool_ci.maxSets = 1;
18631 ds_pool_ci.poolSizeCount = 1;
18632 ds_pool_ci.pPoolSizes = &ds_type_count;
18633
18634 VkDescriptorPool ds_pool;
18635 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18636 ASSERT_VK_SUCCESS(err);
18637
18638 // Create layout with two uniform buffer descriptors w/ empty binding between them
18639 static const uint32_t NUM_BINDINGS = 3;
18640 VkDescriptorSetLayoutBinding dsl_binding[NUM_BINDINGS] = {};
18641 dsl_binding[0].binding = 0;
18642 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18643 dsl_binding[0].descriptorCount = 1;
18644 dsl_binding[0].stageFlags = VK_SHADER_STAGE_ALL;
18645 dsl_binding[0].pImmutableSamplers = NULL;
18646 dsl_binding[1].binding = 1;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018647 dsl_binding[1].descriptorCount = 0; // empty binding
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018648 dsl_binding[2].binding = 2;
18649 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18650 dsl_binding[2].descriptorCount = 1;
18651 dsl_binding[2].stageFlags = VK_SHADER_STAGE_ALL;
18652 dsl_binding[2].pImmutableSamplers = NULL;
18653
18654 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18655 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18656 ds_layout_ci.pNext = NULL;
18657 ds_layout_ci.bindingCount = NUM_BINDINGS;
18658 ds_layout_ci.pBindings = dsl_binding;
18659 VkDescriptorSetLayout ds_layout;
18660 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18661 ASSERT_VK_SUCCESS(err);
18662
18663 VkDescriptorSet descriptor_set = {};
18664 VkDescriptorSetAllocateInfo alloc_info = {};
18665 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18666 alloc_info.descriptorSetCount = 1;
18667 alloc_info.descriptorPool = ds_pool;
18668 alloc_info.pSetLayouts = &ds_layout;
18669 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
18670 ASSERT_VK_SUCCESS(err);
18671
18672 // Create a buffer to be used for update
18673 VkBufferCreateInfo buff_ci = {};
18674 buff_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18675 buff_ci.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18676 buff_ci.size = 256;
18677 buff_ci.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18678 VkBuffer buffer;
18679 err = vkCreateBuffer(m_device->device(), &buff_ci, NULL, &buffer);
18680 ASSERT_VK_SUCCESS(err);
18681 // Have to bind memory to buffer before descriptor update
18682 VkMemoryAllocateInfo mem_alloc = {};
18683 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18684 mem_alloc.pNext = NULL;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018685 mem_alloc.allocationSize = 512; // one allocation for both buffers
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018686 mem_alloc.memoryTypeIndex = 0;
18687
18688 VkMemoryRequirements mem_reqs;
18689 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18690 bool pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, 0);
18691 if (!pass) {
18692 vkDestroyBuffer(m_device->device(), buffer, NULL);
18693 return;
18694 }
18695
18696 VkDeviceMemory mem;
18697 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
18698 ASSERT_VK_SUCCESS(err);
18699 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18700 ASSERT_VK_SUCCESS(err);
18701
18702 // Only update the descriptor at binding 2
18703 VkDescriptorBufferInfo buff_info = {};
18704 buff_info.buffer = buffer;
18705 buff_info.offset = 0;
18706 buff_info.range = VK_WHOLE_SIZE;
18707 VkWriteDescriptorSet descriptor_write = {};
18708 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
18709 descriptor_write.dstBinding = 2;
18710 descriptor_write.descriptorCount = 1;
18711 descriptor_write.pTexelBufferView = nullptr;
18712 descriptor_write.pBufferInfo = &buff_info;
18713 descriptor_write.pImageInfo = nullptr;
18714 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
18715 descriptor_write.dstSet = descriptor_set;
18716
18717 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
18718
18719 m_errorMonitor->VerifyNotFound();
18720 // Cleanup
18721 vkFreeMemory(m_device->device(), mem, NULL);
18722 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18723 vkDestroyBuffer(m_device->device(), buffer, NULL);
18724 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18725}
18726
18727// This is a positive test. No failures are expected.
18728TEST_F(VkPositiveLayerTest, TestAliasedMemoryTracking) {
18729 VkResult err;
18730 bool pass;
18731
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070018732 TEST_DESCRIPTION(
18733 "Create a buffer, allocate memory, bind memory, destroy "
18734 "the buffer, create an image, and bind the same memory to "
18735 "it");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018736
18737 m_errorMonitor->ExpectSuccess();
18738
18739 ASSERT_NO_FATAL_FAILURE(InitState());
18740
18741 VkBuffer buffer;
18742 VkImage image;
18743 VkDeviceMemory mem;
18744 VkMemoryRequirements mem_reqs;
18745
18746 VkBufferCreateInfo buf_info = {};
18747 buf_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
18748 buf_info.pNext = NULL;
18749 buf_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
18750 buf_info.size = 256;
18751 buf_info.queueFamilyIndexCount = 0;
18752 buf_info.pQueueFamilyIndices = NULL;
18753 buf_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18754 buf_info.flags = 0;
18755 err = vkCreateBuffer(m_device->device(), &buf_info, NULL, &buffer);
18756 ASSERT_VK_SUCCESS(err);
18757
18758 vkGetBufferMemoryRequirements(m_device->device(), buffer, &mem_reqs);
18759
18760 VkMemoryAllocateInfo alloc_info = {};
18761 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18762 alloc_info.pNext = NULL;
18763 alloc_info.memoryTypeIndex = 0;
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018764
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018765 // Ensure memory is big enough for both bindings
18766 alloc_info.allocationSize = 0x10000;
18767
18768 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18769 if (!pass) {
18770 vkDestroyBuffer(m_device->device(), buffer, NULL);
18771 return;
18772 }
18773
18774 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
18775 ASSERT_VK_SUCCESS(err);
18776
18777 uint8_t *pData;
18778 err = vkMapMemory(m_device->device(), mem, 0, mem_reqs.size, 0, (void **)&pData);
18779 ASSERT_VK_SUCCESS(err);
18780
18781 memset(pData, 0xCADECADE, static_cast<size_t>(mem_reqs.size));
18782
18783 vkUnmapMemory(m_device->device(), mem);
18784
18785 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
18786 ASSERT_VK_SUCCESS(err);
18787
18788 // NOW, destroy the buffer. Obviously, the resource no longer occupies this
18789 // memory. In fact, it was never used by the GPU.
18790 // Just be be sure, wait for idle.
18791 vkDestroyBuffer(m_device->device(), buffer, NULL);
18792 vkDeviceWaitIdle(m_device->device());
18793
Tobin Ehlis6a005702016-12-28 15:25:56 -070018794 // Use optimal as some platforms report linear support but then fail image creation
18795 VkImageTiling image_tiling = VK_IMAGE_TILING_OPTIMAL;
18796 VkImageFormatProperties image_format_properties;
18797 vkGetPhysicalDeviceImageFormatProperties(gpu(), VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TYPE_2D, image_tiling,
18798 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0, &image_format_properties);
18799 if (image_format_properties.maxExtent.width == 0) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070018800 printf(" Image format not supported; skipped.\n");
Tobin Ehlis6a005702016-12-28 15:25:56 -070018801 vkFreeMemory(m_device->device(), mem, NULL);
18802 return;
18803 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018804 VkImageCreateInfo image_create_info = {};
18805 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
18806 image_create_info.pNext = NULL;
18807 image_create_info.imageType = VK_IMAGE_TYPE_2D;
18808 image_create_info.format = VK_FORMAT_R8G8B8A8_UNORM;
18809 image_create_info.extent.width = 64;
18810 image_create_info.extent.height = 64;
18811 image_create_info.extent.depth = 1;
18812 image_create_info.mipLevels = 1;
18813 image_create_info.arrayLayers = 1;
18814 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
Tobin Ehlis6a005702016-12-28 15:25:56 -070018815 image_create_info.tiling = image_tiling;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018816 image_create_info.initialLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
18817 image_create_info.usage = VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
18818 image_create_info.queueFamilyIndexCount = 0;
18819 image_create_info.pQueueFamilyIndices = NULL;
18820 image_create_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
18821 image_create_info.flags = 0;
18822
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018823 /* Create a mappable image. It will be the texture if linear images are ok
Dave Houlton9dae7ec2017-03-01 16:23:25 -070018824 * to be textures or it will be the staging image if they are not.
18825 */
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018826 err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
18827 ASSERT_VK_SUCCESS(err);
18828
18829 vkGetImageMemoryRequirements(m_device->device(), image, &mem_reqs);
18830
Tobin Ehlis6a005702016-12-28 15:25:56 -070018831 VkMemoryAllocateInfo mem_alloc = {};
18832 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
18833 mem_alloc.pNext = NULL;
18834 mem_alloc.allocationSize = 0;
18835 mem_alloc.memoryTypeIndex = 0;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018836 mem_alloc.allocationSize = mem_reqs.size;
18837
18838 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &mem_alloc, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
18839 if (!pass) {
Tobin Ehlis6a005702016-12-28 15:25:56 -070018840 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018841 vkDestroyImage(m_device->device(), image, NULL);
18842 return;
18843 }
18844
18845 // VALIDATION FAILURE:
18846 err = vkBindImageMemory(m_device->device(), image, mem, 0);
18847 ASSERT_VK_SUCCESS(err);
18848
18849 m_errorMonitor->VerifyNotFound();
18850
18851 vkFreeMemory(m_device->device(), mem, NULL);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060018852 vkDestroyImage(m_device->device(), image, NULL);
18853}
18854
Tony Barbourab713912017-02-02 14:17:35 -070018855// This is a positive test. No failures are expected.
18856TEST_F(VkPositiveLayerTest, TestDestroyFreeNullHandles) {
18857 VkResult err;
18858
18859 TEST_DESCRIPTION(
18860 "Call all applicable destroy and free routines with NULL"
18861 "handles, expecting no validation errors");
18862
18863 m_errorMonitor->ExpectSuccess();
18864
18865 ASSERT_NO_FATAL_FAILURE(InitState());
18866 vkDestroyBuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18867 vkDestroyBufferView(m_device->device(), VK_NULL_HANDLE, NULL);
18868 vkDestroyCommandPool(m_device->device(), VK_NULL_HANDLE, NULL);
18869 vkDestroyDescriptorPool(m_device->device(), VK_NULL_HANDLE, NULL);
18870 vkDestroyDescriptorSetLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18871 vkDestroyDevice(VK_NULL_HANDLE, NULL);
18872 vkDestroyEvent(m_device->device(), VK_NULL_HANDLE, NULL);
18873 vkDestroyFence(m_device->device(), VK_NULL_HANDLE, NULL);
18874 vkDestroyFramebuffer(m_device->device(), VK_NULL_HANDLE, NULL);
18875 vkDestroyImage(m_device->device(), VK_NULL_HANDLE, NULL);
18876 vkDestroyImageView(m_device->device(), VK_NULL_HANDLE, NULL);
18877 vkDestroyInstance(VK_NULL_HANDLE, NULL);
18878 vkDestroyPipeline(m_device->device(), VK_NULL_HANDLE, NULL);
18879 vkDestroyPipelineCache(m_device->device(), VK_NULL_HANDLE, NULL);
18880 vkDestroyPipelineLayout(m_device->device(), VK_NULL_HANDLE, NULL);
18881 vkDestroyQueryPool(m_device->device(), VK_NULL_HANDLE, NULL);
18882 vkDestroyRenderPass(m_device->device(), VK_NULL_HANDLE, NULL);
18883 vkDestroySampler(m_device->device(), VK_NULL_HANDLE, NULL);
18884 vkDestroySemaphore(m_device->device(), VK_NULL_HANDLE, NULL);
18885 vkDestroyShaderModule(m_device->device(), VK_NULL_HANDLE, NULL);
18886
18887 VkCommandPool command_pool;
18888 VkCommandPoolCreateInfo pool_create_info{};
18889 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
18890 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
18891 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
18892 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
18893 VkCommandBuffer command_buffers[3] = {};
18894 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
18895 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18896 command_buffer_allocate_info.commandPool = command_pool;
18897 command_buffer_allocate_info.commandBufferCount = 1;
18898 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18899 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffers[1]);
18900 vkFreeCommandBuffers(m_device->device(), command_pool, 3, command_buffers);
18901 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
18902
18903 VkDescriptorPoolSize ds_type_count = {};
18904 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18905 ds_type_count.descriptorCount = 1;
18906
18907 VkDescriptorPoolCreateInfo ds_pool_ci = {};
18908 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
18909 ds_pool_ci.pNext = NULL;
18910 ds_pool_ci.maxSets = 1;
18911 ds_pool_ci.poolSizeCount = 1;
18912 ds_pool_ci.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
18913 ds_pool_ci.pPoolSizes = &ds_type_count;
18914
18915 VkDescriptorPool ds_pool;
18916 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
18917 ASSERT_VK_SUCCESS(err);
18918
18919 VkDescriptorSetLayoutBinding dsl_binding = {};
18920 dsl_binding.binding = 2;
18921 dsl_binding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
18922 dsl_binding.descriptorCount = 1;
18923 dsl_binding.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
18924 dsl_binding.pImmutableSamplers = NULL;
18925 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
18926 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
18927 ds_layout_ci.pNext = NULL;
18928 ds_layout_ci.bindingCount = 1;
18929 ds_layout_ci.pBindings = &dsl_binding;
18930 VkDescriptorSetLayout ds_layout;
18931 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
18932 ASSERT_VK_SUCCESS(err);
18933
18934 VkDescriptorSet descriptor_sets[3] = {};
18935 VkDescriptorSetAllocateInfo alloc_info = {};
18936 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
18937 alloc_info.descriptorSetCount = 1;
18938 alloc_info.descriptorPool = ds_pool;
18939 alloc_info.pSetLayouts = &ds_layout;
18940 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_sets[1]);
18941 ASSERT_VK_SUCCESS(err);
18942 vkFreeDescriptorSets(m_device->device(), ds_pool, 3, descriptor_sets);
18943 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
18944 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
18945
18946 vkFreeMemory(m_device->device(), VK_NULL_HANDLE, NULL);
18947
18948 m_errorMonitor->VerifyNotFound();
18949}
18950
Tony Barbour626994c2017-02-08 15:29:37 -070018951TEST_F(VkPositiveLayerTest, QueueSubmitSemaphoresAndLayoutTracking) {
Tony Barboure0c5cc92017-02-08 13:53:39 -070018952 TEST_DESCRIPTION("Submit multiple command buffers with chained semaphore signals and layout transitions");
Tony Barbour626994c2017-02-08 15:29:37 -070018953
18954 m_errorMonitor->ExpectSuccess();
18955
18956 ASSERT_NO_FATAL_FAILURE(InitState());
18957 VkCommandBuffer cmd_bufs[4];
18958 VkCommandBufferAllocateInfo alloc_info;
18959 alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
18960 alloc_info.pNext = NULL;
18961 alloc_info.commandBufferCount = 4;
18962 alloc_info.commandPool = m_commandPool;
18963 alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
18964 vkAllocateCommandBuffers(m_device->device(), &alloc_info, cmd_bufs);
18965 VkImageObj image(m_device);
18966 image.init(128, 128, VK_FORMAT_B8G8R8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
18967 ASSERT_TRUE(image.initialized());
18968 VkCommandBufferBeginInfo cb_binfo;
18969 cb_binfo.pNext = NULL;
18970 cb_binfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
18971 cb_binfo.pInheritanceInfo = VK_NULL_HANDLE;
18972 cb_binfo.flags = 0;
18973 // Use 4 command buffers, each with an image layout transition, ColorAO->General->ColorAO->TransferSrc->TransferDst
18974 vkBeginCommandBuffer(cmd_bufs[0], &cb_binfo);
18975 VkImageMemoryBarrier img_barrier = {};
18976 img_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
18977 img_barrier.pNext = NULL;
18978 img_barrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18979 img_barrier.dstAccessMask = VK_ACCESS_HOST_WRITE_BIT;
18980 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18981 img_barrier.newLayout = VK_IMAGE_LAYOUT_GENERAL;
18982 img_barrier.image = image.handle();
18983 img_barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18984 img_barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
18985 img_barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
18986 img_barrier.subresourceRange.baseArrayLayer = 0;
18987 img_barrier.subresourceRange.baseMipLevel = 0;
18988 img_barrier.subresourceRange.layerCount = 1;
18989 img_barrier.subresourceRange.levelCount = 1;
18990 vkCmdPipelineBarrier(cmd_bufs[0], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18991 &img_barrier);
18992 vkEndCommandBuffer(cmd_bufs[0]);
18993 vkBeginCommandBuffer(cmd_bufs[1], &cb_binfo);
18994 img_barrier.oldLayout = VK_IMAGE_LAYOUT_GENERAL;
18995 img_barrier.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
18996 vkCmdPipelineBarrier(cmd_bufs[1], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
18997 &img_barrier);
18998 vkEndCommandBuffer(cmd_bufs[1]);
18999 vkBeginCommandBuffer(cmd_bufs[2], &cb_binfo);
19000 img_barrier.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
19001 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19002 vkCmdPipelineBarrier(cmd_bufs[2], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19003 &img_barrier);
19004 vkEndCommandBuffer(cmd_bufs[2]);
19005 vkBeginCommandBuffer(cmd_bufs[3], &cb_binfo);
19006 img_barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
19007 img_barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
19008 vkCmdPipelineBarrier(cmd_bufs[3], VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 0, nullptr, 1,
19009 &img_barrier);
19010 vkEndCommandBuffer(cmd_bufs[3]);
19011
19012 // Submit 4 command buffers in 3 submits, with submits 2 and 3 waiting for semaphores from submits 1 and 2
19013 VkSemaphore semaphore1, semaphore2;
19014 VkSemaphoreCreateInfo semaphore_create_info{};
19015 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
19016 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore1);
19017 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore2);
19018 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
19019 VkSubmitInfo submit_info[3];
19020 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19021 submit_info[0].pNext = nullptr;
19022 submit_info[0].commandBufferCount = 1;
19023 submit_info[0].pCommandBuffers = &cmd_bufs[0];
19024 submit_info[0].signalSemaphoreCount = 1;
19025 submit_info[0].pSignalSemaphores = &semaphore1;
19026 submit_info[0].waitSemaphoreCount = 0;
19027 submit_info[0].pWaitDstStageMask = nullptr;
19028 submit_info[0].pWaitDstStageMask = flags;
19029 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19030 submit_info[1].pNext = nullptr;
19031 submit_info[1].commandBufferCount = 1;
19032 submit_info[1].pCommandBuffers = &cmd_bufs[1];
19033 submit_info[1].waitSemaphoreCount = 1;
19034 submit_info[1].pWaitSemaphores = &semaphore1;
19035 submit_info[1].signalSemaphoreCount = 1;
19036 submit_info[1].pSignalSemaphores = &semaphore2;
19037 submit_info[1].pWaitDstStageMask = flags;
19038 submit_info[2].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
19039 submit_info[2].pNext = nullptr;
19040 submit_info[2].commandBufferCount = 2;
19041 submit_info[2].pCommandBuffers = &cmd_bufs[2];
19042 submit_info[2].waitSemaphoreCount = 1;
19043 submit_info[2].pWaitSemaphores = &semaphore2;
19044 submit_info[2].signalSemaphoreCount = 0;
19045 submit_info[2].pSignalSemaphores = nullptr;
19046 submit_info[2].pWaitDstStageMask = flags;
19047 vkQueueSubmit(m_device->m_queue, 3, submit_info, VK_NULL_HANDLE);
19048 vkQueueWaitIdle(m_device->m_queue);
19049
19050 vkDestroySemaphore(m_device->device(), semaphore1, NULL);
19051 vkDestroySemaphore(m_device->device(), semaphore2, NULL);
19052 m_errorMonitor->VerifyNotFound();
19053}
19054
Tobin Ehlis953e8392016-11-17 10:54:13 -070019055TEST_F(VkPositiveLayerTest, DynamicOffsetWithInactiveBinding) {
19056 // Create a descriptorSet w/ dynamic descriptors where 1 binding is inactive
19057 // We previously had a bug where dynamic offset of inactive bindings was still being used
19058 VkResult err;
19059 m_errorMonitor->ExpectSuccess();
19060
19061 ASSERT_NO_FATAL_FAILURE(InitState());
19062 ASSERT_NO_FATAL_FAILURE(InitViewport());
19063 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
19064
19065 VkDescriptorPoolSize ds_type_count = {};
19066 ds_type_count.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19067 ds_type_count.descriptorCount = 3;
19068
19069 VkDescriptorPoolCreateInfo ds_pool_ci = {};
19070 ds_pool_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
19071 ds_pool_ci.pNext = NULL;
19072 ds_pool_ci.maxSets = 1;
19073 ds_pool_ci.poolSizeCount = 1;
19074 ds_pool_ci.pPoolSizes = &ds_type_count;
19075
19076 VkDescriptorPool ds_pool;
19077 err = vkCreateDescriptorPool(m_device->device(), &ds_pool_ci, NULL, &ds_pool);
19078 ASSERT_VK_SUCCESS(err);
19079
19080 const uint32_t BINDING_COUNT = 3;
19081 VkDescriptorSetLayoutBinding dsl_binding[BINDING_COUNT] = {};
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019082 dsl_binding[0].binding = 2;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019083 dsl_binding[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19084 dsl_binding[0].descriptorCount = 1;
19085 dsl_binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19086 dsl_binding[0].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019087 dsl_binding[1].binding = 0;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019088 dsl_binding[1].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19089 dsl_binding[1].descriptorCount = 1;
19090 dsl_binding[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19091 dsl_binding[1].pImmutableSamplers = NULL;
Tobin Ehlis0050fba2016-11-30 10:22:02 -070019092 dsl_binding[2].binding = 1;
Tobin Ehlis953e8392016-11-17 10:54:13 -070019093 dsl_binding[2].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19094 dsl_binding[2].descriptorCount = 1;
19095 dsl_binding[2].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
19096 dsl_binding[2].pImmutableSamplers = NULL;
19097
19098 VkDescriptorSetLayoutCreateInfo ds_layout_ci = {};
19099 ds_layout_ci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
19100 ds_layout_ci.pNext = NULL;
19101 ds_layout_ci.bindingCount = BINDING_COUNT;
19102 ds_layout_ci.pBindings = dsl_binding;
19103 VkDescriptorSetLayout ds_layout;
19104 err = vkCreateDescriptorSetLayout(m_device->device(), &ds_layout_ci, NULL, &ds_layout);
19105 ASSERT_VK_SUCCESS(err);
19106
19107 VkDescriptorSet descriptor_set;
19108 VkDescriptorSetAllocateInfo alloc_info = {};
19109 alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
19110 alloc_info.descriptorSetCount = 1;
19111 alloc_info.descriptorPool = ds_pool;
19112 alloc_info.pSetLayouts = &ds_layout;
19113 err = vkAllocateDescriptorSets(m_device->device(), &alloc_info, &descriptor_set);
19114 ASSERT_VK_SUCCESS(err);
19115
19116 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
19117 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
19118 pipeline_layout_ci.pNext = NULL;
19119 pipeline_layout_ci.setLayoutCount = 1;
19120 pipeline_layout_ci.pSetLayouts = &ds_layout;
19121
19122 VkPipelineLayout pipeline_layout;
19123 err = vkCreatePipelineLayout(m_device->device(), &pipeline_layout_ci, NULL, &pipeline_layout);
19124 ASSERT_VK_SUCCESS(err);
19125
19126 // Create two buffers to update the descriptors with
19127 // The first will be 2k and used for bindings 0 & 1, the second is 1k for binding 2
19128 uint32_t qfi = 0;
19129 VkBufferCreateInfo buffCI = {};
19130 buffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
19131 buffCI.size = 2048;
19132 buffCI.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
19133 buffCI.queueFamilyIndexCount = 1;
19134 buffCI.pQueueFamilyIndices = &qfi;
19135
19136 VkBuffer dyub1;
19137 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub1);
19138 ASSERT_VK_SUCCESS(err);
19139 // buffer2
19140 buffCI.size = 1024;
19141 VkBuffer dyub2;
19142 err = vkCreateBuffer(m_device->device(), &buffCI, NULL, &dyub2);
19143 ASSERT_VK_SUCCESS(err);
19144 // Allocate memory and bind to buffers
19145 VkMemoryAllocateInfo mem_alloc[2] = {};
19146 mem_alloc[0].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19147 mem_alloc[0].pNext = NULL;
19148 mem_alloc[0].memoryTypeIndex = 0;
19149 mem_alloc[1].sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19150 mem_alloc[1].pNext = NULL;
19151 mem_alloc[1].memoryTypeIndex = 0;
19152
19153 VkMemoryRequirements mem_reqs1;
19154 vkGetBufferMemoryRequirements(m_device->device(), dyub1, &mem_reqs1);
19155 VkMemoryRequirements mem_reqs2;
19156 vkGetBufferMemoryRequirements(m_device->device(), dyub2, &mem_reqs2);
19157 mem_alloc[0].allocationSize = mem_reqs1.size;
19158 bool pass = m_device->phy().set_memory_type(mem_reqs1.memoryTypeBits, &mem_alloc[0], 0);
19159 mem_alloc[1].allocationSize = mem_reqs2.size;
19160 pass &= m_device->phy().set_memory_type(mem_reqs2.memoryTypeBits, &mem_alloc[1], 0);
19161 if (!pass) {
19162 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19163 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19164 return;
19165 }
19166
19167 VkDeviceMemory mem1;
19168 err = vkAllocateMemory(m_device->device(), &mem_alloc[0], NULL, &mem1);
19169 ASSERT_VK_SUCCESS(err);
19170 err = vkBindBufferMemory(m_device->device(), dyub1, mem1, 0);
19171 ASSERT_VK_SUCCESS(err);
19172 VkDeviceMemory mem2;
19173 err = vkAllocateMemory(m_device->device(), &mem_alloc[1], NULL, &mem2);
19174 ASSERT_VK_SUCCESS(err);
19175 err = vkBindBufferMemory(m_device->device(), dyub2, mem2, 0);
19176 ASSERT_VK_SUCCESS(err);
19177 // Update descriptors
19178 VkDescriptorBufferInfo buff_info[BINDING_COUNT] = {};
19179 buff_info[0].buffer = dyub1;
19180 buff_info[0].offset = 0;
19181 buff_info[0].range = 256;
19182 buff_info[1].buffer = dyub1;
19183 buff_info[1].offset = 256;
19184 buff_info[1].range = 512;
19185 buff_info[2].buffer = dyub2;
19186 buff_info[2].offset = 0;
19187 buff_info[2].range = 512;
19188
19189 VkWriteDescriptorSet descriptor_write;
19190 memset(&descriptor_write, 0, sizeof(descriptor_write));
19191 descriptor_write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
19192 descriptor_write.dstSet = descriptor_set;
19193 descriptor_write.dstBinding = 0;
19194 descriptor_write.descriptorCount = BINDING_COUNT;
19195 descriptor_write.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
19196 descriptor_write.pBufferInfo = buff_info;
19197
19198 vkUpdateDescriptorSets(m_device->device(), 1, &descriptor_write, 0, NULL);
19199
Tony Barbour552f6c02016-12-21 14:34:07 -070019200 m_commandBuffer->BeginCommandBuffer();
19201 m_commandBuffer->BeginRenderPass(m_renderPassBeginInfo);
Tobin Ehlis953e8392016-11-17 10:54:13 -070019202
19203 // Create PSO to be used for draw-time errors below
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019204 char const *vsSource =
19205 "#version 450\n"
19206 "\n"
19207 "out gl_PerVertex { \n"
19208 " vec4 gl_Position;\n"
19209 "};\n"
19210 "void main(){\n"
19211 " gl_Position = vec4(1);\n"
19212 "}\n";
19213 char const *fsSource =
19214 "#version 450\n"
19215 "\n"
19216 "layout(location=0) out vec4 x;\n"
19217 "layout(set=0) layout(binding=0) uniform foo1 { int x; int y; } bar1;\n"
19218 "layout(set=0) layout(binding=2) uniform foo2 { int x; int y; } bar2;\n"
19219 "void main(){\n"
19220 " x = vec4(bar1.y) + vec4(bar2.y);\n"
19221 "}\n";
Tobin Ehlis953e8392016-11-17 10:54:13 -070019222 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
19223 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
19224 VkPipelineObj pipe(m_device);
19225 pipe.SetViewport(m_viewports);
19226 pipe.SetScissor(m_scissors);
19227 pipe.AddShader(&vs);
19228 pipe.AddShader(&fs);
19229 pipe.AddColorAttachment();
19230 pipe.CreateVKPipeline(pipeline_layout, renderPass());
19231
19232 vkCmdBindPipeline(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipe.handle());
19233 // This update should succeed, but offset of inactive binding 1 oversteps binding 2 buffer size
19234 // we used to have a bug in this case.
19235 uint32_t dyn_off[BINDING_COUNT] = {0, 1024, 256};
19236 vkCmdBindDescriptorSets(m_commandBuffer->GetBufferHandle(), VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1,
19237 &descriptor_set, BINDING_COUNT, dyn_off);
19238 Draw(1, 0, 0, 0);
19239 m_errorMonitor->VerifyNotFound();
19240
19241 vkDestroyBuffer(m_device->device(), dyub1, NULL);
19242 vkDestroyBuffer(m_device->device(), dyub2, NULL);
19243 vkFreeMemory(m_device->device(), mem1, NULL);
19244 vkFreeMemory(m_device->device(), mem2, NULL);
19245
19246 vkDestroyPipelineLayout(m_device->device(), pipeline_layout, NULL);
19247 vkDestroyDescriptorSetLayout(m_device->device(), ds_layout, NULL);
19248 vkDestroyDescriptorPool(m_device->device(), ds_pool, NULL);
19249}
19250
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019251TEST_F(VkPositiveLayerTest, NonCoherentMemoryMapping) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019252 TEST_DESCRIPTION(
19253 "Ensure that validations handling of non-coherent memory "
19254 "mapping while using VK_WHOLE_SIZE does not cause access "
19255 "violations");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019256 VkResult err;
19257 uint8_t *pData;
19258 ASSERT_NO_FATAL_FAILURE(InitState());
19259
19260 VkDeviceMemory mem;
19261 VkMemoryRequirements mem_reqs;
19262 mem_reqs.memoryTypeBits = 0xFFFFFFFF;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019263 const VkDeviceSize atom_size = m_device->props.limits.nonCoherentAtomSize;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019264 VkMemoryAllocateInfo alloc_info = {};
19265 alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19266 alloc_info.pNext = NULL;
19267 alloc_info.memoryTypeIndex = 0;
19268
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019269 static const VkDeviceSize allocation_size = 32 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019270 alloc_info.allocationSize = allocation_size;
19271
19272 // Find a memory configurations WITHOUT a COHERENT bit, otherwise exit
19273 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 -070019274 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019275 if (!pass) {
19276 pass = m_device->phy().set_memory_type(mem_reqs.memoryTypeBits, &alloc_info,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019277 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
19278 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019279 if (!pass) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019280 pass = m_device->phy().set_memory_type(
19281 mem_reqs.memoryTypeBits, &alloc_info,
19282 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
19283 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019284 if (!pass) {
19285 return;
19286 }
19287 }
19288 }
19289
19290 err = vkAllocateMemory(m_device->device(), &alloc_info, NULL, &mem);
19291 ASSERT_VK_SUCCESS(err);
19292
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019293 // Map/Flush/Invalidate using WHOLE_SIZE and zero offsets and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019294 m_errorMonitor->ExpectSuccess();
19295 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19296 ASSERT_VK_SUCCESS(err);
19297 VkMappedMemoryRange mmr = {};
19298 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19299 mmr.memory = mem;
19300 mmr.offset = 0;
19301 mmr.size = VK_WHOLE_SIZE;
19302 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19303 ASSERT_VK_SUCCESS(err);
19304 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19305 ASSERT_VK_SUCCESS(err);
19306 m_errorMonitor->VerifyNotFound();
19307 vkUnmapMemory(m_device->device(), mem);
19308
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019309 // Map/Flush/Invalidate using WHOLE_SIZE and an offset and entire mapped range
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019310 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019311 err = vkMapMemory(m_device->device(), mem, 5 * atom_size, VK_WHOLE_SIZE, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019312 ASSERT_VK_SUCCESS(err);
19313 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19314 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019315 mmr.offset = 6 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019316 mmr.size = VK_WHOLE_SIZE;
19317 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19318 ASSERT_VK_SUCCESS(err);
19319 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19320 ASSERT_VK_SUCCESS(err);
19321 m_errorMonitor->VerifyNotFound();
19322 vkUnmapMemory(m_device->device(), mem);
19323
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019324 // Map with offset and size
19325 // Flush/Invalidate subrange of mapped area with offset and size
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019326 m_errorMonitor->ExpectSuccess();
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019327 err = vkMapMemory(m_device->device(), mem, 3 * atom_size, 9 * atom_size, 0, (void **)&pData);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019328 ASSERT_VK_SUCCESS(err);
19329 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19330 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019331 mmr.offset = 4 * atom_size;
19332 mmr.size = 2 * atom_size;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019333 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19334 ASSERT_VK_SUCCESS(err);
19335 err = vkInvalidateMappedMemoryRanges(m_device->device(), 1, &mmr);
19336 ASSERT_VK_SUCCESS(err);
19337 m_errorMonitor->VerifyNotFound();
19338 vkUnmapMemory(m_device->device(), mem);
19339
19340 // Map without offset and flush WHOLE_SIZE with two separate offsets
19341 m_errorMonitor->ExpectSuccess();
19342 err = vkMapMemory(m_device->device(), mem, 0, VK_WHOLE_SIZE, 0, (void **)&pData);
19343 ASSERT_VK_SUCCESS(err);
19344 mmr.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
19345 mmr.memory = mem;
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019346 mmr.offset = allocation_size - (4 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019347 mmr.size = VK_WHOLE_SIZE;
19348 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19349 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski255cdef2016-11-28 13:58:59 -070019350 mmr.offset = allocation_size - (6 * atom_size);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019351 mmr.size = VK_WHOLE_SIZE;
19352 err = vkFlushMappedMemoryRanges(m_device->device(), 1, &mmr);
19353 ASSERT_VK_SUCCESS(err);
19354 m_errorMonitor->VerifyNotFound();
19355 vkUnmapMemory(m_device->device(), mem);
19356
19357 vkFreeMemory(m_device->device(), mem, NULL);
19358}
19359
19360// This is a positive test. We used to expect error in this case but spec now allows it
19361TEST_F(VkPositiveLayerTest, ResetUnsignaledFence) {
19362 m_errorMonitor->ExpectSuccess();
19363 vk_testing::Fence testFence;
19364 VkFenceCreateInfo fenceInfo = {};
19365 fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
19366 fenceInfo.pNext = NULL;
19367
19368 ASSERT_NO_FATAL_FAILURE(InitState());
19369 testFence.init(*m_device, fenceInfo);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019370 VkFence fences[1] = {testFence.handle()};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019371 VkResult result = vkResetFences(m_device->device(), 1, fences);
19372 ASSERT_VK_SUCCESS(result);
19373
19374 m_errorMonitor->VerifyNotFound();
19375}
19376
19377TEST_F(VkPositiveLayerTest, CommandBufferSimultaneousUseSync) {
19378 m_errorMonitor->ExpectSuccess();
19379
19380 ASSERT_NO_FATAL_FAILURE(InitState());
19381 VkResult err;
19382
19383 // Record (empty!) command buffer that can be submitted multiple times
19384 // simultaneously.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019385 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr,
19386 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019387 m_commandBuffer->BeginCommandBuffer(&cbbi);
19388 m_commandBuffer->EndCommandBuffer();
19389
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019390 VkFenceCreateInfo fci = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019391 VkFence fence;
19392 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
19393 ASSERT_VK_SUCCESS(err);
19394
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019395 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019396 VkSemaphore s1, s2;
19397 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s1);
19398 ASSERT_VK_SUCCESS(err);
19399 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s2);
19400 ASSERT_VK_SUCCESS(err);
19401
19402 // Submit CB once signaling s1, with fence so we can roll forward to its retirement.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019403 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &m_commandBuffer->handle(), 1, &s1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019404 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
19405 ASSERT_VK_SUCCESS(err);
19406
19407 // Submit CB again, signaling s2.
19408 si.pSignalSemaphores = &s2;
19409 err = vkQueueSubmit(m_device->m_queue, 1, &si, VK_NULL_HANDLE);
19410 ASSERT_VK_SUCCESS(err);
19411
19412 // Wait for fence.
19413 err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
19414 ASSERT_VK_SUCCESS(err);
19415
19416 // CB is still in flight from second submission, but semaphore s1 is no
19417 // longer in flight. delete it.
19418 vkDestroySemaphore(m_device->device(), s1, nullptr);
19419
19420 m_errorMonitor->VerifyNotFound();
19421
19422 // Force device idle and clean up remaining objects
19423 vkDeviceWaitIdle(m_device->device());
19424 vkDestroySemaphore(m_device->device(), s2, nullptr);
19425 vkDestroyFence(m_device->device(), fence, nullptr);
19426}
19427
19428TEST_F(VkPositiveLayerTest, FenceCreateSignaledWaitHandling) {
19429 m_errorMonitor->ExpectSuccess();
19430
19431 ASSERT_NO_FATAL_FAILURE(InitState());
19432 VkResult err;
19433
19434 // A fence created signaled
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019435 VkFenceCreateInfo fci1 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, VK_FENCE_CREATE_SIGNALED_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019436 VkFence f1;
19437 err = vkCreateFence(m_device->device(), &fci1, nullptr, &f1);
19438 ASSERT_VK_SUCCESS(err);
19439
19440 // A fence created not
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019441 VkFenceCreateInfo fci2 = {VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019442 VkFence f2;
19443 err = vkCreateFence(m_device->device(), &fci2, nullptr, &f2);
19444 ASSERT_VK_SUCCESS(err);
19445
19446 // Submit the unsignaled fence
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019447 VkSubmitInfo si = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019448 err = vkQueueSubmit(m_device->m_queue, 1, &si, f2);
19449
19450 // Wait on both fences, with signaled first.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019451 VkFence fences[] = {f1, f2};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019452 vkWaitForFences(m_device->device(), 2, fences, VK_TRUE, UINT64_MAX);
19453
19454 // Should have both retired!
19455 vkDestroyFence(m_device->device(), f1, nullptr);
19456 vkDestroyFence(m_device->device(), f2, nullptr);
19457
19458 m_errorMonitor->VerifyNotFound();
19459}
19460
19461TEST_F(VkPositiveLayerTest, ValidUsage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019462 TEST_DESCRIPTION(
19463 "Verify that creating an image view from an image with valid usage "
19464 "doesn't generate validation errors");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019465
19466 ASSERT_NO_FATAL_FAILURE(InitState());
19467
19468 m_errorMonitor->ExpectSuccess();
19469 // Verify that we can create a view with usage INPUT_ATTACHMENT
19470 VkImageObj image(m_device);
19471 image.init(128, 128, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19472 ASSERT_TRUE(image.initialized());
19473 VkImageView imageView;
19474 VkImageViewCreateInfo ivci = {};
19475 ivci.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
19476 ivci.image = image.handle();
19477 ivci.viewType = VK_IMAGE_VIEW_TYPE_2D;
19478 ivci.format = VK_FORMAT_R8G8B8A8_UNORM;
19479 ivci.subresourceRange.layerCount = 1;
19480 ivci.subresourceRange.baseMipLevel = 0;
19481 ivci.subresourceRange.levelCount = 1;
19482 ivci.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
19483
19484 vkCreateImageView(m_device->device(), &ivci, NULL, &imageView);
19485 m_errorMonitor->VerifyNotFound();
19486 vkDestroyImageView(m_device->device(), imageView, NULL);
19487}
19488
19489// This is a positive test. No failures are expected.
19490TEST_F(VkPositiveLayerTest, BindSparse) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019491 TEST_DESCRIPTION(
19492 "Bind 2 memory ranges to one image using vkQueueBindSparse, destroy the image"
19493 "and then free the memory");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019494
19495 ASSERT_NO_FATAL_FAILURE(InitState());
19496
19497 auto index = m_device->graphics_queue_node_index_;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019498 if (!(m_device->queue_props[index].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019499
19500 m_errorMonitor->ExpectSuccess();
19501
19502 VkImage image;
19503 VkImageCreateInfo image_create_info = {};
19504 image_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
19505 image_create_info.pNext = NULL;
19506 image_create_info.imageType = VK_IMAGE_TYPE_2D;
19507 image_create_info.format = VK_FORMAT_B8G8R8A8_UNORM;
19508 image_create_info.extent.width = 64;
19509 image_create_info.extent.height = 64;
19510 image_create_info.extent.depth = 1;
19511 image_create_info.mipLevels = 1;
19512 image_create_info.arrayLayers = 1;
19513 image_create_info.samples = VK_SAMPLE_COUNT_1_BIT;
19514 image_create_info.tiling = VK_IMAGE_TILING_OPTIMAL;
19515 image_create_info.usage = VK_IMAGE_USAGE_STORAGE_BIT;
19516 image_create_info.flags = VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
19517 VkResult err = vkCreateImage(m_device->device(), &image_create_info, NULL, &image);
19518 ASSERT_VK_SUCCESS(err);
19519
19520 VkMemoryRequirements memory_reqs;
19521 VkDeviceMemory memory_one, memory_two;
19522 bool pass;
19523 VkMemoryAllocateInfo memory_info = {};
19524 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
19525 memory_info.pNext = NULL;
19526 memory_info.allocationSize = 0;
19527 memory_info.memoryTypeIndex = 0;
19528 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19529 // Find an image big enough to allow sparse mapping of 2 memory regions
19530 // Increase the image size until it is at least twice the
19531 // size of the required alignment, to ensure we can bind both
19532 // allocated memory blocks to the image on aligned offsets.
19533 while (memory_reqs.size < (memory_reqs.alignment * 2)) {
19534 vkDestroyImage(m_device->device(), image, nullptr);
19535 image_create_info.extent.width *= 2;
19536 image_create_info.extent.height *= 2;
19537 err = vkCreateImage(m_device->device(), &image_create_info, nullptr, &image);
19538 ASSERT_VK_SUCCESS(err);
19539 vkGetImageMemoryRequirements(m_device->device(), image, &memory_reqs);
19540 }
19541 // Allocate 2 memory regions of minimum alignment size, bind one at 0, the other
19542 // at the end of the first
19543 memory_info.allocationSize = memory_reqs.alignment;
19544 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
19545 ASSERT_TRUE(pass);
19546 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_one);
19547 ASSERT_VK_SUCCESS(err);
19548 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &memory_two);
19549 ASSERT_VK_SUCCESS(err);
19550 VkSparseMemoryBind binds[2];
19551 binds[0].flags = 0;
19552 binds[0].memory = memory_one;
19553 binds[0].memoryOffset = 0;
19554 binds[0].resourceOffset = 0;
19555 binds[0].size = memory_info.allocationSize;
19556 binds[1].flags = 0;
19557 binds[1].memory = memory_two;
19558 binds[1].memoryOffset = 0;
19559 binds[1].resourceOffset = memory_info.allocationSize;
19560 binds[1].size = memory_info.allocationSize;
19561
19562 VkSparseImageOpaqueMemoryBindInfo opaqueBindInfo;
19563 opaqueBindInfo.image = image;
19564 opaqueBindInfo.bindCount = 2;
19565 opaqueBindInfo.pBinds = binds;
19566
19567 VkFence fence = VK_NULL_HANDLE;
19568 VkBindSparseInfo bindSparseInfo = {};
19569 bindSparseInfo.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO;
19570 bindSparseInfo.imageOpaqueBindCount = 1;
19571 bindSparseInfo.pImageOpaqueBinds = &opaqueBindInfo;
19572
19573 vkQueueBindSparse(m_device->m_queue, 1, &bindSparseInfo, fence);
19574 vkQueueWaitIdle(m_device->m_queue);
19575 vkDestroyImage(m_device->device(), image, NULL);
19576 vkFreeMemory(m_device->device(), memory_one, NULL);
19577 vkFreeMemory(m_device->device(), memory_two, NULL);
19578 m_errorMonitor->VerifyNotFound();
19579}
19580
19581TEST_F(VkPositiveLayerTest, RenderPassInitialLayoutUndefined) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019582 TEST_DESCRIPTION(
19583 "Ensure that CmdBeginRenderPass with an attachment's "
19584 "initialLayout of VK_IMAGE_LAYOUT_UNDEFINED works when "
19585 "the command buffer has prior knowledge of that "
19586 "attachment's layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019587
19588 m_errorMonitor->ExpectSuccess();
19589
19590 ASSERT_NO_FATAL_FAILURE(InitState());
19591
19592 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019593 VkAttachmentDescription attachment = {0,
19594 VK_FORMAT_R8G8B8A8_UNORM,
19595 VK_SAMPLE_COUNT_1_BIT,
19596 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19597 VK_ATTACHMENT_STORE_OP_STORE,
19598 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19599 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19600 VK_IMAGE_LAYOUT_UNDEFINED,
19601 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019602
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019603 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019604
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019605 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019606
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019607 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019608
19609 VkRenderPass rp;
19610 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19611 ASSERT_VK_SUCCESS(err);
19612
19613 // A compatible framebuffer.
19614 VkImageObj image(m_device);
19615 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19616 ASSERT_TRUE(image.initialized());
19617
19618 VkImageViewCreateInfo ivci = {
19619 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19620 nullptr,
19621 0,
19622 image.handle(),
19623 VK_IMAGE_VIEW_TYPE_2D,
19624 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019625 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19626 VK_COMPONENT_SWIZZLE_IDENTITY},
19627 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019628 };
19629 VkImageView view;
19630 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19631 ASSERT_VK_SUCCESS(err);
19632
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019633 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019634 VkFramebuffer fb;
19635 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19636 ASSERT_VK_SUCCESS(err);
19637
19638 // Record a single command buffer which uses this renderpass twice. The
19639 // bug is triggered at the beginning of the second renderpass, when the
19640 // command buffer already has a layout recorded for the attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019641 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
Tony Barbour552f6c02016-12-21 14:34:07 -070019642 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019643 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19644 vkCmdEndRenderPass(m_commandBuffer->handle());
19645 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19646
19647 m_errorMonitor->VerifyNotFound();
19648
19649 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019650 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019651
19652 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19653 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19654 vkDestroyImageView(m_device->device(), view, nullptr);
19655}
19656
19657TEST_F(VkPositiveLayerTest, FramebufferBindingDestroyCommandPool) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019658 TEST_DESCRIPTION(
19659 "This test should pass. Create a Framebuffer and "
19660 "command buffer, bind them together, then destroy "
19661 "command pool and framebuffer and verify there are no "
19662 "errors.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019663
19664 m_errorMonitor->ExpectSuccess();
19665
19666 ASSERT_NO_FATAL_FAILURE(InitState());
19667
19668 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019669 VkAttachmentDescription attachment = {0,
19670 VK_FORMAT_R8G8B8A8_UNORM,
19671 VK_SAMPLE_COUNT_1_BIT,
19672 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19673 VK_ATTACHMENT_STORE_OP_STORE,
19674 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19675 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19676 VK_IMAGE_LAYOUT_UNDEFINED,
19677 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019678
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019679 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019680
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019681 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019682
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019683 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019684
19685 VkRenderPass rp;
19686 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19687 ASSERT_VK_SUCCESS(err);
19688
19689 // A compatible framebuffer.
19690 VkImageObj image(m_device);
19691 image.init(32, 32, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_IMAGE_TILING_OPTIMAL, 0);
19692 ASSERT_TRUE(image.initialized());
19693
19694 VkImageViewCreateInfo ivci = {
19695 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19696 nullptr,
19697 0,
19698 image.handle(),
19699 VK_IMAGE_VIEW_TYPE_2D,
19700 VK_FORMAT_R8G8B8A8_UNORM,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019701 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
19702 VK_COMPONENT_SWIZZLE_IDENTITY},
19703 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019704 };
19705 VkImageView view;
19706 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19707 ASSERT_VK_SUCCESS(err);
19708
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019709 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019710 VkFramebuffer fb;
19711 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19712 ASSERT_VK_SUCCESS(err);
19713
19714 // Explicitly create a command buffer to bind the FB to so that we can then
19715 // destroy the command pool in order to implicitly free command buffer
19716 VkCommandPool command_pool;
19717 VkCommandPoolCreateInfo pool_create_info{};
19718 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
19719 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
19720 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
19721 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
19722
19723 VkCommandBuffer command_buffer;
19724 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
19725 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
19726 command_buffer_allocate_info.commandPool = command_pool;
19727 command_buffer_allocate_info.commandBufferCount = 1;
19728 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
19729 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
19730
19731 // Begin our cmd buffer with renderpass using our framebuffer
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019732 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 -060019733 VkCommandBufferBeginInfo begin_info{};
19734 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
19735 vkBeginCommandBuffer(command_buffer, &begin_info);
19736
19737 vkCmdBeginRenderPass(command_buffer, &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19738 vkCmdEndRenderPass(command_buffer);
19739 vkEndCommandBuffer(command_buffer);
19740 vkDestroyImageView(m_device->device(), view, nullptr);
19741 // Destroy command pool to implicitly free command buffer
19742 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
19743 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19744 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19745 m_errorMonitor->VerifyNotFound();
19746}
19747
19748TEST_F(VkPositiveLayerTest, RenderPassSubpassZeroTransitionsApplied) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019749 TEST_DESCRIPTION(
19750 "Ensure that CmdBeginRenderPass applies the layout "
19751 "transitions for the first subpass");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019752
19753 m_errorMonitor->ExpectSuccess();
19754
19755 ASSERT_NO_FATAL_FAILURE(InitState());
19756
19757 // A renderpass with one color attachment.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019758 VkAttachmentDescription attachment = {0,
19759 VK_FORMAT_R8G8B8A8_UNORM,
19760 VK_SAMPLE_COUNT_1_BIT,
19761 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19762 VK_ATTACHMENT_STORE_OP_STORE,
19763 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19764 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19765 VK_IMAGE_LAYOUT_UNDEFINED,
19766 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019767
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019768 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019769
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019770 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019771
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019772 VkSubpassDependency dep = {0,
19773 0,
19774 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19775 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19776 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19777 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19778 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019779
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019780 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019781
19782 VkResult err;
19783 VkRenderPass rp;
19784 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 // Record a single command buffer which issues a pipeline barrier w/
19813 // image memory barrier for the attachment. This detects the previously
19814 // missing tracking of the subpass layout by throwing a validation error
19815 // if it doesn't occur.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019816 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 -070019817 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019818 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19819
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019820 VkImageMemoryBarrier imb = {VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
19821 nullptr,
19822 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19823 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19824 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19825 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
19826 VK_QUEUE_FAMILY_IGNORED,
19827 VK_QUEUE_FAMILY_IGNORED,
19828 image.handle(),
19829 {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019830 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019831 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19832 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019833
19834 vkCmdEndRenderPass(m_commandBuffer->handle());
19835 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019836 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019837
19838 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19839 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19840 vkDestroyImageView(m_device->device(), view, nullptr);
19841}
19842
19843TEST_F(VkPositiveLayerTest, DepthStencilLayoutTransitionForDepthOnlyImageview) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019844 TEST_DESCRIPTION(
19845 "Validate that when an imageView of a depth/stencil image "
19846 "is used as a depth/stencil framebuffer attachment, the "
19847 "aspectMask is ignored and both depth and stencil image "
19848 "subresources are used.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019849
19850 VkFormatProperties format_properties;
19851 vkGetPhysicalDeviceFormatProperties(gpu(), VK_FORMAT_D32_SFLOAT_S8_UINT, &format_properties);
19852 if (!(format_properties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
19853 return;
19854 }
19855
19856 m_errorMonitor->ExpectSuccess();
19857
19858 ASSERT_NO_FATAL_FAILURE(InitState());
19859
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019860 VkAttachmentDescription attachment = {0,
19861 VK_FORMAT_D32_SFLOAT_S8_UINT,
19862 VK_SAMPLE_COUNT_1_BIT,
19863 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19864 VK_ATTACHMENT_STORE_OP_STORE,
19865 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
19866 VK_ATTACHMENT_STORE_OP_DONT_CARE,
19867 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
19868 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019869
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019870 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019871
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019872 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019873
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019874 VkSubpassDependency dep = {0,
19875 0,
19876 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19877 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
19878 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19879 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
19880 VK_DEPENDENCY_BY_REGION_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019881
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019882 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 1, &dep};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019883
19884 VkResult err;
19885 VkRenderPass rp;
19886 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19887 ASSERT_VK_SUCCESS(err);
19888
19889 VkImageObj image(m_device);
19890 image.init_no_layout(32, 32, VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019891 0x26, // usage
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019892 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019893 ASSERT_TRUE(image.initialized());
19894 image.SetLayout(0x6, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
19895
19896 VkImageViewCreateInfo ivci = {
19897 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
19898 nullptr,
19899 0,
19900 image.handle(),
19901 VK_IMAGE_VIEW_TYPE_2D,
19902 VK_FORMAT_D32_SFLOAT_S8_UINT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019903 {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A},
19904 {0x2, 0, 1, 0, 1},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019905 };
19906 VkImageView view;
19907 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
19908 ASSERT_VK_SUCCESS(err);
19909
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019910 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019911 VkFramebuffer fb;
19912 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19913 ASSERT_VK_SUCCESS(err);
19914
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019915 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 -070019916 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019917 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19918
19919 VkImageMemoryBarrier imb = {};
19920 imb.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
19921 imb.pNext = nullptr;
19922 imb.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
19923 imb.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
19924 imb.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
19925 imb.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
19926 imb.srcQueueFamilyIndex = 0;
19927 imb.dstQueueFamilyIndex = 0;
19928 imb.image = image.handle();
19929 imb.subresourceRange.aspectMask = 0x6;
19930 imb.subresourceRange.baseMipLevel = 0;
19931 imb.subresourceRange.levelCount = 0x1;
19932 imb.subresourceRange.baseArrayLayer = 0;
19933 imb.subresourceRange.layerCount = 0x1;
19934
19935 vkCmdPipelineBarrier(m_commandBuffer->handle(), VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019936 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_DEPENDENCY_BY_REGION_BIT, 0, nullptr, 0, nullptr, 1,
19937 &imb);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019938
19939 vkCmdEndRenderPass(m_commandBuffer->handle());
Tony Barbour552f6c02016-12-21 14:34:07 -070019940 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019941 QueueCommandBuffer(false);
19942 m_errorMonitor->VerifyNotFound();
19943
19944 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19945 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19946 vkDestroyImageView(m_device->device(), view, nullptr);
19947}
19948
19949TEST_F(VkPositiveLayerTest, RenderPassTransitionsAttachmentUnused) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019950 TEST_DESCRIPTION(
19951 "Ensure that layout transitions work correctly without "
19952 "errors, when an attachment reference is "
19953 "VK_ATTACHMENT_UNUSED");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019954
19955 m_errorMonitor->ExpectSuccess();
19956
19957 ASSERT_NO_FATAL_FAILURE(InitState());
19958
19959 // A renderpass with no attachments
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019960 VkAttachmentReference att_ref = {VK_ATTACHMENT_UNUSED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019961
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019962 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 1, &att_ref, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019963
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019964 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 0, nullptr, 1, &subpass, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019965
19966 VkRenderPass rp;
19967 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
19968 ASSERT_VK_SUCCESS(err);
19969
19970 // A compatible framebuffer.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019971 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 0, nullptr, 32, 32, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019972 VkFramebuffer fb;
19973 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
19974 ASSERT_VK_SUCCESS(err);
19975
19976 // Record a command buffer which just begins and ends the renderpass. The
19977 // bug manifests in BeginRenderPass.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070019978 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 -070019979 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019980 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
19981 vkCmdEndRenderPass(m_commandBuffer->handle());
19982 m_errorMonitor->VerifyNotFound();
Tony Barbour552f6c02016-12-21 14:34:07 -070019983 m_commandBuffer->EndCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019984
19985 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
19986 vkDestroyRenderPass(m_device->device(), rp, nullptr);
19987}
19988
19989// This is a positive test. No errors are expected.
19990TEST_F(VkPositiveLayerTest, StencilLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070019991 TEST_DESCRIPTION(
19992 "Create a stencil-only attachment with a LOAD_OP set to "
19993 "CLEAR. stencil[Load|Store]Op used to be ignored.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060019994 VkResult result = VK_SUCCESS;
Tony Barbourf887b162017-03-09 10:06:46 -070019995 ASSERT_NO_FATAL_FAILURE(InitState());
19996 auto depth_format = find_depth_stencil_format(m_device);
19997 if (!depth_format) {
19998 printf(" No Depth + Stencil format found. Skipped.\n");
19999 return;
20000 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020001 VkImageFormatProperties formatProps;
Tony Barbourf887b162017-03-09 10:06:46 -070020002 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020003 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
20004 &formatProps);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020005 if (formatProps.maxExtent.width < 100 || formatProps.maxExtent.height < 100) {
20006 return;
20007 }
20008
Tony Barbourf887b162017-03-09 10:06:46 -070020009 VkFormat depth_stencil_fmt = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020010 m_depthStencil->Init(m_device, 100, 100, depth_stencil_fmt,
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020011 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020012 VkAttachmentDescription att = {};
20013 VkAttachmentReference ref = {};
20014 att.format = depth_stencil_fmt;
20015 att.samples = VK_SAMPLE_COUNT_1_BIT;
20016 att.loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
20017 att.storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
20018 att.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
20019 att.stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE;
20020 att.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20021 att.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20022
20023 VkClearValue clear;
20024 clear.depthStencil.depth = 1.0;
20025 clear.depthStencil.stencil = 0;
20026 ref.attachment = 0;
20027 ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20028
20029 VkSubpassDescription subpass = {};
20030 subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
20031 subpass.flags = 0;
20032 subpass.inputAttachmentCount = 0;
20033 subpass.pInputAttachments = NULL;
20034 subpass.colorAttachmentCount = 0;
20035 subpass.pColorAttachments = NULL;
20036 subpass.pResolveAttachments = NULL;
20037 subpass.pDepthStencilAttachment = &ref;
20038 subpass.preserveAttachmentCount = 0;
20039 subpass.pPreserveAttachments = NULL;
20040
20041 VkRenderPass rp;
20042 VkRenderPassCreateInfo rp_info = {};
20043 rp_info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
20044 rp_info.attachmentCount = 1;
20045 rp_info.pAttachments = &att;
20046 rp_info.subpassCount = 1;
20047 rp_info.pSubpasses = &subpass;
20048 result = vkCreateRenderPass(device(), &rp_info, NULL, &rp);
20049 ASSERT_VK_SUCCESS(result);
20050
20051 VkImageView *depthView = m_depthStencil->BindInfo();
20052 VkFramebufferCreateInfo fb_info = {};
20053 fb_info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
20054 fb_info.pNext = NULL;
20055 fb_info.renderPass = rp;
20056 fb_info.attachmentCount = 1;
20057 fb_info.pAttachments = depthView;
20058 fb_info.width = 100;
20059 fb_info.height = 100;
20060 fb_info.layers = 1;
20061 VkFramebuffer fb;
20062 result = vkCreateFramebuffer(device(), &fb_info, NULL, &fb);
20063 ASSERT_VK_SUCCESS(result);
20064
20065 VkRenderPassBeginInfo rpbinfo = {};
20066 rpbinfo.clearValueCount = 1;
20067 rpbinfo.pClearValues = &clear;
20068 rpbinfo.pNext = NULL;
20069 rpbinfo.renderPass = rp;
20070 rpbinfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
20071 rpbinfo.renderArea.extent.width = 100;
20072 rpbinfo.renderArea.extent.height = 100;
20073 rpbinfo.renderArea.offset.x = 0;
20074 rpbinfo.renderArea.offset.y = 0;
20075 rpbinfo.framebuffer = fb;
20076
20077 VkFence fence = {};
20078 VkFenceCreateInfo fence_ci = {};
20079 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20080 fence_ci.pNext = nullptr;
20081 fence_ci.flags = 0;
20082 result = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fence);
20083 ASSERT_VK_SUCCESS(result);
20084
20085 m_commandBuffer->BeginCommandBuffer();
20086 m_commandBuffer->BeginRenderPass(rpbinfo);
20087 m_commandBuffer->EndRenderPass();
20088 m_commandBuffer->EndCommandBuffer();
20089 m_commandBuffer->QueueCommandBuffer(fence);
20090
20091 VkImageObj destImage(m_device);
20092 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 -070020093 VK_IMAGE_TILING_OPTIMAL, 0);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020094 VkImageMemoryBarrier barrier = {};
20095 VkImageSubresourceRange range;
20096 barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
20097 barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20098 barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
20099 barrier.oldLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
20100 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
20101 barrier.image = m_depthStencil->handle();
20102 range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20103 range.baseMipLevel = 0;
20104 range.levelCount = 1;
20105 range.baseArrayLayer = 0;
20106 range.layerCount = 1;
20107 barrier.subresourceRange = range;
20108 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20109 VkCommandBufferObj cmdbuf(m_device, m_commandPool);
20110 cmdbuf.BeginCommandBuffer();
20111 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 -070020112 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020113 barrier.srcAccessMask = 0;
20114 barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
20115 barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
20116 barrier.image = destImage.handle();
20117 barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
20118 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 -070020119 &barrier);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020120 VkImageCopy cregion;
20121 cregion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20122 cregion.srcSubresource.mipLevel = 0;
20123 cregion.srcSubresource.baseArrayLayer = 0;
20124 cregion.srcSubresource.layerCount = 1;
20125 cregion.srcOffset.x = 0;
20126 cregion.srcOffset.y = 0;
20127 cregion.srcOffset.z = 0;
20128 cregion.dstSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
20129 cregion.dstSubresource.mipLevel = 0;
20130 cregion.dstSubresource.baseArrayLayer = 0;
20131 cregion.dstSubresource.layerCount = 1;
20132 cregion.dstOffset.x = 0;
20133 cregion.dstOffset.y = 0;
20134 cregion.dstOffset.z = 0;
20135 cregion.extent.width = 100;
20136 cregion.extent.height = 100;
20137 cregion.extent.depth = 1;
20138 cmdbuf.CopyImage(m_depthStencil->handle(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, destImage.handle(),
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020139 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &cregion);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020140 cmdbuf.EndCommandBuffer();
20141
20142 VkSubmitInfo submit_info;
20143 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20144 submit_info.pNext = NULL;
20145 submit_info.waitSemaphoreCount = 0;
20146 submit_info.pWaitSemaphores = NULL;
20147 submit_info.pWaitDstStageMask = NULL;
20148 submit_info.commandBufferCount = 1;
20149 submit_info.pCommandBuffers = &cmdbuf.handle();
20150 submit_info.signalSemaphoreCount = 0;
20151 submit_info.pSignalSemaphores = NULL;
20152
20153 m_errorMonitor->ExpectSuccess();
20154 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20155 m_errorMonitor->VerifyNotFound();
20156
20157 vkQueueWaitIdle(m_device->m_queue);
20158 vkDestroyFence(m_device->device(), fence, nullptr);
20159 vkDestroyRenderPass(m_device->device(), rp, nullptr);
20160 vkDestroyFramebuffer(m_device->device(), fb, nullptr);
20161}
20162
20163// This is a positive test. No errors should be generated.
20164TEST_F(VkPositiveLayerTest, WaitEventThenSet) {
20165 TEST_DESCRIPTION("Wait on a event then set it after the wait has been submitted.");
20166
20167 m_errorMonitor->ExpectSuccess();
20168 ASSERT_NO_FATAL_FAILURE(InitState());
20169
20170 VkEvent event;
20171 VkEventCreateInfo event_create_info{};
20172 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20173 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20174
20175 VkCommandPool command_pool;
20176 VkCommandPoolCreateInfo pool_create_info{};
20177 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20178 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20179 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20180 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20181
20182 VkCommandBuffer command_buffer;
20183 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20184 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20185 command_buffer_allocate_info.commandPool = command_pool;
20186 command_buffer_allocate_info.commandBufferCount = 1;
20187 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20188 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20189
20190 VkQueue queue = VK_NULL_HANDLE;
20191 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20192
20193 {
20194 VkCommandBufferBeginInfo begin_info{};
20195 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20196 vkBeginCommandBuffer(command_buffer, &begin_info);
20197
20198 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 -070020199 nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020200 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
20201 vkEndCommandBuffer(command_buffer);
20202 }
20203 {
20204 VkSubmitInfo submit_info{};
20205 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20206 submit_info.commandBufferCount = 1;
20207 submit_info.pCommandBuffers = &command_buffer;
20208 submit_info.signalSemaphoreCount = 0;
20209 submit_info.pSignalSemaphores = nullptr;
20210 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20211 }
20212 { vkSetEvent(m_device->device(), event); }
20213
20214 vkQueueWaitIdle(queue);
20215
20216 vkDestroyEvent(m_device->device(), event, nullptr);
20217 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20218 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20219
20220 m_errorMonitor->VerifyNotFound();
20221}
20222// This is a positive test. No errors should be generated.
20223TEST_F(VkPositiveLayerTest, QueryAndCopySecondaryCommandBuffers) {
20224 TEST_DESCRIPTION("Issue a query on a secondary command buffery and copy it on a primary.");
20225
20226 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020227 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020228
20229 m_errorMonitor->ExpectSuccess();
20230
20231 VkQueryPool query_pool;
20232 VkQueryPoolCreateInfo query_pool_create_info{};
20233 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20234 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20235 query_pool_create_info.queryCount = 1;
20236 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20237
20238 VkCommandPool command_pool;
20239 VkCommandPoolCreateInfo pool_create_info{};
20240 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20241 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20242 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20243 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20244
20245 VkCommandBuffer command_buffer;
20246 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20247 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20248 command_buffer_allocate_info.commandPool = command_pool;
20249 command_buffer_allocate_info.commandBufferCount = 1;
20250 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20251 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20252
20253 VkCommandBuffer secondary_command_buffer;
20254 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
20255 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &secondary_command_buffer);
20256
20257 VkQueue queue = VK_NULL_HANDLE;
20258 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20259
20260 uint32_t qfi = 0;
20261 VkBufferCreateInfo buff_create_info = {};
20262 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20263 buff_create_info.size = 1024;
20264 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20265 buff_create_info.queueFamilyIndexCount = 1;
20266 buff_create_info.pQueueFamilyIndices = &qfi;
20267
20268 VkResult err;
20269 VkBuffer buffer;
20270 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20271 ASSERT_VK_SUCCESS(err);
20272 VkMemoryAllocateInfo mem_alloc = {};
20273 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20274 mem_alloc.pNext = NULL;
20275 mem_alloc.allocationSize = 1024;
20276 mem_alloc.memoryTypeIndex = 0;
20277
20278 VkMemoryRequirements memReqs;
20279 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20280 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20281 if (!pass) {
20282 vkDestroyBuffer(m_device->device(), buffer, NULL);
20283 return;
20284 }
20285
20286 VkDeviceMemory mem;
20287 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20288 ASSERT_VK_SUCCESS(err);
20289 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20290 ASSERT_VK_SUCCESS(err);
20291
20292 VkCommandBufferInheritanceInfo hinfo = {};
20293 hinfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO;
20294 hinfo.renderPass = VK_NULL_HANDLE;
20295 hinfo.subpass = 0;
20296 hinfo.framebuffer = VK_NULL_HANDLE;
20297 hinfo.occlusionQueryEnable = VK_FALSE;
20298 hinfo.queryFlags = 0;
20299 hinfo.pipelineStatistics = 0;
20300
20301 {
20302 VkCommandBufferBeginInfo begin_info{};
20303 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20304 begin_info.pInheritanceInfo = &hinfo;
20305 vkBeginCommandBuffer(secondary_command_buffer, &begin_info);
20306
20307 vkCmdResetQueryPool(secondary_command_buffer, query_pool, 0, 1);
20308 vkCmdWriteTimestamp(secondary_command_buffer, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20309
20310 vkEndCommandBuffer(secondary_command_buffer);
20311
20312 begin_info.pInheritanceInfo = nullptr;
20313 vkBeginCommandBuffer(command_buffer, &begin_info);
20314
20315 vkCmdExecuteCommands(command_buffer, 1, &secondary_command_buffer);
20316 vkCmdCopyQueryPoolResults(command_buffer, query_pool, 0, 1, buffer, 0, 0, 0);
20317
20318 vkEndCommandBuffer(command_buffer);
20319 }
20320 {
20321 VkSubmitInfo submit_info{};
20322 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20323 submit_info.commandBufferCount = 1;
20324 submit_info.pCommandBuffers = &command_buffer;
20325 submit_info.signalSemaphoreCount = 0;
20326 submit_info.pSignalSemaphores = nullptr;
20327 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20328 }
20329
20330 vkQueueWaitIdle(queue);
20331
20332 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20333 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20334 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &secondary_command_buffer);
20335 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20336 vkDestroyBuffer(m_device->device(), buffer, NULL);
20337 vkFreeMemory(m_device->device(), mem, NULL);
20338
20339 m_errorMonitor->VerifyNotFound();
20340}
20341
20342// This is a positive test. No errors should be generated.
20343TEST_F(VkPositiveLayerTest, QueryAndCopyMultipleCommandBuffers) {
20344 TEST_DESCRIPTION("Issue a query and copy from it on a second command buffer.");
20345
20346 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020347 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020348
20349 m_errorMonitor->ExpectSuccess();
20350
20351 VkQueryPool query_pool;
20352 VkQueryPoolCreateInfo query_pool_create_info{};
20353 query_pool_create_info.sType = VK_STRUCTURE_TYPE_QUERY_POOL_CREATE_INFO;
20354 query_pool_create_info.queryType = VK_QUERY_TYPE_TIMESTAMP;
20355 query_pool_create_info.queryCount = 1;
20356 vkCreateQueryPool(m_device->device(), &query_pool_create_info, nullptr, &query_pool);
20357
20358 VkCommandPool command_pool;
20359 VkCommandPoolCreateInfo pool_create_info{};
20360 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20361 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20362 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20363 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20364
20365 VkCommandBuffer command_buffer[2];
20366 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20367 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20368 command_buffer_allocate_info.commandPool = command_pool;
20369 command_buffer_allocate_info.commandBufferCount = 2;
20370 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20371 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20372
20373 VkQueue queue = VK_NULL_HANDLE;
20374 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20375
20376 uint32_t qfi = 0;
20377 VkBufferCreateInfo buff_create_info = {};
20378 buff_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
20379 buff_create_info.size = 1024;
20380 buff_create_info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
20381 buff_create_info.queueFamilyIndexCount = 1;
20382 buff_create_info.pQueueFamilyIndices = &qfi;
20383
20384 VkResult err;
20385 VkBuffer buffer;
20386 err = vkCreateBuffer(m_device->device(), &buff_create_info, NULL, &buffer);
20387 ASSERT_VK_SUCCESS(err);
20388 VkMemoryAllocateInfo mem_alloc = {};
20389 mem_alloc.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
20390 mem_alloc.pNext = NULL;
20391 mem_alloc.allocationSize = 1024;
20392 mem_alloc.memoryTypeIndex = 0;
20393
20394 VkMemoryRequirements memReqs;
20395 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memReqs);
20396 bool pass = m_device->phy().set_memory_type(memReqs.memoryTypeBits, &mem_alloc, 0);
20397 if (!pass) {
20398 vkDestroyBuffer(m_device->device(), buffer, NULL);
20399 return;
20400 }
20401
20402 VkDeviceMemory mem;
20403 err = vkAllocateMemory(m_device->device(), &mem_alloc, NULL, &mem);
20404 ASSERT_VK_SUCCESS(err);
20405 err = vkBindBufferMemory(m_device->device(), buffer, mem, 0);
20406 ASSERT_VK_SUCCESS(err);
20407
20408 {
20409 VkCommandBufferBeginInfo begin_info{};
20410 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20411 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20412
20413 vkCmdResetQueryPool(command_buffer[0], query_pool, 0, 1);
20414 vkCmdWriteTimestamp(command_buffer[0], VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, query_pool, 0);
20415
20416 vkEndCommandBuffer(command_buffer[0]);
20417
20418 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20419
20420 vkCmdCopyQueryPoolResults(command_buffer[1], query_pool, 0, 1, buffer, 0, 0, 0);
20421
20422 vkEndCommandBuffer(command_buffer[1]);
20423 }
20424 {
20425 VkSubmitInfo submit_info{};
20426 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20427 submit_info.commandBufferCount = 2;
20428 submit_info.pCommandBuffers = command_buffer;
20429 submit_info.signalSemaphoreCount = 0;
20430 submit_info.pSignalSemaphores = nullptr;
20431 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20432 }
20433
20434 vkQueueWaitIdle(queue);
20435
20436 vkDestroyQueryPool(m_device->device(), query_pool, nullptr);
20437 vkFreeCommandBuffers(m_device->device(), command_pool, 2, command_buffer);
20438 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20439 vkDestroyBuffer(m_device->device(), buffer, NULL);
20440 vkFreeMemory(m_device->device(), mem, NULL);
20441
20442 m_errorMonitor->VerifyNotFound();
20443}
20444
Tony Barbourc46924f2016-11-04 11:49:52 -060020445TEST_F(VkLayerTest, ResetEventThenSet) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020446 TEST_DESCRIPTION("Reset an event then set it after the reset has been submitted.");
20447
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020448 ASSERT_NO_FATAL_FAILURE(InitState());
20449 VkEvent event;
20450 VkEventCreateInfo event_create_info{};
20451 event_create_info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO;
20452 vkCreateEvent(m_device->device(), &event_create_info, nullptr, &event);
20453
20454 VkCommandPool command_pool;
20455 VkCommandPoolCreateInfo pool_create_info{};
20456 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20457 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20458 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20459 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20460
20461 VkCommandBuffer command_buffer;
20462 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20463 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20464 command_buffer_allocate_info.commandPool = command_pool;
20465 command_buffer_allocate_info.commandBufferCount = 1;
20466 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20467 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, &command_buffer);
20468
20469 VkQueue queue = VK_NULL_HANDLE;
20470 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20471
20472 {
20473 VkCommandBufferBeginInfo begin_info{};
20474 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20475 vkBeginCommandBuffer(command_buffer, &begin_info);
20476
20477 vkCmdResetEvent(command_buffer, event, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020478 vkEndCommandBuffer(command_buffer);
20479 }
20480 {
20481 VkSubmitInfo submit_info{};
20482 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20483 submit_info.commandBufferCount = 1;
20484 submit_info.pCommandBuffers = &command_buffer;
20485 submit_info.signalSemaphoreCount = 0;
20486 submit_info.pSignalSemaphores = nullptr;
20487 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20488 }
20489 {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020490 m_errorMonitor->SetDesiredFailureMsg(VK_DEBUG_REPORT_ERROR_BIT_EXT,
20491 "that is already in use by a "
20492 "command buffer.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020493 vkSetEvent(m_device->device(), event);
20494 m_errorMonitor->VerifyFound();
20495 }
20496
20497 vkQueueWaitIdle(queue);
20498
20499 vkDestroyEvent(m_device->device(), event, nullptr);
20500 vkFreeCommandBuffers(m_device->device(), command_pool, 1, &command_buffer);
20501 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20502}
20503
20504// This is a positive test. No errors should be generated.
20505TEST_F(VkPositiveLayerTest, TwoFencesThreeFrames) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020506 TEST_DESCRIPTION(
20507 "Two command buffers with two separate fences are each "
20508 "run through a Submit & WaitForFences cycle 3 times. This "
20509 "previously revealed a bug so running this positive test "
20510 "to prevent a regression.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020511 m_errorMonitor->ExpectSuccess();
20512
20513 ASSERT_NO_FATAL_FAILURE(InitState());
20514 VkQueue queue = VK_NULL_HANDLE;
20515 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 0, &queue);
20516
20517 static const uint32_t NUM_OBJECTS = 2;
20518 static const uint32_t NUM_FRAMES = 3;
20519 VkCommandBuffer cmd_buffers[NUM_OBJECTS] = {};
20520 VkFence fences[NUM_OBJECTS] = {};
20521
20522 VkCommandPool cmd_pool;
20523 VkCommandPoolCreateInfo cmd_pool_ci = {};
20524 cmd_pool_ci.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20525 cmd_pool_ci.queueFamilyIndex = m_device->graphics_queue_node_index_;
20526 cmd_pool_ci.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20527 VkResult err = vkCreateCommandPool(m_device->device(), &cmd_pool_ci, nullptr, &cmd_pool);
20528 ASSERT_VK_SUCCESS(err);
20529
20530 VkCommandBufferAllocateInfo cmd_buf_info = {};
20531 cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20532 cmd_buf_info.commandPool = cmd_pool;
20533 cmd_buf_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20534 cmd_buf_info.commandBufferCount = 1;
20535
20536 VkFenceCreateInfo fence_ci = {};
20537 fence_ci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20538 fence_ci.pNext = nullptr;
20539 fence_ci.flags = 0;
20540
20541 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20542 err = vkAllocateCommandBuffers(m_device->device(), &cmd_buf_info, &cmd_buffers[i]);
20543 ASSERT_VK_SUCCESS(err);
20544 err = vkCreateFence(m_device->device(), &fence_ci, nullptr, &fences[i]);
20545 ASSERT_VK_SUCCESS(err);
20546 }
20547
20548 for (uint32_t frame = 0; frame < NUM_FRAMES; ++frame) {
20549 for (uint32_t obj = 0; obj < NUM_OBJECTS; ++obj) {
20550 // Create empty cmd buffer
20551 VkCommandBufferBeginInfo cmdBufBeginDesc = {};
20552 cmdBufBeginDesc.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20553
20554 err = vkBeginCommandBuffer(cmd_buffers[obj], &cmdBufBeginDesc);
20555 ASSERT_VK_SUCCESS(err);
20556 err = vkEndCommandBuffer(cmd_buffers[obj]);
20557 ASSERT_VK_SUCCESS(err);
20558
20559 VkSubmitInfo submit_info = {};
20560 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20561 submit_info.commandBufferCount = 1;
20562 submit_info.pCommandBuffers = &cmd_buffers[obj];
20563 // Submit cmd buffer and wait for fence
20564 err = vkQueueSubmit(queue, 1, &submit_info, fences[obj]);
20565 ASSERT_VK_SUCCESS(err);
20566 err = vkWaitForFences(m_device->device(), 1, &fences[obj], VK_TRUE, UINT64_MAX);
20567 ASSERT_VK_SUCCESS(err);
20568 err = vkResetFences(m_device->device(), 1, &fences[obj]);
20569 ASSERT_VK_SUCCESS(err);
20570 }
20571 }
20572 m_errorMonitor->VerifyNotFound();
20573 vkDestroyCommandPool(m_device->device(), cmd_pool, NULL);
20574 for (uint32_t i = 0; i < NUM_OBJECTS; ++i) {
20575 vkDestroyFence(m_device->device(), fences[i], nullptr);
20576 }
20577}
20578// This is a positive test. No errors should be generated.
20579TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWI) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020580 TEST_DESCRIPTION(
20581 "Two command buffers, each in a separate QueueSubmit call "
20582 "submitted on separate queues followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020583
20584 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020585 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020586
20587 m_errorMonitor->ExpectSuccess();
20588
20589 VkSemaphore semaphore;
20590 VkSemaphoreCreateInfo semaphore_create_info{};
20591 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20592 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20593
20594 VkCommandPool command_pool;
20595 VkCommandPoolCreateInfo pool_create_info{};
20596 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20597 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20598 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20599 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20600
20601 VkCommandBuffer command_buffer[2];
20602 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20603 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20604 command_buffer_allocate_info.commandPool = command_pool;
20605 command_buffer_allocate_info.commandBufferCount = 2;
20606 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20607 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20608
20609 VkQueue queue = VK_NULL_HANDLE;
20610 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20611
20612 {
20613 VkCommandBufferBeginInfo begin_info{};
20614 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20615 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20616
20617 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 -070020618 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020619
20620 VkViewport viewport{};
20621 viewport.maxDepth = 1.0f;
20622 viewport.minDepth = 0.0f;
20623 viewport.width = 512;
20624 viewport.height = 512;
20625 viewport.x = 0;
20626 viewport.y = 0;
20627 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20628 vkEndCommandBuffer(command_buffer[0]);
20629 }
20630 {
20631 VkCommandBufferBeginInfo begin_info{};
20632 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20633 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20634
20635 VkViewport viewport{};
20636 viewport.maxDepth = 1.0f;
20637 viewport.minDepth = 0.0f;
20638 viewport.width = 512;
20639 viewport.height = 512;
20640 viewport.x = 0;
20641 viewport.y = 0;
20642 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20643 vkEndCommandBuffer(command_buffer[1]);
20644 }
20645 {
20646 VkSubmitInfo submit_info{};
20647 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20648 submit_info.commandBufferCount = 1;
20649 submit_info.pCommandBuffers = &command_buffer[0];
20650 submit_info.signalSemaphoreCount = 1;
20651 submit_info.pSignalSemaphores = &semaphore;
20652 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20653 }
20654 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020655 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020656 VkSubmitInfo submit_info{};
20657 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20658 submit_info.commandBufferCount = 1;
20659 submit_info.pCommandBuffers = &command_buffer[1];
20660 submit_info.waitSemaphoreCount = 1;
20661 submit_info.pWaitSemaphores = &semaphore;
20662 submit_info.pWaitDstStageMask = flags;
20663 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
20664 }
20665
20666 vkQueueWaitIdle(m_device->m_queue);
20667
20668 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20669 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20670 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20671
20672 m_errorMonitor->VerifyNotFound();
20673}
20674
20675// This is a positive test. No errors should be generated.
20676TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceQWIFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020677 TEST_DESCRIPTION(
20678 "Two command buffers, each in a separate QueueSubmit call "
20679 "submitted on separate queues, the second having a fence"
20680 "followed by a QueueWaitIdle.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020681
20682 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020683 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020684
20685 m_errorMonitor->ExpectSuccess();
20686
20687 VkFence fence;
20688 VkFenceCreateInfo fence_create_info{};
20689 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20690 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20691
20692 VkSemaphore semaphore;
20693 VkSemaphoreCreateInfo semaphore_create_info{};
20694 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20695 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20696
20697 VkCommandPool command_pool;
20698 VkCommandPoolCreateInfo pool_create_info{};
20699 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20700 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20701 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20702 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20703
20704 VkCommandBuffer command_buffer[2];
20705 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20706 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20707 command_buffer_allocate_info.commandPool = command_pool;
20708 command_buffer_allocate_info.commandBufferCount = 2;
20709 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20710 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20711
20712 VkQueue queue = VK_NULL_HANDLE;
20713 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20714
20715 {
20716 VkCommandBufferBeginInfo begin_info{};
20717 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20718 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20719
20720 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 -070020721 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020722
20723 VkViewport viewport{};
20724 viewport.maxDepth = 1.0f;
20725 viewport.minDepth = 0.0f;
20726 viewport.width = 512;
20727 viewport.height = 512;
20728 viewport.x = 0;
20729 viewport.y = 0;
20730 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20731 vkEndCommandBuffer(command_buffer[0]);
20732 }
20733 {
20734 VkCommandBufferBeginInfo begin_info{};
20735 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20736 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20737
20738 VkViewport viewport{};
20739 viewport.maxDepth = 1.0f;
20740 viewport.minDepth = 0.0f;
20741 viewport.width = 512;
20742 viewport.height = 512;
20743 viewport.x = 0;
20744 viewport.y = 0;
20745 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20746 vkEndCommandBuffer(command_buffer[1]);
20747 }
20748 {
20749 VkSubmitInfo submit_info{};
20750 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20751 submit_info.commandBufferCount = 1;
20752 submit_info.pCommandBuffers = &command_buffer[0];
20753 submit_info.signalSemaphoreCount = 1;
20754 submit_info.pSignalSemaphores = &semaphore;
20755 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20756 }
20757 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020758 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020759 VkSubmitInfo submit_info{};
20760 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20761 submit_info.commandBufferCount = 1;
20762 submit_info.pCommandBuffers = &command_buffer[1];
20763 submit_info.waitSemaphoreCount = 1;
20764 submit_info.pWaitSemaphores = &semaphore;
20765 submit_info.pWaitDstStageMask = flags;
20766 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20767 }
20768
20769 vkQueueWaitIdle(m_device->m_queue);
20770
20771 vkDestroyFence(m_device->device(), fence, nullptr);
20772 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20773 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20774 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20775
20776 m_errorMonitor->VerifyNotFound();
20777}
20778
20779// This is a positive test. No errors should be generated.
20780TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFenceTwoWFF) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020781 TEST_DESCRIPTION(
20782 "Two command buffers, each in a separate QueueSubmit call "
20783 "submitted on separate queues, the second having a fence"
20784 "followed by two consecutive WaitForFences calls on the same fence.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020785
20786 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020787 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020788
20789 m_errorMonitor->ExpectSuccess();
20790
20791 VkFence fence;
20792 VkFenceCreateInfo fence_create_info{};
20793 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20794 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20795
20796 VkSemaphore semaphore;
20797 VkSemaphoreCreateInfo semaphore_create_info{};
20798 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20799 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20800
20801 VkCommandPool command_pool;
20802 VkCommandPoolCreateInfo pool_create_info{};
20803 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20804 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20805 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20806 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20807
20808 VkCommandBuffer command_buffer[2];
20809 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20810 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20811 command_buffer_allocate_info.commandPool = command_pool;
20812 command_buffer_allocate_info.commandBufferCount = 2;
20813 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20814 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20815
20816 VkQueue queue = VK_NULL_HANDLE;
20817 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20818
20819 {
20820 VkCommandBufferBeginInfo begin_info{};
20821 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20822 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20823
20824 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 -070020825 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020826
20827 VkViewport viewport{};
20828 viewport.maxDepth = 1.0f;
20829 viewport.minDepth = 0.0f;
20830 viewport.width = 512;
20831 viewport.height = 512;
20832 viewport.x = 0;
20833 viewport.y = 0;
20834 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
20835 vkEndCommandBuffer(command_buffer[0]);
20836 }
20837 {
20838 VkCommandBufferBeginInfo begin_info{};
20839 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20840 vkBeginCommandBuffer(command_buffer[1], &begin_info);
20841
20842 VkViewport viewport{};
20843 viewport.maxDepth = 1.0f;
20844 viewport.minDepth = 0.0f;
20845 viewport.width = 512;
20846 viewport.height = 512;
20847 viewport.x = 0;
20848 viewport.y = 0;
20849 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
20850 vkEndCommandBuffer(command_buffer[1]);
20851 }
20852 {
20853 VkSubmitInfo submit_info{};
20854 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20855 submit_info.commandBufferCount = 1;
20856 submit_info.pCommandBuffers = &command_buffer[0];
20857 submit_info.signalSemaphoreCount = 1;
20858 submit_info.pSignalSemaphores = &semaphore;
20859 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
20860 }
20861 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020862 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020863 VkSubmitInfo submit_info{};
20864 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
20865 submit_info.commandBufferCount = 1;
20866 submit_info.pCommandBuffers = &command_buffer[1];
20867 submit_info.waitSemaphoreCount = 1;
20868 submit_info.pWaitSemaphores = &semaphore;
20869 submit_info.pWaitDstStageMask = flags;
20870 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
20871 }
20872
20873 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20874 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
20875
20876 vkDestroyFence(m_device->device(), fence, nullptr);
20877 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
20878 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
20879 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
20880
20881 m_errorMonitor->VerifyNotFound();
20882}
20883
20884TEST_F(VkPositiveLayerTest, TwoQueuesEnsureCorrectRetirementWithWorkStolen) {
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020885 ASSERT_NO_FATAL_FAILURE(InitState());
20886 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070020887 printf(" Test requires two queues, skipping\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020888 return;
20889 }
20890
20891 VkResult err;
20892
20893 m_errorMonitor->ExpectSuccess();
20894
20895 VkQueue q0 = m_device->m_queue;
20896 VkQueue q1 = nullptr;
20897 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &q1);
20898 ASSERT_NE(q1, nullptr);
20899
20900 // An (empty) command buffer. We must have work in the first submission --
20901 // the layer treats unfenced work differently from fenced work.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020902 VkCommandPoolCreateInfo cpci = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, nullptr, 0, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020903 VkCommandPool pool;
20904 err = vkCreateCommandPool(m_device->device(), &cpci, nullptr, &pool);
20905 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020906 VkCommandBufferAllocateInfo cbai = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, nullptr, pool,
20907 VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020908 VkCommandBuffer cb;
20909 err = vkAllocateCommandBuffers(m_device->device(), &cbai, &cb);
20910 ASSERT_VK_SUCCESS(err);
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020911 VkCommandBufferBeginInfo cbbi = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020912 err = vkBeginCommandBuffer(cb, &cbbi);
20913 ASSERT_VK_SUCCESS(err);
20914 err = vkEndCommandBuffer(cb);
20915 ASSERT_VK_SUCCESS(err);
20916
20917 // A semaphore
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020918 VkSemaphoreCreateInfo sci = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020919 VkSemaphore s;
20920 err = vkCreateSemaphore(m_device->device(), &sci, nullptr, &s);
20921 ASSERT_VK_SUCCESS(err);
20922
20923 // First submission, to q0
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020924 VkSubmitInfo s0 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr, 1, &cb, 1, &s};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020925
20926 err = vkQueueSubmit(q0, 1, &s0, VK_NULL_HANDLE);
20927 ASSERT_VK_SUCCESS(err);
20928
20929 // Second submission, to q1, waiting on s
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020930 VkFlags waitmask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; // doesn't really matter what this value is.
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070020931 VkSubmitInfo s1 = {VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 1, &s, &waitmask, 0, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020932
20933 err = vkQueueSubmit(q1, 1, &s1, VK_NULL_HANDLE);
20934 ASSERT_VK_SUCCESS(err);
20935
20936 // Wait for q0 idle
20937 err = vkQueueWaitIdle(q0);
20938 ASSERT_VK_SUCCESS(err);
20939
20940 // Command buffer should have been completed (it was on q0); reset the pool.
20941 vkFreeCommandBuffers(m_device->device(), pool, 1, &cb);
20942
20943 m_errorMonitor->VerifyNotFound();
20944
20945 // Force device completely idle and clean up resources
20946 vkDeviceWaitIdle(m_device->device());
20947 vkDestroyCommandPool(m_device->device(), pool, nullptr);
20948 vkDestroySemaphore(m_device->device(), s, nullptr);
20949}
20950
20951// This is a positive test. No errors should be generated.
20952TEST_F(VkPositiveLayerTest, TwoQueueSubmitsSeparateQueuesWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020953 TEST_DESCRIPTION(
20954 "Two command buffers, each in a separate QueueSubmit call "
20955 "submitted on separate queues, the second having a fence, "
20956 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020957
20958 ASSERT_NO_FATAL_FAILURE(InitState());
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070020959 if ((m_device->queue_props.empty()) || (m_device->queue_props[0].queueCount < 2)) return;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020960
20961 m_errorMonitor->ExpectSuccess();
20962
20963 ASSERT_NO_FATAL_FAILURE(InitState());
20964 VkFence fence;
20965 VkFenceCreateInfo fence_create_info{};
20966 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
20967 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
20968
20969 VkSemaphore semaphore;
20970 VkSemaphoreCreateInfo semaphore_create_info{};
20971 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
20972 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
20973
20974 VkCommandPool command_pool;
20975 VkCommandPoolCreateInfo pool_create_info{};
20976 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
20977 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
20978 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
20979 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
20980
20981 VkCommandBuffer command_buffer[2];
20982 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
20983 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
20984 command_buffer_allocate_info.commandPool = command_pool;
20985 command_buffer_allocate_info.commandBufferCount = 2;
20986 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
20987 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
20988
20989 VkQueue queue = VK_NULL_HANDLE;
20990 vkGetDeviceQueue(m_device->device(), m_device->graphics_queue_node_index_, 1, &queue);
20991
20992 {
20993 VkCommandBufferBeginInfo begin_info{};
20994 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
20995 vkBeginCommandBuffer(command_buffer[0], &begin_info);
20996
20997 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 -070020998 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060020999
21000 VkViewport viewport{};
21001 viewport.maxDepth = 1.0f;
21002 viewport.minDepth = 0.0f;
21003 viewport.width = 512;
21004 viewport.height = 512;
21005 viewport.x = 0;
21006 viewport.y = 0;
21007 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21008 vkEndCommandBuffer(command_buffer[0]);
21009 }
21010 {
21011 VkCommandBufferBeginInfo begin_info{};
21012 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21013 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21014
21015 VkViewport viewport{};
21016 viewport.maxDepth = 1.0f;
21017 viewport.minDepth = 0.0f;
21018 viewport.width = 512;
21019 viewport.height = 512;
21020 viewport.x = 0;
21021 viewport.y = 0;
21022 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21023 vkEndCommandBuffer(command_buffer[1]);
21024 }
21025 {
21026 VkSubmitInfo submit_info{};
21027 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21028 submit_info.commandBufferCount = 1;
21029 submit_info.pCommandBuffers = &command_buffer[0];
21030 submit_info.signalSemaphoreCount = 1;
21031 submit_info.pSignalSemaphores = &semaphore;
21032 vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
21033 }
21034 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021035 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021036 VkSubmitInfo submit_info{};
21037 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21038 submit_info.commandBufferCount = 1;
21039 submit_info.pCommandBuffers = &command_buffer[1];
21040 submit_info.waitSemaphoreCount = 1;
21041 submit_info.pWaitSemaphores = &semaphore;
21042 submit_info.pWaitDstStageMask = flags;
21043 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21044 }
21045
21046 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21047
21048 vkDestroyFence(m_device->device(), fence, nullptr);
21049 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21050 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21051 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21052
21053 m_errorMonitor->VerifyNotFound();
21054}
21055
21056// This is a positive test. No errors should be generated.
21057TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueWithSemaphoreAndOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021058 TEST_DESCRIPTION(
21059 "Two command buffers, each in a separate QueueSubmit call "
21060 "on the same queue, sharing a signal/wait semaphore, the "
21061 "second having a fence, "
21062 "followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021063
21064 m_errorMonitor->ExpectSuccess();
21065
21066 ASSERT_NO_FATAL_FAILURE(InitState());
21067 VkFence fence;
21068 VkFenceCreateInfo fence_create_info{};
21069 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21070 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21071
21072 VkSemaphore semaphore;
21073 VkSemaphoreCreateInfo semaphore_create_info{};
21074 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21075 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21076
21077 VkCommandPool command_pool;
21078 VkCommandPoolCreateInfo pool_create_info{};
21079 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21080 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21081 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21082 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21083
21084 VkCommandBuffer command_buffer[2];
21085 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21086 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21087 command_buffer_allocate_info.commandPool = command_pool;
21088 command_buffer_allocate_info.commandBufferCount = 2;
21089 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21090 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21091
21092 {
21093 VkCommandBufferBeginInfo begin_info{};
21094 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21095 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21096
21097 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 -070021098 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021099
21100 VkViewport viewport{};
21101 viewport.maxDepth = 1.0f;
21102 viewport.minDepth = 0.0f;
21103 viewport.width = 512;
21104 viewport.height = 512;
21105 viewport.x = 0;
21106 viewport.y = 0;
21107 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21108 vkEndCommandBuffer(command_buffer[0]);
21109 }
21110 {
21111 VkCommandBufferBeginInfo begin_info{};
21112 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21113 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21114
21115 VkViewport viewport{};
21116 viewport.maxDepth = 1.0f;
21117 viewport.minDepth = 0.0f;
21118 viewport.width = 512;
21119 viewport.height = 512;
21120 viewport.x = 0;
21121 viewport.y = 0;
21122 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21123 vkEndCommandBuffer(command_buffer[1]);
21124 }
21125 {
21126 VkSubmitInfo submit_info{};
21127 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21128 submit_info.commandBufferCount = 1;
21129 submit_info.pCommandBuffers = &command_buffer[0];
21130 submit_info.signalSemaphoreCount = 1;
21131 submit_info.pSignalSemaphores = &semaphore;
21132 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21133 }
21134 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021135 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021136 VkSubmitInfo submit_info{};
21137 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21138 submit_info.commandBufferCount = 1;
21139 submit_info.pCommandBuffers = &command_buffer[1];
21140 submit_info.waitSemaphoreCount = 1;
21141 submit_info.pWaitSemaphores = &semaphore;
21142 submit_info.pWaitDstStageMask = flags;
21143 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21144 }
21145
21146 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21147
21148 vkDestroyFence(m_device->device(), fence, nullptr);
21149 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21150 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21151 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21152
21153 m_errorMonitor->VerifyNotFound();
21154}
21155
21156// This is a positive test. No errors should be generated.
21157TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueNullQueueSubmitWithFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021158 TEST_DESCRIPTION(
21159 "Two command buffers, each in a separate QueueSubmit call "
21160 "on the same queue, no fences, followed by a third QueueSubmit with NO "
21161 "SubmitInfos but with a fence, followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021162
21163 m_errorMonitor->ExpectSuccess();
21164
21165 ASSERT_NO_FATAL_FAILURE(InitState());
21166 VkFence fence;
21167 VkFenceCreateInfo fence_create_info{};
21168 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21169 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21170
21171 VkCommandPool command_pool;
21172 VkCommandPoolCreateInfo pool_create_info{};
21173 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21174 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21175 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21176 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21177
21178 VkCommandBuffer command_buffer[2];
21179 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21180 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21181 command_buffer_allocate_info.commandPool = command_pool;
21182 command_buffer_allocate_info.commandBufferCount = 2;
21183 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21184 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
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 = 0;
21225 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21226 vkQueueSubmit(m_device->m_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 = 0;
21235 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21236 submit_info.pWaitDstStageMask = flags;
21237 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21238 }
21239
21240 vkQueueSubmit(m_device->m_queue, 0, NULL, fence);
21241
21242 VkResult err = vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21243 ASSERT_VK_SUCCESS(err);
21244
21245 vkDestroyFence(m_device->device(), fence, nullptr);
21246 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21247 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21248
21249 m_errorMonitor->VerifyNotFound();
21250}
21251
21252// This is a positive test. No errors should be generated.
21253TEST_F(VkPositiveLayerTest, TwoQueueSubmitsOneQueueOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021254 TEST_DESCRIPTION(
21255 "Two command buffers, each in a separate QueueSubmit call "
21256 "on the same queue, the second having a fence, followed "
21257 "by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021258
21259 m_errorMonitor->ExpectSuccess();
21260
21261 ASSERT_NO_FATAL_FAILURE(InitState());
21262 VkFence fence;
21263 VkFenceCreateInfo fence_create_info{};
21264 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21265 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21266
21267 VkCommandPool command_pool;
21268 VkCommandPoolCreateInfo pool_create_info{};
21269 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21270 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21271 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21272 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21273
21274 VkCommandBuffer command_buffer[2];
21275 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21276 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21277 command_buffer_allocate_info.commandPool = command_pool;
21278 command_buffer_allocate_info.commandBufferCount = 2;
21279 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21280 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21281
21282 {
21283 VkCommandBufferBeginInfo begin_info{};
21284 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21285 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21286
21287 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 -070021288 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021289
21290 VkViewport viewport{};
21291 viewport.maxDepth = 1.0f;
21292 viewport.minDepth = 0.0f;
21293 viewport.width = 512;
21294 viewport.height = 512;
21295 viewport.x = 0;
21296 viewport.y = 0;
21297 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21298 vkEndCommandBuffer(command_buffer[0]);
21299 }
21300 {
21301 VkCommandBufferBeginInfo begin_info{};
21302 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21303 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21304
21305 VkViewport viewport{};
21306 viewport.maxDepth = 1.0f;
21307 viewport.minDepth = 0.0f;
21308 viewport.width = 512;
21309 viewport.height = 512;
21310 viewport.x = 0;
21311 viewport.y = 0;
21312 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21313 vkEndCommandBuffer(command_buffer[1]);
21314 }
21315 {
21316 VkSubmitInfo submit_info{};
21317 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21318 submit_info.commandBufferCount = 1;
21319 submit_info.pCommandBuffers = &command_buffer[0];
21320 submit_info.signalSemaphoreCount = 0;
21321 submit_info.pSignalSemaphores = VK_NULL_HANDLE;
21322 vkQueueSubmit(m_device->m_queue, 1, &submit_info, VK_NULL_HANDLE);
21323 }
21324 {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021325 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021326 VkSubmitInfo submit_info{};
21327 submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21328 submit_info.commandBufferCount = 1;
21329 submit_info.pCommandBuffers = &command_buffer[1];
21330 submit_info.waitSemaphoreCount = 0;
21331 submit_info.pWaitSemaphores = VK_NULL_HANDLE;
21332 submit_info.pWaitDstStageMask = flags;
21333 vkQueueSubmit(m_device->m_queue, 1, &submit_info, fence);
21334 }
21335
21336 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21337
21338 vkDestroyFence(m_device->device(), fence, nullptr);
21339 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21340 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21341
21342 m_errorMonitor->VerifyNotFound();
21343}
21344
21345// This is a positive test. No errors should be generated.
21346TEST_F(VkPositiveLayerTest, TwoSubmitInfosWithSemaphoreOneQueueSubmitsOneFence) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021347 TEST_DESCRIPTION(
21348 "Two command buffers each in a separate SubmitInfo sent in a single "
21349 "QueueSubmit call followed by a WaitForFences call.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021350 ASSERT_NO_FATAL_FAILURE(InitState());
21351
21352 m_errorMonitor->ExpectSuccess();
21353
21354 VkFence fence;
21355 VkFenceCreateInfo fence_create_info{};
21356 fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
21357 vkCreateFence(m_device->device(), &fence_create_info, nullptr, &fence);
21358
21359 VkSemaphore semaphore;
21360 VkSemaphoreCreateInfo semaphore_create_info{};
21361 semaphore_create_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
21362 vkCreateSemaphore(m_device->device(), &semaphore_create_info, nullptr, &semaphore);
21363
21364 VkCommandPool command_pool;
21365 VkCommandPoolCreateInfo pool_create_info{};
21366 pool_create_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
21367 pool_create_info.queueFamilyIndex = m_device->graphics_queue_node_index_;
21368 pool_create_info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
21369 vkCreateCommandPool(m_device->device(), &pool_create_info, nullptr, &command_pool);
21370
21371 VkCommandBuffer command_buffer[2];
21372 VkCommandBufferAllocateInfo command_buffer_allocate_info{};
21373 command_buffer_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
21374 command_buffer_allocate_info.commandPool = command_pool;
21375 command_buffer_allocate_info.commandBufferCount = 2;
21376 command_buffer_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
21377 vkAllocateCommandBuffers(m_device->device(), &command_buffer_allocate_info, command_buffer);
21378
21379 {
21380 VkCommandBufferBeginInfo begin_info{};
21381 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21382 vkBeginCommandBuffer(command_buffer[0], &begin_info);
21383
21384 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 -070021385 nullptr, 0, nullptr, 0, nullptr);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021386
21387 VkViewport viewport{};
21388 viewport.maxDepth = 1.0f;
21389 viewport.minDepth = 0.0f;
21390 viewport.width = 512;
21391 viewport.height = 512;
21392 viewport.x = 0;
21393 viewport.y = 0;
21394 vkCmdSetViewport(command_buffer[0], 0, 1, &viewport);
21395 vkEndCommandBuffer(command_buffer[0]);
21396 }
21397 {
21398 VkCommandBufferBeginInfo begin_info{};
21399 begin_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
21400 vkBeginCommandBuffer(command_buffer[1], &begin_info);
21401
21402 VkViewport viewport{};
21403 viewport.maxDepth = 1.0f;
21404 viewport.minDepth = 0.0f;
21405 viewport.width = 512;
21406 viewport.height = 512;
21407 viewport.x = 0;
21408 viewport.y = 0;
21409 vkCmdSetViewport(command_buffer[1], 0, 1, &viewport);
21410 vkEndCommandBuffer(command_buffer[1]);
21411 }
21412 {
21413 VkSubmitInfo submit_info[2];
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021414 VkPipelineStageFlags flags[]{VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021415
21416 submit_info[0].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21417 submit_info[0].pNext = NULL;
21418 submit_info[0].commandBufferCount = 1;
21419 submit_info[0].pCommandBuffers = &command_buffer[0];
21420 submit_info[0].signalSemaphoreCount = 1;
21421 submit_info[0].pSignalSemaphores = &semaphore;
21422 submit_info[0].waitSemaphoreCount = 0;
21423 submit_info[0].pWaitSemaphores = NULL;
21424 submit_info[0].pWaitDstStageMask = 0;
21425
21426 submit_info[1].sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
21427 submit_info[1].pNext = NULL;
21428 submit_info[1].commandBufferCount = 1;
21429 submit_info[1].pCommandBuffers = &command_buffer[1];
21430 submit_info[1].waitSemaphoreCount = 1;
21431 submit_info[1].pWaitSemaphores = &semaphore;
21432 submit_info[1].pWaitDstStageMask = flags;
21433 submit_info[1].signalSemaphoreCount = 0;
21434 submit_info[1].pSignalSemaphores = NULL;
21435 vkQueueSubmit(m_device->m_queue, 2, &submit_info[0], fence);
21436 }
21437
21438 vkWaitForFences(m_device->device(), 1, &fence, VK_TRUE, UINT64_MAX);
21439
21440 vkDestroyFence(m_device->device(), fence, nullptr);
21441 vkFreeCommandBuffers(m_device->device(), command_pool, 2, &command_buffer[0]);
21442 vkDestroyCommandPool(m_device->device(), command_pool, NULL);
21443 vkDestroySemaphore(m_device->device(), semaphore, nullptr);
21444
21445 m_errorMonitor->VerifyNotFound();
21446}
21447
21448TEST_F(VkPositiveLayerTest, RenderPassSecondaryCommandBuffersMultipleTimes) {
21449 m_errorMonitor->ExpectSuccess();
21450
21451 ASSERT_NO_FATAL_FAILURE(InitState());
21452 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21453
Tony Barbour552f6c02016-12-21 14:34:07 -070021454 m_commandBuffer->BeginCommandBuffer();
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021455
21456 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
21457 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21458 m_errorMonitor->VerifyNotFound();
21459 vkCmdBeginRenderPass(m_commandBuffer->GetBufferHandle(), &m_renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
21460 m_errorMonitor->VerifyNotFound();
21461 vkCmdEndRenderPass(m_commandBuffer->GetBufferHandle());
21462 m_errorMonitor->VerifyNotFound();
21463
21464 m_commandBuffer->EndCommandBuffer();
21465 m_errorMonitor->VerifyNotFound();
21466}
21467
21468TEST_F(VkPositiveLayerTest, ValidRenderPassAttachmentLayoutWithLoadOp) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021469 TEST_DESCRIPTION(
21470 "Positive test where we create a renderpass with an "
21471 "attachment that uses LOAD_OP_CLEAR, the first subpass "
21472 "has a valid layout, and a second subpass then uses a "
21473 "valid *READ_ONLY* layout.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021474 m_errorMonitor->ExpectSuccess();
21475 ASSERT_NO_FATAL_FAILURE(InitState());
Tony Barbourf887b162017-03-09 10:06:46 -070021476 auto depth_format = find_depth_stencil_format(m_device);
21477 if (!depth_format) {
21478 printf(" No Depth + Stencil format found. Skipped.\n");
21479 return;
21480 }
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021481
21482 VkAttachmentReference attach[2] = {};
21483 attach[0].attachment = 0;
21484 attach[0].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21485 attach[1].attachment = 0;
21486 attach[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21487 VkSubpassDescription subpasses[2] = {};
21488 // First subpass clears DS attach on load
21489 subpasses[0].pDepthStencilAttachment = &attach[0];
21490 // 2nd subpass reads in DS as input attachment
21491 subpasses[1].inputAttachmentCount = 1;
21492 subpasses[1].pInputAttachments = &attach[1];
21493 VkAttachmentDescription attach_desc = {};
Tony Barbourf887b162017-03-09 10:06:46 -070021494 attach_desc.format = depth_format;
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021495 attach_desc.samples = VK_SAMPLE_COUNT_1_BIT;
21496 attach_desc.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
21497 attach_desc.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
21498 attach_desc.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21499 attach_desc.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
21500 attach_desc.initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
21501 attach_desc.finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL;
21502 VkRenderPassCreateInfo rpci = {};
21503 rpci.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
21504 rpci.attachmentCount = 1;
21505 rpci.pAttachments = &attach_desc;
21506 rpci.subpassCount = 2;
21507 rpci.pSubpasses = subpasses;
21508
21509 // Now create RenderPass and verify no errors
21510 VkRenderPass rp;
21511 vkCreateRenderPass(m_device->device(), &rpci, NULL, &rp);
21512 m_errorMonitor->VerifyNotFound();
21513
21514 vkDestroyRenderPass(m_device->device(), rp, NULL);
21515}
21516
Tobin Ehlis01103de2017-02-16 13:22:47 -070021517TEST_F(VkPositiveLayerTest, RenderPassDepthStencilLayoutTransition) {
21518 TEST_DESCRIPTION(
21519 "Create a render pass with depth-stencil attachment where layout transition "
21520 "from UNDEFINED TO DS_READ_ONLY_OPTIMAL is set by render pass and verify that "
21521 "transition has correctly occurred at queue submit time with no validation errors.");
21522
Tony Barbourf887b162017-03-09 10:06:46 -070021523 ASSERT_NO_FATAL_FAILURE(InitState());
21524 auto depth_format = find_depth_stencil_format(m_device);
21525 if (!depth_format) {
21526 printf(" No Depth + Stencil format found. Skipped.\n");
21527 return;
21528 }
Tobin Ehlis01103de2017-02-16 13:22:47 -070021529 VkImageFormatProperties format_props;
Tony Barbourf887b162017-03-09 10:06:46 -070021530 vkGetPhysicalDeviceImageFormatProperties(gpu(), depth_format, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021531 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, 0, &format_props);
21532 if (format_props.maxExtent.width < 32 || format_props.maxExtent.height < 32) {
Tony Barbourf887b162017-03-09 10:06:46 -070021533 printf("Depth extent too small, RenderPassDepthStencilLayoutTransition skipped.\n");
Tobin Ehlis01103de2017-02-16 13:22:47 -070021534 return;
21535 }
21536
21537 m_errorMonitor->ExpectSuccess();
Tobin Ehlis01103de2017-02-16 13:22:47 -070021538 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21539
21540 // A renderpass with one depth/stencil attachment.
21541 VkAttachmentDescription attachment = {0,
Tony Barbourf887b162017-03-09 10:06:46 -070021542 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021543 VK_SAMPLE_COUNT_1_BIT,
21544 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21545 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21546 VK_ATTACHMENT_LOAD_OP_DONT_CARE,
21547 VK_ATTACHMENT_STORE_OP_DONT_CARE,
21548 VK_IMAGE_LAYOUT_UNDEFINED,
21549 VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21550
21551 VkAttachmentReference att_ref = {0, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL};
21552
21553 VkSubpassDescription subpass = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 0, nullptr, 0, nullptr, nullptr, &att_ref, 0, nullptr};
21554
21555 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 1, &attachment, 1, &subpass, 0, nullptr};
21556
21557 VkRenderPass rp;
21558 VkResult err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
21559 ASSERT_VK_SUCCESS(err);
21560 // A compatible ds image.
21561 VkImageObj image(m_device);
Tony Barbourf887b162017-03-09 10:06:46 -070021562 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 -070021563 ASSERT_TRUE(image.initialized());
21564
21565 VkImageViewCreateInfo ivci = {
21566 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
21567 nullptr,
21568 0,
21569 image.handle(),
21570 VK_IMAGE_VIEW_TYPE_2D,
Tony Barbourf887b162017-03-09 10:06:46 -070021571 depth_format,
Tobin Ehlis01103de2017-02-16 13:22:47 -070021572 {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
21573 VK_COMPONENT_SWIZZLE_IDENTITY},
21574 {VK_IMAGE_ASPECT_DEPTH_BIT, 0, 1, 0, 1},
21575 };
21576 VkImageView view;
21577 err = vkCreateImageView(m_device->device(), &ivci, nullptr, &view);
21578 ASSERT_VK_SUCCESS(err);
21579
21580 VkFramebufferCreateInfo fci = {VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, nullptr, 0, rp, 1, &view, 32, 32, 1};
21581 VkFramebuffer fb;
21582 err = vkCreateFramebuffer(m_device->device(), &fci, nullptr, &fb);
21583 ASSERT_VK_SUCCESS(err);
21584
21585 VkRenderPassBeginInfo rpbi = {VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, nullptr, rp, fb, {{0, 0}, {32, 32}}, 0, nullptr};
21586 m_commandBuffer->BeginCommandBuffer();
21587 vkCmdBeginRenderPass(m_commandBuffer->handle(), &rpbi, VK_SUBPASS_CONTENTS_INLINE);
21588 vkCmdEndRenderPass(m_commandBuffer->handle());
21589 m_commandBuffer->EndCommandBuffer();
21590 QueueCommandBuffer(false);
21591 m_errorMonitor->VerifyNotFound();
21592
21593 // Cleanup
21594 vkDestroyImageView(m_device->device(), view, NULL);
21595 vkDestroyRenderPass(m_device->device(), rp, NULL);
21596 vkDestroyFramebuffer(m_device->device(), fb, NULL);
21597}
21598
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021599TEST_F(VkPositiveLayerTest, CreatePipelineAttribMatrixType) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021600 TEST_DESCRIPTION(
21601 "Test that pipeline validation accepts matrices passed "
21602 "as vertex attributes");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021603 m_errorMonitor->ExpectSuccess();
21604
21605 ASSERT_NO_FATAL_FAILURE(InitState());
21606 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21607
21608 VkVertexInputBindingDescription input_binding;
21609 memset(&input_binding, 0, sizeof(input_binding));
21610
21611 VkVertexInputAttributeDescription input_attribs[2];
21612 memset(input_attribs, 0, sizeof(input_attribs));
21613
21614 for (int i = 0; i < 2; i++) {
21615 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21616 input_attribs[i].location = i;
21617 }
21618
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021619 char const *vsSource =
21620 "#version 450\n"
21621 "\n"
21622 "layout(location=0) in mat2x4 x;\n"
21623 "out gl_PerVertex {\n"
21624 " vec4 gl_Position;\n"
21625 "};\n"
21626 "void main(){\n"
21627 " gl_Position = x[0] + x[1];\n"
21628 "}\n";
21629 char const *fsSource =
21630 "#version 450\n"
21631 "\n"
21632 "layout(location=0) out vec4 color;\n"
21633 "void main(){\n"
21634 " color = vec4(1);\n"
21635 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021636
21637 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21638 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21639
21640 VkPipelineObj pipe(m_device);
21641 pipe.AddColorAttachment();
21642 pipe.AddShader(&vs);
21643 pipe.AddShader(&fs);
21644
21645 pipe.AddVertexInputBindings(&input_binding, 1);
21646 pipe.AddVertexInputAttribs(input_attribs, 2);
21647
21648 VkDescriptorSetObj descriptorSet(m_device);
21649 descriptorSet.AppendDummy();
21650 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21651
21652 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21653
21654 /* expect success */
21655 m_errorMonitor->VerifyNotFound();
21656}
21657
21658TEST_F(VkPositiveLayerTest, CreatePipelineAttribArrayType) {
21659 m_errorMonitor->ExpectSuccess();
21660
21661 ASSERT_NO_FATAL_FAILURE(InitState());
21662 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21663
21664 VkVertexInputBindingDescription input_binding;
21665 memset(&input_binding, 0, sizeof(input_binding));
21666
21667 VkVertexInputAttributeDescription input_attribs[2];
21668 memset(input_attribs, 0, sizeof(input_attribs));
21669
21670 for (int i = 0; i < 2; i++) {
21671 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21672 input_attribs[i].location = i;
21673 }
21674
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021675 char const *vsSource =
21676 "#version 450\n"
21677 "\n"
21678 "layout(location=0) in vec4 x[2];\n"
21679 "out gl_PerVertex {\n"
21680 " vec4 gl_Position;\n"
21681 "};\n"
21682 "void main(){\n"
21683 " gl_Position = x[0] + x[1];\n"
21684 "}\n";
21685 char const *fsSource =
21686 "#version 450\n"
21687 "\n"
21688 "layout(location=0) out vec4 color;\n"
21689 "void main(){\n"
21690 " color = vec4(1);\n"
21691 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021692
21693 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21694 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21695
21696 VkPipelineObj pipe(m_device);
21697 pipe.AddColorAttachment();
21698 pipe.AddShader(&vs);
21699 pipe.AddShader(&fs);
21700
21701 pipe.AddVertexInputBindings(&input_binding, 1);
21702 pipe.AddVertexInputAttribs(input_attribs, 2);
21703
21704 VkDescriptorSetObj descriptorSet(m_device);
21705 descriptorSet.AppendDummy();
21706 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21707
21708 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21709
21710 m_errorMonitor->VerifyNotFound();
21711}
21712
21713TEST_F(VkPositiveLayerTest, CreatePipelineAttribComponents) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021714 TEST_DESCRIPTION(
21715 "Test that pipeline validation accepts consuming a vertex attribute "
21716 "through multiple vertex shader inputs, each consuming a different "
21717 "subset of the components.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021718 m_errorMonitor->ExpectSuccess();
21719
21720 ASSERT_NO_FATAL_FAILURE(InitState());
21721 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21722
21723 VkVertexInputBindingDescription input_binding;
21724 memset(&input_binding, 0, sizeof(input_binding));
21725
21726 VkVertexInputAttributeDescription input_attribs[3];
21727 memset(input_attribs, 0, sizeof(input_attribs));
21728
21729 for (int i = 0; i < 3; i++) {
21730 input_attribs[i].format = VK_FORMAT_R32G32B32A32_SFLOAT;
21731 input_attribs[i].location = i;
21732 }
21733
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021734 char const *vsSource =
21735 "#version 450\n"
21736 "\n"
21737 "layout(location=0) in vec4 x;\n"
21738 "layout(location=1) in vec3 y1;\n"
21739 "layout(location=1, component=3) in float y2;\n"
21740 "layout(location=2) in vec4 z;\n"
21741 "out gl_PerVertex {\n"
21742 " vec4 gl_Position;\n"
21743 "};\n"
21744 "void main(){\n"
21745 " gl_Position = x + vec4(y1, y2) + z;\n"
21746 "}\n";
21747 char const *fsSource =
21748 "#version 450\n"
21749 "\n"
21750 "layout(location=0) out vec4 color;\n"
21751 "void main(){\n"
21752 " color = vec4(1);\n"
21753 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021754
21755 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21756 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21757
21758 VkPipelineObj pipe(m_device);
21759 pipe.AddColorAttachment();
21760 pipe.AddShader(&vs);
21761 pipe.AddShader(&fs);
21762
21763 pipe.AddVertexInputBindings(&input_binding, 1);
21764 pipe.AddVertexInputAttribs(input_attribs, 3);
21765
21766 VkDescriptorSetObj descriptorSet(m_device);
21767 descriptorSet.AppendDummy();
21768 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21769
21770 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21771
21772 m_errorMonitor->VerifyNotFound();
21773}
21774
21775TEST_F(VkPositiveLayerTest, CreatePipelineSimplePositive) {
21776 m_errorMonitor->ExpectSuccess();
21777
21778 ASSERT_NO_FATAL_FAILURE(InitState());
21779 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21780
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021781 char const *vsSource =
21782 "#version 450\n"
21783 "out gl_PerVertex {\n"
21784 " vec4 gl_Position;\n"
21785 "};\n"
21786 "void main(){\n"
21787 " gl_Position = vec4(0);\n"
21788 "}\n";
21789 char const *fsSource =
21790 "#version 450\n"
21791 "\n"
21792 "layout(location=0) out vec4 color;\n"
21793 "void main(){\n"
21794 " color = vec4(1);\n"
21795 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021796
21797 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21798 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21799
21800 VkPipelineObj pipe(m_device);
21801 pipe.AddColorAttachment();
21802 pipe.AddShader(&vs);
21803 pipe.AddShader(&fs);
21804
21805 VkDescriptorSetObj descriptorSet(m_device);
21806 descriptorSet.AppendDummy();
21807 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21808
21809 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21810
21811 m_errorMonitor->VerifyNotFound();
21812}
21813
21814TEST_F(VkPositiveLayerTest, CreatePipelineRelaxedTypeMatch) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021815 TEST_DESCRIPTION(
21816 "Test that pipeline validation accepts the relaxed type matching rules "
21817 "set out in 14.1.3: fundamental type must match, and producer side must "
21818 "have at least as many components");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021819 m_errorMonitor->ExpectSuccess();
21820
21821 // VK 1.0.8 Specification, 14.1.3 "Additionally,..." block
21822
21823 ASSERT_NO_FATAL_FAILURE(InitState());
21824 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21825
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021826 char const *vsSource =
21827 "#version 450\n"
21828 "out gl_PerVertex {\n"
21829 " vec4 gl_Position;\n"
21830 "};\n"
21831 "layout(location=0) out vec3 x;\n"
21832 "layout(location=1) out ivec3 y;\n"
21833 "layout(location=2) out vec3 z;\n"
21834 "void main(){\n"
21835 " gl_Position = vec4(0);\n"
21836 " x = vec3(0); y = ivec3(0); z = vec3(0);\n"
21837 "}\n";
21838 char const *fsSource =
21839 "#version 450\n"
21840 "\n"
21841 "layout(location=0) out vec4 color;\n"
21842 "layout(location=0) in float x;\n"
21843 "layout(location=1) flat in int y;\n"
21844 "layout(location=2) in vec2 z;\n"
21845 "void main(){\n"
21846 " color = vec4(1 + x + y + z.x);\n"
21847 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021848
21849 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21850 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21851
21852 VkPipelineObj pipe(m_device);
21853 pipe.AddColorAttachment();
21854 pipe.AddShader(&vs);
21855 pipe.AddShader(&fs);
21856
21857 VkDescriptorSetObj descriptorSet(m_device);
21858 descriptorSet.AppendDummy();
21859 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21860
21861 VkResult err = VK_SUCCESS;
21862 err = pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21863 ASSERT_VK_SUCCESS(err);
21864
21865 m_errorMonitor->VerifyNotFound();
21866}
21867
21868TEST_F(VkPositiveLayerTest, CreatePipelineTessPerVertex) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021869 TEST_DESCRIPTION(
21870 "Test that pipeline validation accepts per-vertex variables "
21871 "passed between the TCS and TES stages");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021872 m_errorMonitor->ExpectSuccess();
21873
21874 ASSERT_NO_FATAL_FAILURE(InitState());
21875 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21876
21877 if (!m_device->phy().features().tessellationShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021878 printf(" Device does not support tessellation shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021879 return;
21880 }
21881
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021882 char const *vsSource =
21883 "#version 450\n"
21884 "void main(){}\n";
21885 char const *tcsSource =
21886 "#version 450\n"
21887 "layout(location=0) out int x[];\n"
21888 "layout(vertices=3) out;\n"
21889 "void main(){\n"
21890 " gl_TessLevelOuter[0] = gl_TessLevelOuter[1] = gl_TessLevelOuter[2] = 1;\n"
21891 " gl_TessLevelInner[0] = 1;\n"
21892 " x[gl_InvocationID] = gl_InvocationID;\n"
21893 "}\n";
21894 char const *tesSource =
21895 "#version 450\n"
21896 "layout(triangles, equal_spacing, cw) in;\n"
21897 "layout(location=0) in int x[];\n"
21898 "out gl_PerVertex { vec4 gl_Position; };\n"
21899 "void main(){\n"
21900 " gl_Position.xyz = gl_TessCoord;\n"
21901 " gl_Position.w = x[0] + x[1] + x[2];\n"
21902 "}\n";
21903 char const *fsSource =
21904 "#version 450\n"
21905 "layout(location=0) out vec4 color;\n"
21906 "void main(){\n"
21907 " color = vec4(1);\n"
21908 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021909
21910 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21911 VkShaderObj tcs(m_device, tcsSource, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, this);
21912 VkShaderObj tes(m_device, tesSource, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, this);
21913 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21914
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021915 VkPipelineInputAssemblyStateCreateInfo iasci{VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, nullptr, 0,
21916 VK_PRIMITIVE_TOPOLOGY_PATCH_LIST, VK_FALSE};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021917
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070021918 VkPipelineTessellationStateCreateInfo tsci{VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO, nullptr, 0, 3};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021919
21920 VkPipelineObj pipe(m_device);
21921 pipe.SetInputAssembly(&iasci);
21922 pipe.SetTessellation(&tsci);
21923 pipe.AddColorAttachment();
21924 pipe.AddShader(&vs);
21925 pipe.AddShader(&tcs);
21926 pipe.AddShader(&tes);
21927 pipe.AddShader(&fs);
21928
21929 VkDescriptorSetObj descriptorSet(m_device);
21930 descriptorSet.AppendDummy();
21931 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21932
21933 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21934
21935 m_errorMonitor->VerifyNotFound();
21936}
21937
21938TEST_F(VkPositiveLayerTest, CreatePipelineGeometryInputBlockPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021939 TEST_DESCRIPTION(
21940 "Test that pipeline validation accepts a user-defined "
21941 "interface block passed into the geometry shader. This "
21942 "is interesting because the 'extra' array level is not "
21943 "present on the member type, but on the block instance.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021944 m_errorMonitor->ExpectSuccess();
21945
21946 ASSERT_NO_FATAL_FAILURE(InitState());
21947 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
21948
21949 if (!m_device->phy().features().geometryShader) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070021950 printf(" Device does not support geometry shaders; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021951 return;
21952 }
21953
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021954 char const *vsSource =
21955 "#version 450\n"
21956 "layout(location=0) out VertexData { vec4 x; } vs_out;\n"
21957 "void main(){\n"
21958 " vs_out.x = vec4(1);\n"
21959 "}\n";
21960 char const *gsSource =
21961 "#version 450\n"
21962 "layout(triangles) in;\n"
21963 "layout(triangle_strip, max_vertices=3) out;\n"
21964 "layout(location=0) in VertexData { vec4 x; } gs_in[];\n"
21965 "out gl_PerVertex { vec4 gl_Position; };\n"
21966 "void main() {\n"
21967 " gl_Position = gs_in[0].x;\n"
21968 " EmitVertex();\n"
21969 "}\n";
21970 char const *fsSource =
21971 "#version 450\n"
21972 "layout(location=0) out vec4 color;\n"
21973 "void main(){\n"
21974 " color = vec4(1);\n"
21975 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060021976
21977 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
21978 VkShaderObj gs(m_device, gsSource, VK_SHADER_STAGE_GEOMETRY_BIT, this);
21979 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
21980
21981 VkPipelineObj pipe(m_device);
21982 pipe.AddColorAttachment();
21983 pipe.AddShader(&vs);
21984 pipe.AddShader(&gs);
21985 pipe.AddShader(&fs);
21986
21987 VkDescriptorSetObj descriptorSet(m_device);
21988 descriptorSet.AppendDummy();
21989 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
21990
21991 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
21992
21993 m_errorMonitor->VerifyNotFound();
21994}
21995
21996TEST_F(VkPositiveLayerTest, CreatePipeline64BitAttributesPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070021997 TEST_DESCRIPTION(
21998 "Test that pipeline validation accepts basic use of 64bit vertex "
21999 "attributes. This is interesting because they consume multiple "
22000 "locations.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022001 m_errorMonitor->ExpectSuccess();
22002
22003 ASSERT_NO_FATAL_FAILURE(InitState());
22004 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22005
22006 if (!m_device->phy().features().shaderFloat64) {
Mark Lobodzinskif8839bd2017-02-16 10:41:47 -070022007 printf(" Device does not support 64bit vertex attributes; skipped.\n");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022008 return;
22009 }
22010
22011 VkVertexInputBindingDescription input_bindings[1];
22012 memset(input_bindings, 0, sizeof(input_bindings));
22013
22014 VkVertexInputAttributeDescription input_attribs[4];
22015 memset(input_attribs, 0, sizeof(input_attribs));
22016 input_attribs[0].location = 0;
22017 input_attribs[0].offset = 0;
22018 input_attribs[0].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22019 input_attribs[1].location = 2;
22020 input_attribs[1].offset = 32;
22021 input_attribs[1].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22022 input_attribs[2].location = 4;
22023 input_attribs[2].offset = 64;
22024 input_attribs[2].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22025 input_attribs[3].location = 6;
22026 input_attribs[3].offset = 96;
22027 input_attribs[3].format = VK_FORMAT_R64G64B64A64_SFLOAT;
22028
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022029 char const *vsSource =
22030 "#version 450\n"
22031 "\n"
22032 "layout(location=0) in dmat4 x;\n"
22033 "out gl_PerVertex {\n"
22034 " vec4 gl_Position;\n"
22035 "};\n"
22036 "void main(){\n"
22037 " gl_Position = vec4(x[0][0]);\n"
22038 "}\n";
22039 char const *fsSource =
22040 "#version 450\n"
22041 "\n"
22042 "layout(location=0) out vec4 color;\n"
22043 "void main(){\n"
22044 " color = vec4(1);\n"
22045 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022046
22047 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22048 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22049
22050 VkPipelineObj pipe(m_device);
22051 pipe.AddColorAttachment();
22052 pipe.AddShader(&vs);
22053 pipe.AddShader(&fs);
22054
22055 pipe.AddVertexInputBindings(input_bindings, 1);
22056 pipe.AddVertexInputAttribs(input_attribs, 4);
22057
22058 VkDescriptorSetObj descriptorSet(m_device);
22059 descriptorSet.AppendDummy();
22060 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22061
22062 pipe.CreateVKPipeline(descriptorSet.GetPipelineLayout(), renderPass());
22063
22064 m_errorMonitor->VerifyNotFound();
22065}
22066
22067TEST_F(VkPositiveLayerTest, CreatePipelineInputAttachmentPositive) {
22068 TEST_DESCRIPTION("Positive test for a correctly matched input attachment");
22069 m_errorMonitor->ExpectSuccess();
22070
22071 ASSERT_NO_FATAL_FAILURE(InitState());
22072
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022073 char const *vsSource =
22074 "#version 450\n"
22075 "\n"
22076 "out gl_PerVertex {\n"
22077 " vec4 gl_Position;\n"
22078 "};\n"
22079 "void main(){\n"
22080 " gl_Position = vec4(1);\n"
22081 "}\n";
22082 char const *fsSource =
22083 "#version 450\n"
22084 "\n"
22085 "layout(input_attachment_index=0, set=0, binding=0) uniform subpassInput x;\n"
22086 "layout(location=0) out vec4 color;\n"
22087 "void main() {\n"
22088 " color = subpassLoad(x);\n"
22089 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022090
22091 VkShaderObj vs(m_device, vsSource, VK_SHADER_STAGE_VERTEX_BIT, this);
22092 VkShaderObj fs(m_device, fsSource, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22093
22094 VkPipelineObj pipe(m_device);
22095 pipe.AddShader(&vs);
22096 pipe.AddShader(&fs);
22097 pipe.AddColorAttachment();
22098 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22099
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022100 VkDescriptorSetLayoutBinding dslb = {0, VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1, VK_SHADER_STAGE_FRAGMENT_BIT, nullptr};
22101 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dslb};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022102 VkDescriptorSetLayout dsl;
22103 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22104 ASSERT_VK_SUCCESS(err);
22105
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022106 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022107 VkPipelineLayout pl;
22108 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22109 ASSERT_VK_SUCCESS(err);
22110
22111 VkAttachmentDescription descs[2] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022112 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22113 VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22114 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL},
22115 {0, VK_FORMAT_R8G8B8A8_UNORM, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_LOAD, VK_ATTACHMENT_STORE_OP_STORE,
22116 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 -060022117 };
22118 VkAttachmentReference color = {
22119 0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
22120 };
22121 VkAttachmentReference input = {
22122 1, VK_IMAGE_LAYOUT_GENERAL,
22123 };
22124
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022125 VkSubpassDescription sd = {0, VK_PIPELINE_BIND_POINT_GRAPHICS, 1, &input, 1, &color, nullptr, nullptr, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022126
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022127 VkRenderPassCreateInfo rpci = {VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, nullptr, 0, 2, descs, 1, &sd, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022128 VkRenderPass rp;
22129 err = vkCreateRenderPass(m_device->device(), &rpci, nullptr, &rp);
22130 ASSERT_VK_SUCCESS(err);
22131
22132 // should be OK. would go wrong here if it's going to...
22133 pipe.CreateVKPipeline(pl, rp);
22134
22135 m_errorMonitor->VerifyNotFound();
22136
22137 vkDestroyRenderPass(m_device->device(), rp, nullptr);
22138 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22139 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22140}
22141
22142TEST_F(VkPositiveLayerTest, CreateComputePipelineMissingDescriptorUnusedPositive) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022143 TEST_DESCRIPTION(
22144 "Test that pipeline validation accepts a compute pipeline which declares a "
22145 "descriptor-backed resource which is not provided, but the shader does not "
22146 "statically use it. This is interesting because it requires compute pipelines "
22147 "to have a proper descriptor use walk, which they didn't for some time.");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022148 m_errorMonitor->ExpectSuccess();
22149
22150 ASSERT_NO_FATAL_FAILURE(InitState());
22151
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022152 char const *csSource =
22153 "#version 450\n"
22154 "\n"
22155 "layout(local_size_x=1) in;\n"
22156 "layout(set=0, binding=0) buffer block { vec4 x; };\n"
22157 "void main(){\n"
22158 " // x is not used.\n"
22159 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022160
22161 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22162
22163 VkDescriptorSetObj descriptorSet(m_device);
22164 descriptorSet.CreateVKDescriptorSet(m_commandBuffer);
22165
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022166 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22167 nullptr,
22168 0,
22169 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22170 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22171 descriptorSet.GetPipelineLayout(),
22172 VK_NULL_HANDLE,
22173 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022174
22175 VkPipeline pipe;
22176 VkResult err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22177
22178 m_errorMonitor->VerifyNotFound();
22179
22180 if (err == VK_SUCCESS) {
22181 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22182 }
22183}
22184
22185TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsSampler) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022186 TEST_DESCRIPTION(
22187 "Test that pipeline validation accepts a shader consuming only the "
22188 "sampler portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022189 m_errorMonitor->ExpectSuccess();
22190
22191 ASSERT_NO_FATAL_FAILURE(InitState());
22192
22193 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022194 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22195 {1, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22196 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022197 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022198 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022199 VkDescriptorSetLayout dsl;
22200 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22201 ASSERT_VK_SUCCESS(err);
22202
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022203 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022204 VkPipelineLayout pl;
22205 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22206 ASSERT_VK_SUCCESS(err);
22207
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022208 char const *csSource =
22209 "#version 450\n"
22210 "\n"
22211 "layout(local_size_x=1) in;\n"
22212 "layout(set=0, binding=0) uniform sampler s;\n"
22213 "layout(set=0, binding=1) uniform texture2D t;\n"
22214 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22215 "void main() {\n"
22216 " x = texture(sampler2D(t, s), vec2(0));\n"
22217 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022218 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22219
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022220 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22221 nullptr,
22222 0,
22223 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22224 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22225 pl,
22226 VK_NULL_HANDLE,
22227 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022228
22229 VkPipeline pipe;
22230 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22231
22232 m_errorMonitor->VerifyNotFound();
22233
22234 if (err == VK_SUCCESS) {
22235 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22236 }
22237
22238 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22239 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22240}
22241
22242TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsImage) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022243 TEST_DESCRIPTION(
22244 "Test that pipeline validation accepts a shader consuming only the "
22245 "image portion of a combined image + sampler");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022246 m_errorMonitor->ExpectSuccess();
22247
22248 ASSERT_NO_FATAL_FAILURE(InitState());
22249
22250 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022251 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22252 {1, VK_DESCRIPTOR_TYPE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22253 {2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022254 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022255 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 3, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022256 VkDescriptorSetLayout dsl;
22257 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22258 ASSERT_VK_SUCCESS(err);
22259
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022260 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022261 VkPipelineLayout pl;
22262 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22263 ASSERT_VK_SUCCESS(err);
22264
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022265 char const *csSource =
22266 "#version 450\n"
22267 "\n"
22268 "layout(local_size_x=1) in;\n"
22269 "layout(set=0, binding=0) uniform texture2D t;\n"
22270 "layout(set=0, binding=1) uniform sampler s;\n"
22271 "layout(set=0, binding=2) buffer block { vec4 x; };\n"
22272 "void main() {\n"
22273 " x = texture(sampler2D(t, s), vec2(0));\n"
22274 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022275 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22276
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022277 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22278 nullptr,
22279 0,
22280 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22281 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22282 pl,
22283 VK_NULL_HANDLE,
22284 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022285
22286 VkPipeline pipe;
22287 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22288
22289 m_errorMonitor->VerifyNotFound();
22290
22291 if (err == VK_SUCCESS) {
22292 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22293 }
22294
22295 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22296 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22297}
22298
22299TEST_F(VkPositiveLayerTest, CreateComputePipelineCombinedImageSamplerConsumedAsBoth) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022300 TEST_DESCRIPTION(
22301 "Test that pipeline validation accepts a shader consuming "
22302 "both the sampler and the image of a combined image+sampler "
22303 "but via separate variables");
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022304 m_errorMonitor->ExpectSuccess();
22305
22306 ASSERT_NO_FATAL_FAILURE(InitState());
22307
22308 VkDescriptorSetLayoutBinding bindings[] = {
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022309 {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
22310 {1, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, nullptr},
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022311 };
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022312 VkDescriptorSetLayoutCreateInfo dslci = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, nullptr, 0, 2, bindings};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022313 VkDescriptorSetLayout dsl;
22314 VkResult err = vkCreateDescriptorSetLayout(m_device->device(), &dslci, nullptr, &dsl);
22315 ASSERT_VK_SUCCESS(err);
22316
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022317 VkPipelineLayoutCreateInfo plci = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, nullptr, 0, 1, &dsl, 0, nullptr};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022318 VkPipelineLayout pl;
22319 err = vkCreatePipelineLayout(m_device->device(), &plci, nullptr, &pl);
22320 ASSERT_VK_SUCCESS(err);
22321
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022322 char const *csSource =
22323 "#version 450\n"
22324 "\n"
22325 "layout(local_size_x=1) in;\n"
22326 "layout(set=0, binding=0) uniform texture2D t;\n"
22327 "layout(set=0, binding=0) uniform sampler s; // both binding 0!\n"
22328 "layout(set=0, binding=1) buffer block { vec4 x; };\n"
22329 "void main() {\n"
22330 " x = texture(sampler2D(t, s), vec2(0));\n"
22331 "}\n";
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022332 VkShaderObj cs(m_device, csSource, VK_SHADER_STAGE_COMPUTE_BIT, this);
22333
Mark Lobodzinski729a8d32017-01-26 12:16:30 -070022334 VkComputePipelineCreateInfo cpci = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
22335 nullptr,
22336 0,
22337 {VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, nullptr, 0,
22338 VK_SHADER_STAGE_COMPUTE_BIT, cs.handle(), "main", nullptr},
22339 pl,
22340 VK_NULL_HANDLE,
22341 -1};
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022342
22343 VkPipeline pipe;
22344 err = vkCreateComputePipelines(m_device->device(), VK_NULL_HANDLE, 1, &cpci, nullptr, &pipe);
22345
22346 m_errorMonitor->VerifyNotFound();
22347
22348 if (err == VK_SUCCESS) {
22349 vkDestroyPipeline(m_device->device(), pipe, nullptr);
22350 }
22351
22352 vkDestroyPipelineLayout(m_device->device(), pl, nullptr);
22353 vkDestroyDescriptorSetLayout(m_device->device(), dsl, nullptr);
22354}
22355
22356TEST_F(VkPositiveLayerTest, ValidStructPNext) {
22357 TEST_DESCRIPTION("Verify that a valid pNext value is handled correctly");
22358
22359 ASSERT_NO_FATAL_FAILURE(InitState());
22360
22361 // Positive test to check parameter_validation and unique_objects support
22362 // for NV_dedicated_allocation
22363 uint32_t extension_count = 0;
22364 bool supports_nv_dedicated_allocation = false;
22365 VkResult err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, nullptr);
22366 ASSERT_VK_SUCCESS(err);
22367
22368 if (extension_count > 0) {
22369 std::vector<VkExtensionProperties> available_extensions(extension_count);
22370
22371 err = vkEnumerateDeviceExtensionProperties(gpu(), nullptr, &extension_count, &available_extensions[0]);
22372 ASSERT_VK_SUCCESS(err);
22373
22374 for (const auto &extension_props : available_extensions) {
22375 if (strcmp(extension_props.extensionName, VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME) == 0) {
22376 supports_nv_dedicated_allocation = true;
22377 }
22378 }
22379 }
22380
22381 if (supports_nv_dedicated_allocation) {
22382 m_errorMonitor->ExpectSuccess();
22383
22384 VkDedicatedAllocationBufferCreateInfoNV dedicated_buffer_create_info = {};
22385 dedicated_buffer_create_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_BUFFER_CREATE_INFO_NV;
22386 dedicated_buffer_create_info.pNext = nullptr;
22387 dedicated_buffer_create_info.dedicatedAllocation = VK_TRUE;
22388
22389 uint32_t queue_family_index = 0;
22390 VkBufferCreateInfo buffer_create_info = {};
22391 buffer_create_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
22392 buffer_create_info.pNext = &dedicated_buffer_create_info;
22393 buffer_create_info.size = 1024;
22394 buffer_create_info.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT;
22395 buffer_create_info.queueFamilyIndexCount = 1;
22396 buffer_create_info.pQueueFamilyIndices = &queue_family_index;
22397
22398 VkBuffer buffer;
Karl Schultz47dd59d2017-01-20 13:19:20 -070022399 err = vkCreateBuffer(m_device->device(), &buffer_create_info, NULL, &buffer);
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022400 ASSERT_VK_SUCCESS(err);
22401
22402 VkMemoryRequirements memory_reqs;
22403 vkGetBufferMemoryRequirements(m_device->device(), buffer, &memory_reqs);
22404
22405 VkDedicatedAllocationMemoryAllocateInfoNV dedicated_memory_info = {};
22406 dedicated_memory_info.sType = VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV;
22407 dedicated_memory_info.pNext = nullptr;
22408 dedicated_memory_info.buffer = buffer;
22409 dedicated_memory_info.image = VK_NULL_HANDLE;
22410
22411 VkMemoryAllocateInfo memory_info = {};
22412 memory_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
22413 memory_info.pNext = &dedicated_memory_info;
22414 memory_info.allocationSize = memory_reqs.size;
22415
22416 bool pass;
22417 pass = m_device->phy().set_memory_type(memory_reqs.memoryTypeBits, &memory_info, 0);
22418 ASSERT_TRUE(pass);
22419
22420 VkDeviceMemory buffer_memory;
22421 err = vkAllocateMemory(m_device->device(), &memory_info, NULL, &buffer_memory);
22422 ASSERT_VK_SUCCESS(err);
22423
22424 err = vkBindBufferMemory(m_device->device(), buffer, buffer_memory, 0);
22425 ASSERT_VK_SUCCESS(err);
22426
22427 vkDestroyBuffer(m_device->device(), buffer, NULL);
22428 vkFreeMemory(m_device->device(), buffer_memory, NULL);
22429
22430 m_errorMonitor->VerifyNotFound();
22431 }
22432}
22433
22434TEST_F(VkPositiveLayerTest, PSOPolygonModeValid) {
22435 VkResult err;
22436
22437 TEST_DESCRIPTION("Verify that using a solid polygon fill mode works correctly.");
22438
22439 ASSERT_NO_FATAL_FAILURE(InitState());
22440 ASSERT_NO_FATAL_FAILURE(InitRenderTarget());
22441
22442 std::vector<const char *> device_extension_names;
22443 auto features = m_device->phy().features();
22444 // Artificially disable support for non-solid fill modes
22445 features.fillModeNonSolid = false;
22446 // The sacrificial device object
22447 VkDeviceObj test_device(0, gpu(), device_extension_names, &features);
22448
22449 VkRenderpassObj render_pass(&test_device);
22450
22451 VkPipelineLayoutCreateInfo pipeline_layout_ci = {};
22452 pipeline_layout_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22453 pipeline_layout_ci.setLayoutCount = 0;
22454 pipeline_layout_ci.pSetLayouts = NULL;
22455
22456 VkPipelineLayout pipeline_layout;
22457 err = vkCreatePipelineLayout(test_device.device(), &pipeline_layout_ci, NULL, &pipeline_layout);
22458 ASSERT_VK_SUCCESS(err);
22459
22460 VkPipelineRasterizationStateCreateInfo rs_ci = {};
22461 rs_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
22462 rs_ci.pNext = nullptr;
22463 rs_ci.lineWidth = 1.0f;
22464 rs_ci.rasterizerDiscardEnable = true;
22465
22466 VkShaderObj vs(&test_device, bindStateVertShaderText, VK_SHADER_STAGE_VERTEX_BIT, this);
22467 VkShaderObj fs(&test_device, bindStateFragShaderText, VK_SHADER_STAGE_FRAGMENT_BIT, this);
22468
22469 // Set polygonMode=FILL. No error is expected
22470 m_errorMonitor->ExpectSuccess();
22471 {
22472 VkPipelineObj pipe(&test_device);
22473 pipe.AddShader(&vs);
22474 pipe.AddShader(&fs);
22475 pipe.AddColorAttachment();
22476 // Set polygonMode to a good value
22477 rs_ci.polygonMode = VK_POLYGON_MODE_FILL;
22478 pipe.SetRasterization(&rs_ci);
22479 pipe.CreateVKPipeline(pipeline_layout, render_pass.handle());
22480 }
22481 m_errorMonitor->VerifyNotFound();
22482
22483 vkDestroyPipelineLayout(test_device.device(), pipeline_layout, NULL);
22484}
22485
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022486#if 0 // A few devices have issues with this test so disabling for now
Mark Lobodzinski008b6ba2016-10-19 10:27:54 -060022487TEST_F(VkPositiveLayerTest, LongFenceChain)
22488{
22489 m_errorMonitor->ExpectSuccess();
22490
22491 ASSERT_NO_FATAL_FAILURE(InitState());
22492 VkResult err;
22493
22494 std::vector<VkFence> fences;
22495
22496 const int chainLength = 32768;
22497
22498 for (int i = 0; i < chainLength; i++) {
22499 VkFenceCreateInfo fci = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, nullptr, 0 };
22500 VkFence fence;
22501 err = vkCreateFence(m_device->device(), &fci, nullptr, &fence);
22502 ASSERT_VK_SUCCESS(err);
22503
22504 fences.push_back(fence);
22505
22506 VkSubmitInfo si = { VK_STRUCTURE_TYPE_SUBMIT_INFO, nullptr, 0, nullptr, nullptr,
22507 0, nullptr, 0, nullptr };
22508 err = vkQueueSubmit(m_device->m_queue, 1, &si, fence);
22509 ASSERT_VK_SUCCESS(err);
22510
22511 }
22512
22513 // BOOM, stack overflow.
22514 vkWaitForFences(m_device->device(), 1, &fences.back(), VK_TRUE, UINT64_MAX);
22515
22516 for (auto fence : fences)
22517 vkDestroyFence(m_device->device(), fence, nullptr);
22518
22519 m_errorMonitor->VerifyNotFound();
22520}
22521#endif
22522
Cody Northrop1242dfd2016-07-13 17:24:59 -060022523#if defined(ANDROID) && defined(VALIDATION_APK)
22524static bool initialized = false;
22525static bool active = false;
22526
22527// Convert Intents to argv
22528// Ported from Hologram sample, only difference is flexible key
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022529std::vector<std::string> get_args(android_app &app, const char *intent_extra_data_key) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022530 std::vector<std::string> args;
22531 JavaVM &vm = *app.activity->vm;
22532 JNIEnv *p_env;
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022533 if (vm.AttachCurrentThread(&p_env, nullptr) != JNI_OK) return args;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022534
22535 JNIEnv &env = *p_env;
22536 jobject activity = app.activity->clazz;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022537 jmethodID get_intent_method = env.GetMethodID(env.GetObjectClass(activity), "getIntent", "()Landroid/content/Intent;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022538 jobject intent = env.CallObjectMethod(activity, get_intent_method);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022539 jmethodID get_string_extra_method =
22540 env.GetMethodID(env.GetObjectClass(intent), "getStringExtra", "(Ljava/lang/String;)Ljava/lang/String;");
Cody Northrop1242dfd2016-07-13 17:24:59 -060022541 jvalue get_string_extra_args;
22542 get_string_extra_args.l = env.NewStringUTF(intent_extra_data_key);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022543 jstring extra_str = static_cast<jstring>(env.CallObjectMethodA(intent, get_string_extra_method, &get_string_extra_args));
Cody Northrop1242dfd2016-07-13 17:24:59 -060022544
22545 std::string args_str;
22546 if (extra_str) {
22547 const char *extra_utf = env.GetStringUTFChars(extra_str, nullptr);
22548 args_str = extra_utf;
22549 env.ReleaseStringUTFChars(extra_str, extra_utf);
22550 env.DeleteLocalRef(extra_str);
22551 }
22552
22553 env.DeleteLocalRef(get_string_extra_args.l);
22554 env.DeleteLocalRef(intent);
22555 vm.DetachCurrentThread();
22556
22557 // split args_str
22558 std::stringstream ss(args_str);
22559 std::string arg;
22560 while (std::getline(ss, arg, ' ')) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022561 if (!arg.empty()) args.push_back(arg);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022562 }
22563
22564 return args;
22565}
22566
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022567static int32_t processInput(struct android_app *app, AInputEvent *event) { return 0; }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022568
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022569static void processCommand(struct android_app *app, int32_t cmd) {
22570 switch (cmd) {
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022571 case APP_CMD_INIT_WINDOW: {
22572 if (app->window) {
22573 initialized = true;
22574 }
22575 break;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022576 }
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022577 case APP_CMD_GAINED_FOCUS: {
22578 active = true;
22579 break;
22580 }
22581 case APP_CMD_LOST_FOCUS: {
22582 active = false;
22583 break;
22584 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022585 }
22586}
22587
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022588void android_main(struct android_app *app) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022589 app_dummy();
22590
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022591 const char *appTag = "VulkanLayerValidationTests";
Cody Northrop1242dfd2016-07-13 17:24:59 -060022592
22593 int vulkanSupport = InitVulkan();
22594 if (vulkanSupport == 0) {
22595 __android_log_print(ANDROID_LOG_INFO, appTag, "==== FAILED ==== No Vulkan support found");
22596 return;
22597 }
22598
22599 app->onAppCmd = processCommand;
22600 app->onInputEvent = processInput;
22601
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022602 while (1) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022603 int events;
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022604 struct android_poll_source *source;
22605 while (ALooper_pollAll(active ? 0 : -1, NULL, &events, (void **)&source) >= 0) {
Cody Northrop1242dfd2016-07-13 17:24:59 -060022606 if (source) {
22607 source->process(app, source);
22608 }
22609
22610 if (app->destroyRequested != 0) {
22611 VkTestFramework::Finish();
22612 return;
22613 }
22614 }
22615
22616 if (initialized && active) {
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022617 // Use the following key to send arguments to gtest, i.e.
22618 // --es args "--gtest_filter=-VkLayerTest.foo"
22619 const char key[] = "args";
22620 std::vector<std::string> args = get_args(*app, key);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022621
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022622 std::string filter = "";
22623 if (args.size() > 0) {
22624 __android_log_print(ANDROID_LOG_INFO, appTag, "Intent args = %s", args[0].c_str());
22625 filter += args[0];
22626 } else {
22627 __android_log_print(ANDROID_LOG_INFO, appTag, "No Intent args detected");
22628 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022629
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022630 int argc = 2;
22631 char *argv[] = {(char *)"foo", (char *)filter.c_str()};
22632 __android_log_print(ANDROID_LOG_DEBUG, appTag, "filter = %s", argv[1]);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022633
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022634 // Route output to files until we can override the gtest output
22635 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/out.txt", "w", stdout);
22636 freopen("/sdcard/Android/data/com.example.VulkanLayerValidationTests/files/err.txt", "w", stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022637
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022638 ::testing::InitGoogleTest(&argc, argv);
22639 VkTestFramework::InitArgs(&argc, argv);
22640 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022641
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022642 int result = RUN_ALL_TESTS();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022643
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022644 if (result != 0) {
22645 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests FAILED ====");
22646 } else {
22647 __android_log_print(ANDROID_LOG_INFO, appTag, "==== Tests PASSED ====");
22648 }
Cody Northrop1242dfd2016-07-13 17:24:59 -060022649
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022650 VkTestFramework::Finish();
Cody Northrop1242dfd2016-07-13 17:24:59 -060022651
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022652 fclose(stdout);
22653 fclose(stderr);
Cody Northrop1242dfd2016-07-13 17:24:59 -060022654
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022655 ANativeActivity_finish(app->activity);
Mark Lobodzinskice751c62016-09-08 10:45:35 -060022656 return;
Cody Northrop1242dfd2016-07-13 17:24:59 -060022657 }
22658 }
22659}
22660#endif
22661
Tony Barbour300a6082015-04-07 13:44:53 -060022662int main(int argc, char **argv) {
22663 int result;
22664
Cody Northrop8e54a402016-03-08 22:25:52 -070022665#ifdef ANDROID
22666 int vulkanSupport = InitVulkan();
Mark Lobodzinski64318ba2017-01-26 13:34:13 -070022667 if (vulkanSupport == 0) return 1;
Cody Northrop8e54a402016-03-08 22:25:52 -070022668#endif
22669
Tony Barbour300a6082015-04-07 13:44:53 -060022670 ::testing::InitGoogleTest(&argc, argv);
Tony Barbour6918cd52015-04-09 12:58:51 -060022671 VkTestFramework::InitArgs(&argc, argv);
Tony Barbour300a6082015-04-07 13:44:53 -060022672
22673 ::testing::AddGlobalTestEnvironment(new TestEnvironment);
22674
22675 result = RUN_ALL_TESTS();
22676
Tony Barbour6918cd52015-04-09 12:58:51 -060022677 VkTestFramework::Finish();
Tony Barbour300a6082015-04-07 13:44:53 -060022678 return result;
22679}